@@ -92,6 +92,9 @@ public final class CBORObject implements Comparable<CBORObject> {
9292 private static CBORObject ConstructSimpleValue (int v ) {
9393 return new CBORObject (CBORObjectTypeSimpleValue , v );
9494 }
95+ private static CBORObject ConstructIntegerValue (int v ) {
96+ return new CBORObject (CBORObjectTypeInteger , (long )v );
97+ }
9598
9699 /**
97100 * Represents the value false.
@@ -138,6 +141,12 @@ private static CBORObject ConstructSimpleValue(int v) {
138141 public static final CBORObject Undefined =
139142 CBORObject .ConstructSimpleValue (23 );
140143
144+ /**
145+ * Gets a CBOR object for the number zero.
146+ */
147+ public static final CBORObject Zero =
148+ CBORObject .ConstructIntegerValue (0 );
149+
141150 static final int CBORObjectTypeArray = 4 ;
142151 static final int CBORObjectTypeBigInteger = 1 ; // all other integers
143152 static final int CBORObjectTypeByteString = 2 ;
@@ -350,6 +359,15 @@ public final Collection<CBORObject> getKeys() {
350359 throw new IllegalStateException ("Not a map" );
351360 }
352361
362+ /**
363+ * Gets a value indicating whether this object is a negative number.
364+ * @return True if this object is a negative number; otherwise, false.
365+ */
366+ public final boolean isNegative () {
367+ ICBORNumber cn = NumberInterfaces [this .getItemType ()];
368+ return (cn != null ) && cn .IsNegative (this .getThisItem ());
369+ }
370+
353371 /**
354372 * Gets the outermost tag for this CBOR data item, or -1 if the item is
355373 * untagged.
@@ -1172,31 +1190,33 @@ public static <TKey, TValue> CBORObject FromObject(Map<TKey,
11721190 * Generates a CBORObject from an arbitrary object. The following types are
11731191 * specially handled by this method: null; primitive types; string;
11741192 * CBORObject; the <code>EDecimal</code>, <code>EFloat</code>, <code>EInteger</code>, and
1175- * <code>ERational</code> classes in the new <code>PeterO.Numbers</code> library (in
1176- * .NET) or the <code>com.github.peteroupc/numbers</code> artifact (in Java);
1177- * the legacy <code>ExtendedDecimal</code>, <code>ExtendedFloat</code>,
1178- * <code>ExtendedInteger</code>, and <code>ExtendedRational</code> classes in this
1179- * library; arrays; enumerations (<code>Enum</code> objects); and maps. <p>In
1180- * the .NET version, if the object is a type not specially handled by
1181- * this method, returns a CBOR map with the values of each of its
1182- * read/write properties (or all properties in the case of an anonymous
1183- * type). Properties are converted to their camel-case names (meaning if
1184- * a name starts with A to Z, that letter is lower-cased). If the
1185- * property name begins with the word "Is", that word is deleted from
1186- * the name. Also, .NET <code>Enum</code> objects will be converted to their
1187- * integer values, and a multidimensional array is converted to an array
1188- * of arrays.</p> <p>In the Java version, if the object is a type not
1189- * specially handled by this method, this method checks the CBOR object
1190- * for methods starting with the word "get" or "is" that take no
1191- * parameters, and returns a CBOR map with one entry for each such
1192- * method found. For each method found, the starting word "get" or "is"
1193- * is deleted from its name, and the name is converted to camel case
1194- * (meaning if a name starts with A to Z, that letter is lower-cased).
1195- * Also, Java <code>Enum</code> objects will be converted to the result of
1196- * their name method.</p> <p>If the input is a byte array, the byte
1197- * array is copied to a new byte array. (This method can't be used to
1198- * decode CBOR data from a byte array; for that, use the DecodeFromBytes
1199- * method instead.).</p>
1193+ * <code>ERational</code> classes in the new <a
1194+ * href='https://www.nuget.org/packages/PeterO.Numbers'><code>PeterO.Numbers</code></a>
1195+ * library (in .NET) or the <a
1196+ * href='https://github.com/peteroupc/numbers-java'><code>com.github.peteroupc/numbers</code></a>
1197+ * artifact (in Java); the legacy <code>ExtendedDecimal</code>,
1198+ * <code>ExtendedFloat</code>, <code>ExtendedInteger</code>, and
1199+ * <code>ExtendedRational</code> classes in this library; arrays; enumerations
1200+ * (<code>Enum</code> objects); and maps. <p>In the .NET version, if the
1201+ * object is a type not specially handled by this method, returns a CBOR
1202+ * map with the values of each of its read/write properties (or all
1203+ * properties in the case of an anonymous type). Properties are
1204+ * converted to their camel-case names (meaning if a name starts with A
1205+ * to Z, that letter is lower-cased). If the property name begins with
1206+ * the word "Is", that word is deleted from the name. Also, .NET
1207+ * <code>Enum</code> objects will be converted to their integer values, and a
1208+ * multidimensional array is converted to an array of arrays.</p> <p>In
1209+ * the Java version, if the object is a type not specially handled by
1210+ * this method, this method checks the CBOR object for methods starting
1211+ * with the word "get" or "is" that take no parameters, and returns a
1212+ * CBOR map with one entry for each such method found. For each method
1213+ * found, the starting word "get" or "is" is deleted from its name, and
1214+ * the name is converted to camel case (meaning if a name starts with A
1215+ * to Z, that letter is lower-cased). Also, Java <code>Enum</code> objects
1216+ * will be converted to the result of their name method.</p> <p>If the
1217+ * input is a byte array, the byte array is copied to a new byte array.
1218+ * (This method can't be used to decode CBOR data from a byte array; for
1219+ * that, use the DecodeFromBytes method instead.).</p>
12001220 * @param obj An arbitrary object.
12011221 * @return A CBOR object corresponding to the given object. Returns
12021222 * CBORObject.Null if the object is null.
0 commit comments