@@ -92,6 +92,9 @@ public final class CBORObject implements Comparable<CBORObject> {
92
92
private static CBORObject ConstructSimpleValue (int v ) {
93
93
return new CBORObject (CBORObjectTypeSimpleValue , v );
94
94
}
95
+ private static CBORObject ConstructIntegerValue (int v ) {
96
+ return new CBORObject (CBORObjectTypeInteger , (long )v );
97
+ }
95
98
96
99
/**
97
100
* Represents the value false.
@@ -138,6 +141,12 @@ private static CBORObject ConstructSimpleValue(int v) {
138
141
public static final CBORObject Undefined =
139
142
CBORObject .ConstructSimpleValue (23 );
140
143
144
+ /**
145
+ * Gets a CBOR object for the number zero.
146
+ */
147
+ public static final CBORObject Zero =
148
+ CBORObject .ConstructIntegerValue (0 );
149
+
141
150
static final int CBORObjectTypeArray = 4 ;
142
151
static final int CBORObjectTypeBigInteger = 1 ; // all other integers
143
152
static final int CBORObjectTypeByteString = 2 ;
@@ -350,6 +359,15 @@ public final Collection<CBORObject> getKeys() {
350
359
throw new IllegalStateException ("Not a map" );
351
360
}
352
361
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
+
353
371
/**
354
372
* Gets the outermost tag for this CBOR data item, or -1 if the item is
355
373
* untagged.
@@ -1172,31 +1190,33 @@ public static <TKey, TValue> CBORObject FromObject(Map<TKey,
1172
1190
* Generates a CBORObject from an arbitrary object. The following types are
1173
1191
* specially handled by this method: null; primitive types; string;
1174
1192
* 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>
1200
1220
* @param obj An arbitrary object.
1201
1221
* @return A CBOR object corresponding to the given object. Returns
1202
1222
* CBORObject.Null if the object is null.
0 commit comments