Skip to content

Commit 9be33d7

Browse files
committed
update Java version
1 parent 9eea9fa commit 9be33d7

File tree

3 files changed

+71
-51
lines changed

3 files changed

+71
-51
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,7 @@ private CBORObject NextJSONNonnegativeNumber(int c, int[] nextChar) {
425425
numberStartIndex,
426426
numberEndIndex - numberStartIndex,
427427
this.options);
428-
/*
429-
System.out.println("ParseJSONNumber
430-
{0}->{1}",EDecimal.FromString(this.bytes,
431-
numberStartIndex,
432-
numberEndIndex - numberStartIndex), obj);
433-
*/
428+
434429
if (obj == null) {
435430
String errstr = "";
436431
// errstr = (str.length() <= 100) ? str : (str.substring(0, // 100) + "...");

src/test/java/com/upokecenter/test/CBORObjectTest.java

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9337,10 +9337,10 @@ public static void AssertJSONDouble(
93379337
String json,
93389338
String numconv,
93399339
double dbl) {
9340-
JSONOptions opt=new JSONOptions("numberconversion=" + numconv);
9340+
JSONOptions opt = new JSONOptions("numberconversion=" + numconv);
93419341
CBORObject[] cbors = {
93429342
FromJSON(json, numconv),
9343-
CBORDataUtilities.ParseJSONNumber(json, opt)
9343+
CBORDataUtilities.ParseJSONNumber(json, opt),
93449344
};
93459345
for (CBORObject cbor : cbors) {
93469346
if (cbor.getType() != CBORType.FloatingPoint) {
@@ -9357,10 +9357,10 @@ public static void AssertJSONInteger(
93579357
String json,
93589358
String numconv,
93599359
long longval) {
9360-
JSONOptions opt=new JSONOptions("numberconversion=" + numconv);
9360+
JSONOptions opt = new JSONOptions("numberconversion=" + numconv);
93619361
CBORObject[] cbors = {
93629362
FromJSON(json, numconv),
9363-
CBORDataUtilities.ParseJSONNumber(json, opt)
9363+
CBORDataUtilities.ParseJSONNumber(json, opt),
93649364
};
93659365
for (CBORObject cbor : cbors) {
93669366
if (cbor.getType() != CBORType.Integer) {
@@ -9379,10 +9379,10 @@ public static void AssertJSONInteger(
93799379
String json,
93809380
String numconv,
93819381
int intval) {
9382-
JSONOptions opt=new JSONOptions("numberconversion=" + numconv);
9382+
JSONOptions opt = new JSONOptions("numberconversion=" + numconv);
93839383
CBORObject[] cbors = {
93849384
FromJSON(json, numconv),
9385-
CBORDataUtilities.ParseJSONNumber(json, opt)
9385+
CBORDataUtilities.ParseJSONNumber(json, opt),
93869386
};
93879387
for (CBORObject cbor : cbors) {
93889388
if (cbor.getType() != CBORType.Integer) {
@@ -9529,7 +9529,7 @@ public void TestFromJsonStringEDecimalSpec() {
95299529
for (int i = 0; i < 1000; ++i) {
95309530
String[] decstring = new String[1];
95319531
EDecimal ed = RandomObjects.RandomEDecimal(rg, decstring);
9532-
if ((decstring[0]) == null) {
9532+
if (decstring[0] == null) {
95339533
Assert.fail();
95349534
}
95359535
double dbl = ed.ToDouble();
@@ -9549,7 +9549,7 @@ public void TestFromJsonStringEDecimalSpec() {
95499549
public void TestFromJsonStringSmallDoubleSpec() {
95509550
RandomGenerator rg = new RandomGenerator();
95519551
for (int i = 0; i < 10000; ++i) {
9552-
int rv = rg.GetInt32(Integer.MAX_VALUE) * (rg.GetInt32(2)*2-1);
9552+
int rv = rg.GetInt32(Integer.MAX_VALUE) * (rg.GetInt32(2) * 2 - 1);
95539553
String rvstring = TestCommon.IntToString(rv);
95549554
AssertJSONDouble(
95559555
rvstring,
@@ -9560,8 +9560,8 @@ public void TestFromJsonStringSmallDoubleSpec() {
95609560
"intorfloat",
95619561
rv);
95629562
}
9563-
AssertJSONDouble("511","double",511);
9564-
AssertJSONDouble("-511","double",-511);
9563+
AssertJSONDouble("511", "double", 511);
9564+
AssertJSONDouble("-511", "double", -511);
95659565
AssertJSONDouble(
95669566
TestCommon.IntToString(Integer.MAX_VALUE),
95679567
"double",
@@ -9579,34 +9579,35 @@ public void TestFromJsonStringSmallDoubleSpec() {
95799579
@Test(timeout = 10000)
95809580
public void TestFromJsonStringSmallDouble() {
95819581
CBORObject cbor;
9582-
AssertJSONDouble("0","double",0.0);
9583-
cbor=FromJSON("[0, 1, 2, 3]", "double");
9582+
AssertJSONDouble("0", "double", 0.0);
9583+
cbor = FromJSON("[0, 1, 2, 3]", "double");
95849584
Assert.assertEquals(4, cbor.size());
9585-
Assert.assertEquals(0.0, cbor.get(0).AsDouble());
9586-
Assert.assertEquals(1.0, cbor.get(1).AsDouble());
9587-
Assert.assertEquals(2.0, cbor.get(2).AsDouble());
9588-
Assert.assertEquals(3.0, cbor.get(3).AsDouble());
9589-
cbor=FromJSON("[0]", "double");
9585+
Assert.assertEquals((double)0.0, cbor.get(0).AsDouble(), 0);
9586+
Assert.assertEquals((double)1.0, cbor.get(1).AsDouble(), 0);
9587+
Assert.assertEquals((double)2.0, cbor.get(2).AsDouble(), 0);
9588+
Assert.assertEquals((double)3.0, cbor.get(3).AsDouble(), 0);
9589+
cbor = FromJSON("[0]", "double");
95909590
Assert.assertEquals(1, cbor.size());
95919591
Assert.assertEquals(0.0, cbor.get(0).AsDouble());
9592-
cbor=FromJSON("[-0]", "double");
9592+
cbor = FromJSON("[-0]", "double");
95939593
Assert.assertEquals(1, cbor.size());
9594-
cbor=FromJSON("[1]", "double");
9594+
cbor = FromJSON("[1]", "double");
95959595
Assert.assertEquals(1, cbor.size());
9596-
Assert.assertEquals(1.0, cbor.get(0).AsDouble());
9597-
cbor=FromJSON("[-1]", "double");
9596+
Assert.assertEquals((double)1.0, cbor.get(0).AsDouble(), 0);
9597+
cbor = FromJSON("[-1]", "double");
95989598
Assert.assertEquals(1, cbor.size());
9599-
Assert.assertEquals(-1.0, cbor.get(0).AsDouble());
9600-
cbor=FromJSON("[-1022,-1023,-1024,-1025,1022,1023,1024,1025]", "double");
9599+
Assert.assertEquals((double)-1.0, cbor.get(0).AsDouble(), 0);
9600+
cbor = FromJSON("[-1022,-1023,-1024,-1025,1022,1023,1024,1025]",
9601+
"double");
96019602
Assert.assertEquals(8, cbor.size());
9602-
Assert.assertEquals(-1022.0, cbor.get(0).AsDouble());
9603-
Assert.assertEquals(-1023.0, cbor.get(1).AsDouble());
9604-
Assert.assertEquals(-1024.0, cbor.get(2).AsDouble());
9605-
Assert.assertEquals(-1025.0, cbor.get(3).AsDouble());
9606-
Assert.assertEquals(1022.0, cbor.get(4).AsDouble());
9607-
Assert.assertEquals(1023.0, cbor.get(5).AsDouble());
9608-
Assert.assertEquals(1024.0, cbor.get(6).AsDouble());
9609-
Assert.assertEquals(1025.0, cbor.get(7).AsDouble());
9603+
Assert.assertEquals((double)-1022.0, cbor.get(0).AsDouble(), 0);
9604+
Assert.assertEquals((double)-1023.0, cbor.get(1).AsDouble(), 0);
9605+
Assert.assertEquals((double)-1024.0, cbor.get(2).AsDouble(), 0);
9606+
Assert.assertEquals((double)-1025.0, cbor.get(3).AsDouble(), 0);
9607+
Assert.assertEquals((double)1022.0, cbor.get(4).AsDouble(), 0);
9608+
Assert.assertEquals((double)1023.0, cbor.get(5).AsDouble(), 0);
9609+
Assert.assertEquals((double)1024.0, cbor.get(6).AsDouble(), 0);
9610+
Assert.assertEquals((double)1025.0, cbor.get(7).AsDouble(), 0);
96109611
}
96119612

96129613
@Test(timeout = 10000)

src/test/java/com/upokecenter/test/CBORTest.java

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5202,31 +5202,55 @@ public static boolean CheckUtf16(String str) {
52025202
@Test
52035203
public void TestJSONOptions() {
52045204
JSONOptions jsonop1 = new JSONOptions("numberconversion=intorfloat");
5205-
Assert.assertEquals(jsonop1.toString(), new
5206-
JSONOptions(jsonop1.toString()).toString());
5205+
{
5206+
Object objectTemp = jsonop1.toString();
5207+
Object objectTemp2 = new
5208+
JSONOptions(jsonop1.toString()).toString();
5209+
Assert.assertEquals(objectTemp, objectTemp2);
5210+
}
52075211
JSONOptions jsonop2 = new JSONOptions("numberconversion=decimal128");
5208-
Assert.assertEquals(jsonop2.toString(), new
5209-
JSONOptions(jsonop2.toString()).toString());
5212+
{
5213+
Object objectTemp = jsonop2.toString();
5214+
Object objectTemp2 = new
5215+
JSONOptions(jsonop2.toString()).toString();
5216+
Assert.assertEquals(objectTemp, objectTemp2);
5217+
}
52105218
JSONOptions jsonop3 = new JSONOptions("numberconversion=intorfloatfromdouble");
5211-
Assert.assertEquals(jsonop3.toString(), new
5212-
JSONOptions(jsonop3.toString()).toString());
5219+
{
5220+
Object objectTemp = jsonop3.toString();
5221+
Object objectTemp2 = new
5222+
JSONOptions(jsonop3.toString()).toString();
5223+
Assert.assertEquals(objectTemp, objectTemp2);
5224+
}
52135225
JSONOptions jsonop4 = new JSONOptions("numberconversion=double");
5214-
Assert.assertEquals(jsonop4.toString(), new
5215-
JSONOptions(jsonop4.toString()).toString());
5226+
{
5227+
Object objectTemp = jsonop4.toString();
5228+
Object objectTemp2 = new
5229+
JSONOptions(jsonop4.toString()).toString();
5230+
Assert.assertEquals(objectTemp, objectTemp2);
5231+
}
52165232
}
52175233

52185234
@Test
52195235
public void TestPODOptions() {
52205236
PODOptions podop = PODOptions.Default;
5221-
Assert.assertEquals(podop.toString(), new
5222-
PODOptions(podop.toString()).toString());
5237+
{
5238+
Object objectTemp = podop.toString();
5239+
Object objectTemp2 = new
5240+
PODOptions(podop.toString()).toString();
5241+
Assert.assertEquals(objectTemp, objectTemp2);
5242+
}
52235243
}
52245244

52255245
@Test
52265246
public void TestCBOREncodeOptions() {
52275247
CBOREncodeOptions encodeop = CBOREncodeOptions.Default;
5228-
Assert.assertEquals(encodeop.toString(), new
5229-
CBOREncodeOptions(encodeop.toString()).toString());
5248+
{
5249+
Object objectTemp = encodeop.toString();
5250+
Object objectTemp2 = new
5251+
CBOREncodeOptions(encodeop.toString()).toString();
5252+
Assert.assertEquals(objectTemp, objectTemp2);
5253+
}
52305254
}
52315255

52325256
@Test
@@ -5239,7 +5263,7 @@ public void TestRandomJSON() {
52395263
JSONOptions jsonop4 = new JSONOptions("numberconversion=double");
52405264
for (int i = 0; i < 200; ++i) {
52415265
byte[] json = jsongen.Generate(rg);
5242-
System.out.println("" + i + " len=" + (json.length));
5266+
System.out.println("" + i + " len=" + json.length);
52435267
JSONOptions currop = null;
52445268
try {
52455269
currop = jsonop1;
@@ -5252,7 +5276,7 @@ public void TestRandomJSON() {
52525276
CBORObject.FromJSONBytes(json, jsonop4);
52535277
} catch (CBORException ex) {
52545278
String msg = ex.getMessage() + "\n" +
5255-
DataUtilities.GetUtf8String(json,true) + "\n" + currop;
5279+
DataUtilities.GetUtf8String(json, true) + "\n" + currop;
52565280
throw new IllegalStateException(msg, ex);
52575281
}
52585282
}

0 commit comments

Comments
 (0)