Skip to content

Commit 09e7e12

Browse files
committed
update Java version
1 parent 7096db0 commit 09e7e12

File tree

5 files changed

+61
-29
lines changed

5 files changed

+61
-29
lines changed

src/main/java/com/upokecenter/cbor/CBORDataUtilities.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ public static CBORObject ParseJSONNumber(String str) {
3232
/**
3333
* Parses a number whose format follows the JSON specification (RFC 7159).
3434
* Roughly speaking, a valid number consists of an optional minus sign,
35-
* one or more digits (starting with 1 to 9 unless the only digit is 0),
36-
* an optional decimal point with one or more digits, and an optional
37-
* letter E or e with an optional plus or minus sign and one or more
38-
* digits (the exponent).
35+
* one or more basic digits (starting with 1 to 9 unless the only digit
36+
* is 0), an optional decimal point ("." , full stop) with one or more
37+
* basic digits, and an optional letter E or e with an optional plus or
38+
* minus sign and one or more basic digits (the exponent).
3939
* @param str A string to parse.
4040
* @param integersOnly If true, no decimal points or exponents are allowed in
4141
* the string.

src/main/java/com/upokecenter/cbor/CBORObject.java

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,20 @@
6969
* without such synchronization.</p> <p>One kind of CBOR object is
7070
* called a map, or a list of key-value pairs. Keys can be any kind of
7171
* CBOR object, including numbers, strings, arrays, and maps. However,
72-
* text strings are the most suitable to ((use instanceof keys) ?
73-
* (keys)use : null); other kinds of CBOR object are much better used as
74-
* map values instead, keeping in mind that some of them are not thread
75-
* safe without synchronizing reads and writes to them.</p> <p>To find
76-
* the type of a CBOR object, call its Type property (or "getType()" in
77-
* Java). The return value can be Number, Boolean, SimpleValue, or
78-
* TextString for immutable CBOR objects, and Array, Map, or ByteString
79-
* for mutable CBOR objects.</p> <p><b>Nesting Depth:</b></p> <p>The
80-
* DecodeFromBytes method can only read objects with a limited maximum
81-
* depth of arrays and maps nested within other arrays and maps. The
82-
* code sets this maximum depth to 500 (allowing more than enough
83-
* nesting for most purposes), but it's possible that stack overflows in
84-
* some runtimes might lower the effective maximum nesting depth. When
85-
* the nesting depth goes above 500, the DecodeFromBytes method throws a
86-
* CBORException.</p>
72+
* text strings are the most suitable to use as keys; other kinds of
73+
* CBOR object are much better used as map values instead, keeping in
74+
* mind that some of them are not thread safe without synchronizing
75+
* reads and writes to them.</p> <p>To find the type of a CBOR object,
76+
* call its Type property (or "getType()" in Java). The return value can
77+
* be Number, Boolean, SimpleValue, or TextString for immutable CBOR
78+
* objects, and Array, Map, or ByteString for mutable CBOR objects.</p>
79+
* <p><b>Nesting Depth:</b></p> <p>The DecodeFromBytes method can only
80+
* read objects with a limited maximum depth of arrays and maps nested
81+
* within other arrays and maps. The code sets this maximum depth to 500
82+
* (allowing more than enough nesting for most purposes), but it's
83+
* possible that stack overflows in some runtimes might lower the
84+
* effective maximum nesting depth. When the nesting depth goes above
85+
* 500, the DecodeFromBytes method throws a CBORException.</p>
8786
*/
8887
public final class CBORObject implements Comparable<CBORObject> {
8988
private static CBORObject ConstructSimpleValue(int v) {
@@ -1048,7 +1047,33 @@ public static <TKey, TValue> CBORObject FromObject(Map<TKey,
10481047
}
10491048

10501049
/**
1051-
*
1050+
* Generates a CBORObject from an arbitrary object. The following types are
1051+
* specially handled by this method: null , primitive types, strings,
1052+
* CBORObject , ExtendedDecimal , ExtendedFloat , ExtendedRational, the
1053+
* custom BigInteger , lists, arrays, enumerations (<code>Enum</code>
1054+
* objects), and maps.<p>In the .NET version, if the object is a type
1055+
* not specially handled by this method, returns a CBOR map with the
1056+
* values of each of its read/write properties (or all properties in the
1057+
* case of an anonymous type). Properties are converted to their
1058+
* camel-case names (meaning if a name starts with A to Z, that letter
1059+
* is lower-cased). If the property name begins with the word "Is", that
1060+
* word is deleted from the name. Also, .NET <code>Enum</code> objects will be
1061+
* converted to their integer values, and a multidimensional array is
1062+
* converted to an array of arrays.</p> <p>In the Java version, if the
1063+
* object is a type not specially handled by this method, this method
1064+
* checks the CBOR object for methods starting with the word "get" or
1065+
* "is" that take no parameters, and returns a CBOR map with one entry
1066+
* for each such method found. For each method found, the starting word
1067+
* "get" or "is" is deleted from its name, and the name is converted to
1068+
* camel case (meaning if a name starts with A to Z, that letter is
1069+
* lower-cased). Also, Java <code>Enum</code> objects will be converted to the
1070+
* result of their name method.</p> <p>If the input is a byte array, the
1071+
* byte array is copied to a new byte array. (This method can't be used
1072+
* to decode CBOR data from a byte array; for that, use the
1073+
* DecodeFromBytes method instead.).</p>
1074+
* @param obj An arbitrary object.
1075+
* @return A CBOR object corresponding to the given object. Returns
1076+
* CBORObject.Null if the object is null.
10521077
*/
10531078
public static CBORObject FromObject(Object obj) {
10541079
if (obj == null) {

src/main/java/com/upokecenter/util/ExtendedDecimal.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,10 +2365,9 @@ public ExtendedDecimal Remainder(
23652365
* @param divisor The divisor.
23662366
* @param ctx A precision context object to control the precision. The rounding
23672367
* and exponent range settings of this context are ignored (the rounding
2368-
* mode is always ((treated instanceof HalfEven) ? (HalfEven)treated :
2369-
* null)). If HasFlags of the context is true, will also store the flags
2370-
* resulting from the operation (the flags are in addition to the
2371-
* pre-existing flags). Can be null.
2368+
* mode is always treated as HalfEven). If HasFlags of the context is
2369+
* true, will also store the flags resulting from the operation (the
2370+
* flags are in addition to the pre-existing flags). Can be null.
23722371
* @return The distance of the closest multiple. Signals FlagInvalid and
23732372
* returns NaN if the divisor is 0, or either the result of integer
23742373
* division (the quotient) or the remainder wouldn't fit the given

src/main/java/com/upokecenter/util/ExtendedFloat.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,10 +1565,9 @@ public ExtendedFloat Remainder(
15651565
* @param divisor The divisor.
15661566
* @param ctx A precision context object to control the precision. The rounding
15671567
* and exponent range settings of this context are ignored (the rounding
1568-
* mode is always ((treated instanceof HalfEven) ? (HalfEven)treated :
1569-
* null)). If HasFlags of the context is true, will also store the flags
1570-
* resulting from the operation (the flags are in addition to the
1571-
* pre-existing flags). Can be null.
1568+
* mode is always treated as HalfEven). If HasFlags of the context is
1569+
* true, will also store the flags resulting from the operation (the
1570+
* flags are in addition to the pre-existing flags). Can be null.
15721571
* @return The distance of the closest multiple. Signals FlagInvalid and
15731572
* returns NaN if the divisor is 0, or either the result of integer
15741573
* division (the quotient) or the remainder wouldn't fit the given

src/test/java/com/upokecenter/test/BigIntTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ public class BigIntTest {
1515
// Test some specific cases
1616
@Test
1717
public void TestSpecificCases() {
18-
TestCommon.DoTestMultiply(
18+
TestCommon.DoTestRemainder(
19+
"-2472320648",
20+
"2831812081",
21+
"359491433");
22+
TestCommon.DoTestMultiply(
1923
"39258416159456516340113264558732499166970244380745050",
2024
"39258416159456516340113264558732499166970244380745051",
2125
"1541223239349076530208308657654362309553698742116222355477449713742236585667505604058123112521437480247550");
@@ -46,6 +50,8 @@ public void TestMultiplyDivide() {
4650
for (int i = 0; i < 4000; ++i) {
4751
BigInteger bigintA = RandomObjects.RandomBigInteger(r);
4852
BigInteger bigintB = RandomObjects.RandomBigInteger(r);
53+
bigintA = BigInteger.fromString("-2472320648");
54+
bigintB = BigInteger.fromString("2831812081");
4955
// Test that A*B/A = B and A*B/B = A
5056
BigInteger bigintC = bigintA.multiply(bigintB);
5157
BigInteger bigintRem;
@@ -94,7 +100,10 @@ public void TestMultiplyDivide() {
94100
BigInteger[] divrem=(bigintA).divideAndRemainder(bigintB);
95101
bigintC = divrem[0];
96102
bigintRem = divrem[1]; }
103+
System.out.println(bigintC);
104+
System.out.println(bigintRem);
97105
bigintD = bigintB.multiply(bigintC);
106+
System.out.println(bigintD);
98107
bigintD = bigintD.add(bigintRem);
99108
if (!bigintD.equals(bigintA)) {
100109
Assert.assertEquals("TestMultiplyDivide " + bigintA + "; " + bigintB,bigintA,bigintD);

0 commit comments

Comments
 (0)