Skip to content

Commit b9713f6

Browse files
committed
update Java version
1 parent 096bab1 commit b9713f6

File tree

10 files changed

+781
-33
lines changed

10 files changed

+781
-33
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public static CBORObject ParseJSONNumber(
154154
if (haveDecimalPoint) {
155155
haveDigitsAfterDecimal = true;
156156
if (newScaleInt == Integer.MIN_VALUE) {
157-
newScale = (newScale == null) ? ((new FastInteger2(newScaleInt))) : newScale;
157+
newScale = (newScale == null) ? ((new FastInteger2(newScaleInt))) : newScale;
158158
newScale.AddInt(-1);
159159
} else {
160160
--newScaleInt;
@@ -232,18 +232,17 @@ public static CBORObject ParseJSONNumber(
232232
if (exp != null && (expBufferMult != 1 || expBuffer != 0)) {
233233
exp.Multiply(expBufferMult).AddInt(expBuffer);
234234
}
235-
if (offset >= 0 && newScaleInt == 0 && newScale == null && exp ==
236-
null) {
235+
if (offset >= 0 && newScaleInt == 0 && newScale == null && exp == null) {
237236
newScaleInt = expInt;
238237
} else if (exp == null) {
239-
newScale = (newScale == null) ? ((new FastInteger2(newScaleInt))) : newScale;
238+
newScale = (newScale == null) ? ((new FastInteger2(newScaleInt))) : newScale;
240239
if (offset < 0) {
241240
newScale.SubtractInt(expInt);
242241
} else if (expInt != 0) {
243242
newScale.AddInt(expInt);
244243
}
245244
} else {
246-
newScale = (newScale == null) ? ((new FastInteger2(newScaleInt))) : newScale;
245+
newScale = (newScale == null) ? ((new FastInteger2(newScaleInt))) : newScale;
247246
if (offset < 0) {
248247
newScale.Subtract(exp);
249248
} else {

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

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,20 +220,23 @@ null, new CBORExtendedFloat(), new CBORExtendedRational()
220220

221221
private static CBORObject[] valueFixedObjects = InitializeFixedObjects();
222222

223-
private int itemtypeValue;
224-
private Object itemValue;
225-
private int tagHigh;
226-
private int tagLow;
223+
private final int itemtypeValue;
224+
private final Object itemValue;
225+
private final int tagHigh;
226+
private final int tagLow;
227227

228228
CBORObject(CBORObject obj, int tagLow, int tagHigh) {
229-
this(CBORObjectTypeTagged, obj);
229+
this.itemtypeValue = CBORObjectTypeTagged;
230+
this.itemValue = obj;
230231
this.tagLow = tagLow;
231232
this.tagHigh = tagHigh;
232233
}
233234

234235
CBORObject(int type, Object item) {
235236
this.itemtypeValue = type;
236237
this.itemValue = item;
238+
this.tagLow = 0;
239+
this.tagHigh = 0;
237240
}
238241

239242
/**
@@ -784,7 +787,9 @@ public static CBORObject DecodeFromBytes(
784787
return o;
785788
}
786789
finally {
787-
try { if (ms != null)ms.close(); } catch (java.io.IOException ex) {}
790+
try { if (ms != null) {
791+
ms.close();
792+
} } catch (java.io.IOException ex) {}
788793
}
789794
}
790795
}
@@ -2380,13 +2385,13 @@ public CBORObject Add(Object key, Object valueOb) {
23802385
mapKey = CBORObject.Null;
23812386
} else {
23822387
mapKey = ((key instanceof CBORObject) ? (CBORObject)key : null);
2383-
mapKey = (mapKey == null) ? (CBORObject.FromObject(key)) : mapKey;
2388+
mapKey = (mapKey == null) ? (CBORObject.FromObject(key)) : mapKey;
23842389
}
23852390
if (valueOb == null) {
23862391
mapValue = CBORObject.Null;
23872392
} else {
23882393
mapValue = ((valueOb instanceof CBORObject) ? (CBORObject)valueOb : null);
2389-
mapValue = (mapValue == null) ? (CBORObject.FromObject(valueOb)) : mapValue;
2394+
mapValue = (mapValue == null) ? (CBORObject.FromObject(valueOb)) : mapValue;
23902395
}
23912396
Map<CBORObject, CBORObject> map = this.AsMap();
23922397
if (map.containsKey(mapKey)) {
@@ -3163,7 +3168,9 @@ public byte[] EncodeToBytes(CBOREncodeOptions options) {
31633168
return ms.toByteArray();
31643169
}
31653170
finally {
3166-
try { if (ms != null)ms.close(); } catch (java.io.IOException ex) {}
3171+
try { if (ms != null) {
3172+
ms.close();
3173+
} } catch (java.io.IOException ex) {}
31673174
}
31683175
} catch (IOException ex) {
31693176
throw new CBORException("I/O Error occurred", ex);
@@ -3432,7 +3439,7 @@ public CBORObject Insert(int index, Object valueOb) {
34323439
mapValue = CBORObject.Null;
34333440
} else {
34343441
mapValue = ((valueOb instanceof CBORObject) ? (CBORObject)valueOb : null);
3435-
mapValue = (mapValue == null) ? (CBORObject.FromObject(valueOb)) : mapValue;
3442+
mapValue = (mapValue == null) ? (CBORObject.FromObject(valueOb)) : mapValue;
34363443
}
34373444
list.add(index, mapValue);
34383445
} else {
@@ -3563,13 +3570,13 @@ public CBORObject Set(Object key, Object valueOb) {
35633570
mapKey = CBORObject.Null;
35643571
} else {
35653572
mapKey = ((key instanceof CBORObject) ? (CBORObject)key : null);
3566-
mapKey = (mapKey == null) ? (CBORObject.FromObject(key)) : mapKey;
3573+
mapKey = (mapKey == null) ? (CBORObject.FromObject(key)) : mapKey;
35673574
}
35683575
if (valueOb == null) {
35693576
mapValue = CBORObject.Null;
35703577
} else {
35713578
mapValue = ((valueOb instanceof CBORObject) ? (CBORObject)valueOb : null);
3572-
mapValue = (mapValue == null) ? (CBORObject.FromObject(valueOb)) : mapValue;
3579+
mapValue = (mapValue == null) ? (CBORObject.FromObject(valueOb)) : mapValue;
35733580
}
35743581
Map<CBORObject, CBORObject> map = this.AsMap();
35753582
if (map.containsKey(mapKey)) {
@@ -3681,7 +3688,7 @@ public String ToJSONString() {
36813688
}
36823689
sb.append(simvalue);
36833690
} else {
3684-
sb = (sb == null) ? ((new StringBuilder())) : sb;
3691+
sb = (sb == null) ? ((new StringBuilder())) : sb;
36853692
sb.append("simple(");
36863693
int thisItemInt = ((Integer)this.getThisItem()).intValue();
36873694
sb.append(
@@ -3739,7 +3746,7 @@ public String ToJSONString() {
37393746
break;
37403747
}
37413748
case CBORObjectTypeByteString: {
3742-
sb = (sb == null) ? ((new StringBuilder())) : sb;
3749+
sb = (sb == null) ? ((new StringBuilder())) : sb;
37433750
sb.append("h'");
37443751
CBORUtilities.ToBase16(sb, (byte[])this.getThisItem());
37453752
sb.append("'");
@@ -3755,7 +3762,7 @@ public String ToJSONString() {
37553762
break;
37563763
}
37573764
case CBORObjectTypeArray: {
3758-
sb = (sb == null) ? ((new StringBuilder())) : sb;
3765+
sb = (sb == null) ? ((new StringBuilder())) : sb;
37593766
boolean first = true;
37603767
sb.append("[");
37613768
for (CBORObject i : this.AsList()) {
@@ -3769,7 +3776,7 @@ public String ToJSONString() {
37693776
break;
37703777
}
37713778
case CBORObjectTypeMap: {
3772-
sb = (sb == null) ? ((new StringBuilder())) : sb;
3779+
sb = (sb == null) ? ((new StringBuilder())) : sb;
37733780
boolean first = true;
37743781
sb.append("{");
37753782
Map<CBORObject, CBORObject> map = this.AsMap();
@@ -4136,13 +4143,13 @@ List<CBORObject> AsList() {
41364143
Map<CBORObject, CBORObject> AsMap() {
41374144
return (Map<CBORObject, CBORObject>)this.getThisItem();
41384145
}
4139-
4146+
/*
41404147
void Redefine(CBORObject cbor) {
41414148
this.itemtypeValue = cbor.itemtypeValue;
41424149
this.tagLow = cbor.tagLow;
41434150
this.tagHigh = cbor.tagHigh;
41444151
this.itemValue = cbor.itemValue;
4145-
}
4152+
} */
41464153

41474154
private static boolean BigIntFits(EInteger bigint) {
41484155
return bigint.GetSignedBitLength() <= 64;
@@ -4238,7 +4245,7 @@ private static int CBORMapHashCode(Map<CBORObject, CBORObject> a) {
42384245
// how CBORObjects ought to be compared (since a stable
42394246
// sort order is necessary for two equal maps to have the
42404247
// same hash code), which is much too difficult to do.
4241-
return (a.size() * 19);
4248+
return a.size() * 19;
42424249
}
42434250

42444251
private static void CheckCBORLength(

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,10 @@ public CBORObject ReadForFirstByte(
499499
this.sharedRefs.AddObject(o);
500500
}
501501
if (tagObject != null) {
502-
tagObject.Redefine(o);
503-
o = tagObject;
502+
// TODO: Somehow implement sharable objects
503+
// without relying on Redefine method
504+
// tagObject.Redefine(o);
505+
// o = tagObject;
504506
}
505507

506508
break;

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ private static int StringToInt(String str) {
4040
}
4141
}
4242
ret += x;
43-
}
43+
} else {
44+
throw new NumberFormatException();
45+
}
4446
}
4547
return neg ? -ret : ret;
4648
}
@@ -77,7 +79,9 @@ private static long StringToLong(String str) {
7779
}
7880
}
7981
ret += x;
80-
}
82+
} else {
83+
throw new NumberFormatException();
84+
}
8185
}
8286
return neg ? -ret : ret;
8387
}

src/test/java/com/upokecenter/test/RandomObjects.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
at: http://peteroupc.github.io/
88
*/
99

10-
import com.upokecenter.numbers.*;
1110
import com.upokecenter.util.*;
11+
import com.upokecenter.numbers.*;
1212

1313
/**
1414
* Description of RandomObjects.

src/test/java/com/upokecenter/test/StringAndBigInt.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.upokecenter.test;
22

3-
import com.upokecenter.numbers.*;
43
import com.upokecenter.util.*;
4+
import com.upokecenter.numbers.*;
55

66
final class StringAndBigInt {
77
private static final String ValueDigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -32,7 +32,7 @@ public static StringAndBigInt Generate(RandomGenerator rand, int radix) {
3232
}
3333
EInteger bv = EInteger.FromInt32(0);
3434
StringAndBigInt sabi = new StringAndBigInt();
35-
int numDigits = 1 + rand.UniformInt(100);
35+
int numDigits = 1 + rand.UniformInt(400);
3636
boolean negative = false;
3737
StringBuilder builder = new StringBuilder();
3838
if (rand.UniformInt(2) == 0) {

src/test/java/com/upokecenter/test/URIUtilityTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ private static void assertIdempotency(String s) {
7373
}
7474

7575
private static void assertIdempotencyNeg(String s) {
76-
if (!(!(
77-
(boolean)(Boolean)Reflect.InvokeStatic(
76+
if (!(!((boolean)(Boolean)Reflect.InvokeStatic(
7877
URIUtilityName,
7978
"isValidIRI",
8079
s))))Assert.fail();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.upokecenter.util;
2+
3+
/**
4+
* Interface for random-number generators.
5+
*/
6+
public interface IRandomGen {
7+
/**
8+
* Randomly generates a set of bytes.
9+
* @param bytes Byte buffer to store the random bytes.
10+
* @param offset A zero-based index showing where the desired portion of {@code
11+
* bytes} begins.
12+
* @param length The length, in bytes, of the desired portion of {@code bytes}
13+
* (but not more than {@code bytes} 's length).
14+
* @return Number of bytes returned.
15+
*/
16+
int GetBytes(byte[] bytes, int offset, int length);
17+
}

0 commit comments

Comments
 (0)