Skip to content

Commit 8725cd6

Browse files
committed
update Java version
1 parent ef9bcf8 commit 8725cd6

File tree

6 files changed

+399
-388
lines changed

6 files changed

+399
-388
lines changed

api/com.upokecenter.cbor.CBORObject.md

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@
351351
java.lang.Object valueOb)`<br>
352352
Inserts an object at the specified position in this CBOR array.
353353
* `boolean isFalse()`<br>
354-
Gets a value indicating whether this value is a CBOR false value.
354+
Gets a value indicating whether this value is a CBOR false value, whether
355+
tagged or not.
355356
* `boolean isFinite()`<br>
356357
Gets a value indicating whether this CBOR object represents a finite number.
357358
* `boolean IsInfinity()`<br>
@@ -378,7 +379,8 @@
378379
* `boolean isTagged()`<br>
379380
Gets a value indicating whether this data item has at least one tag.
380381
* `boolean isTrue()`<br>
381-
Gets a value indicating whether this value is a CBOR true value.
382+
Gets a value indicating whether this value is a CBOR true value, whether
383+
tagged or not.
382384
* `boolean isUndefined()`<br>
383385
Gets a value indicating whether this value is a CBOR undefined value.
384386
* `boolean isZero()`<br>
@@ -637,11 +639,12 @@ Gets the last defined tag for this CBOR data item, or -1 if the item is
637639

638640
### isFalse
639641
public final boolean isFalse()
640-
Gets a value indicating whether this value is a CBOR false value.
642+
Gets a value indicating whether this value is a CBOR false value, whether
643+
tagged or not.
641644

642645
**Returns:**
643646

644-
* <code>true</code> If this value is a CBOR false value; otherwise, <code>
647+
* <code>true</code> if this value is a CBOR false value; otherwise, <code>
645648
false</code>.
646649

647650
### isFinite
@@ -650,7 +653,7 @@ Gets a value indicating whether this CBOR object represents a finite number.
650653

651654
**Returns:**
652655

653-
* <code>true</code> If this CBOR object represents a finite number;
656+
* <code>true</code> if this CBOR object represents a finite number;
654657
otherwise, <code>false</code>.
655658

656659
### isIntegral
@@ -661,7 +664,7 @@ Gets a value indicating whether this object represents an integer number,
661664

662665
**Returns:**
663666

664-
* <code>true</code> If this object represents an integer number, that is, a
667+
* <code>true</code> if this object represents an integer number, that is, a
665668
number without a fractional part; otherwise, <code>false</code>.
666669

667670
### isNull
@@ -670,7 +673,7 @@ Gets a value indicating whether this value is a CBOR null value.
670673

671674
**Returns:**
672675

673-
* <code>true</code> If this value is a CBOR null value; otherwise, <code>
676+
* <code>true</code> if this value is a CBOR null value; otherwise, <code>
674677
false</code>.
675678

676679
### isTagged
@@ -679,16 +682,17 @@ Gets a value indicating whether this data item has at least one tag.
679682

680683
**Returns:**
681684

682-
* <code>true</code> If this data item has at least one tag; otherwise,
685+
* <code>true</code> if this data item has at least one tag; otherwise,
683686
<code>false</code>.
684687

685688
### isTrue
686689
public final boolean isTrue()
687-
Gets a value indicating whether this value is a CBOR true value.
690+
Gets a value indicating whether this value is a CBOR true value, whether
691+
tagged or not.
688692

689693
**Returns:**
690694

691-
* <code>true</code> If this value is a CBOR true value; otherwise, <code>
695+
* <code>true</code> if this value is a CBOR true value; otherwise, <code>
692696
false</code>.
693697

694698
### isUndefined
@@ -697,7 +701,7 @@ Gets a value indicating whether this value is a CBOR undefined value.
697701

698702
**Returns:**
699703

700-
* <code>true</code> If this value is a CBOR undefined value; otherwise,
704+
* <code>true</code> if this value is a CBOR undefined value; otherwise,
701705
<code>false</code>.
702706

703707
### isZero
@@ -706,7 +710,7 @@ Gets a value indicating whether this object's value equals 0.
706710

707711
**Returns:**
708712

709-
* <code>true</code> If this object's value equals 0; otherwise, <code>
713+
* <code>true</code> if this object's value equals 0; otherwise, <code>
710714
false</code>.
711715

712716
### getKeys
@@ -727,7 +731,7 @@ Gets a value indicating whether this object is a negative number.
727731

728732
**Returns:**
729733

730-
* <code>true</code> If this object is a negative number; otherwise, <code>
734+
* <code>true</code> if this object is a negative number; otherwise, <code>
731735
false</code>.
732736

733737
### getMostOuterTag
@@ -1176,15 +1180,15 @@ Converts this CBOR object to an object of an arbitrary type. See the
11761180
<code>typeof</code> operator. The following example, written in Java, is a
11771181
way to specify that the return value will be an ArrayList of string
11781182
objects.</p> <pre>Type arrayListString = new ParameterizedType() {
1179-
public Type[] getActualTypeArguments() { // Contains one type
1180-
parameter, string return new Type[] { string.class }; } public Type
1181-
getRawType() { /* Raw type is ArrayList */ return ArrayList.class; }
1182-
public Type getOwnerType() { return null; } };
1183+
public Type[] getActualTypeArguments() { /* Contains one type
1184+
parameter, string */ return new Type[] { string.class }; } public
1185+
Type getRawType() { /* Raw type is ArrayList */ return
1186+
ArrayList.class; } public Type getOwnerType() { return null; } };
11831187
ArrayList&lt;string&gt; array = (ArrayList&lt;string&gt;)
11841188
cborArray.ToObject(arrayListString);</pre> <p>By comparison, the C#
11851189
version is much shorter.</p> <pre>List&lt;string&gt; array =
11861190
(List&lt;string&gt;)cborArray.ToObject(
1187-
typeof(List&lt;string&gt;));</pre> .
1191+
typeof(List&lt;string&gt;));</pre>.
11881192

11891193
**Parameters:**
11901194

@@ -1372,39 +1376,41 @@ Converts this CBOR object to an object of an arbitrary type. See the
13721376
the given type for eligible setters as follows:</li> <li>(*) In the
13731377
.NET version, eligible setters are the public, nonstatic setters of
13741378
properties with a public, nonstatic getter. Eligible setters also
1375-
include public, nonstatic, non- <code>readonly</code> fields. If a class
1376-
has two properties and/or fields of the form "X" and "IsX", where
1377-
"X" is any name, or has multiple properties and/or fields with the
1378-
same name, those properties and fields are ignored.</li> <li>(*) In
1379-
the Java version, eligible setters are public, nonstatic methods
1380-
starting with "set" followed by a character other than a basic digit
1381-
or lower-case letter, that is, other than "a" to "z" or "0" to "9",
1382-
that take one parameter. The class containing an eligible setter
1383-
must have a public, nonstatic method with the same name, but
1384-
starting with "get" or "is" rather than "set", that takes no
1385-
parameters and does not return void. (For example, if a class has
1386-
"public setValue(string)" and "public getValue()", "setValue" is an
1387-
eligible setter. However, "setValue()" and "setValue(string, int)"
1388-
are not eligible setters.) In addition, public, nonstatic, nonfinal
1389-
fields are also eligible setters. If a class has two or more
1390-
otherwise eligible setters (methods and/or fields) with the same
1391-
name, but different parameter type, they are not eligible
1392-
setters.</li> <li>Then, the method creates an object of the given
1393-
type and invokes each eligible setter with the corresponding value
1394-
in the CBOR map, if any. Key names in the map are matched to
1395-
eligible setters according to the rules described in the <code>PODOptions</code> documentation. Note that for
1396-
security reasons, certain types are not supported even if they
1379+
include public, nonstatic, non- <code>static final</code> , non- <code>readonly</code>
1380+
fields. If a class has two properties and/or fields of the form "X"
1381+
and "IsX", where "X" is any name, or has multiple properties and/or
1382+
fields with the same name, those properties and fields are
1383+
ignored.</li> <li>(*) In the Java version, eligible setters are
1384+
public, nonstatic methods starting with "set" followed by a
1385+
character other than a basic digit or lower-case letter, that is,
1386+
other than "a" to "z" or "0" to "9", that take one parameter. The
1387+
class containing an eligible setter must have a public, nonstatic
1388+
method with the same name, but starting with "get" or "is" rather
1389+
than "set", that takes no parameters and does not return void. (For
1390+
example, if a class has "public setValue(string)" and "public
1391+
getValue()", "setValue" is an eligible setter. However, "setValue()"
1392+
and "setValue(string, int)" are not eligible setters.) In addition,
1393+
public, nonstatic, nonfinal fields are also eligible setters. If a
1394+
class has two or more otherwise eligible setters (methods and/or
1395+
fields) with the same name, but different parameter type, they are
1396+
not eligible setters.</li> <li>Then, the method creates an object of
1397+
the given type and invokes each eligible setter with the
1398+
corresponding value in the CBOR map, if any. Key names in the map
1399+
are matched to eligible setters according to the rules described in
1400+
the <code>PODOptions</code> documentation. Note that
1401+
for security reasons, certain types are not supported even if they
13971402
contain eligible setters. For the Java version, the object creation
13981403
may fail in the case of a nested nonstatic class.</li> </ul><p>
13991404
</p><p>Java offers no easy way to express a generic type, at least none
14001405
as easy as C#'s <code>typeof</code> operator. The following example,
14011406
written in Java, is a way to specify that the return value will be
14021407
an ArrayList of string objects.</p> <pre>Type arrayListString = new
1403-
ParameterizedType() { public Type[] getActualTypeArguments() { //
1404-
Contains one type parameter, string return new Type[] { string.class
1405-
}; } public Type getRawType() { /* Raw type is ArrayList */ return
1406-
ArrayList.class; } public Type getOwnerType() { return null; } };
1407-
ArrayList&lt;string&gt; array = (ArrayList&lt;string&gt;)
1408+
ParameterizedType() { public Type[] getActualTypeArguments() { /*
1409+
Contains one type parameter, string */ return new Type[] {
1410+
string.class }; } public Type getRawType() { /* Raw type is
1411+
ArrayList */ return ArrayList.class; } public Type getOwnerType() {
1412+
return null; } }; ArrayList&lt;string&gt; array =
1413+
(ArrayList&lt;string&gt;)
14081414
cborArray.ToObject(arrayListString);</pre> <p>By comparison, the C#
14091415
version is much shorter.</p> <pre>List&lt;string&gt; array =
14101416
(List&lt;string&gt;)cborArray.ToObject(
@@ -1833,20 +1839,20 @@ Generates a CBORObject from an arbitrary object. See the overload of this
18331839
In the .NET version, eligible getters are the public, nonstatic
18341840
getters of read/write properties (and also those of read-only
18351841
properties in the case of a compiler-generated type). Eligible
1836-
getters also include public, nonstatic, non- <code>readonly</code> fields.
1837-
If a class has two properties and/or fields of the form "X" and
1838-
"IsX", where "X" is any name, or has multiple properties and/or
1839-
fields with the same name, those properties and fields are
1840-
ignored.</li> <li>(*) In the Java version, eligible getters are
1841-
public, nonstatic methods starting with "get" or "is" (either word
1842-
followed by a character other than a basic digit or lower-case
1843-
letter, that is, other than "a" to "z" or "0" to "9"), that take no
1844-
parameters and do not return void, except that methods named
1845-
"getClass" are not eligible getters. In addition, public, nonstatic,
1846-
nonfinal fields are also eligible getters. If a class has two
1847-
otherwise eligible getters (methods and/or fields) of the form "isX"
1848-
and "getX", where "X" is the same in both, or two such getters with
1849-
the same name but different return type, they are not eligible
1842+
getters also include public, nonstatic, non- <code>static final</code> , non-
1843+
<code>readonly</code> fields. If a class has two properties and/or fields
1844+
of the form "X" and "IsX", where "X" is any name, or has multiple
1845+
properties and/or fields with the same name, those properties and
1846+
fields are ignored.</li> <li>(*) In the Java version, eligible
1847+
getters are public, nonstatic methods starting with "get" or "is"
1848+
(either word followed by a character other than a basic digit or
1849+
lower-case letter, that is, other than "a" to "z" or "0" to "9"),
1850+
that take no parameters and do not return void, except that methods
1851+
named "getClass" are not eligible getters. In addition, public,
1852+
nonstatic, nonfinal fields are also eligible getters. If a class has
1853+
two otherwise eligible getters (methods and/or fields) of the form
1854+
"isX" and "getX", where "X" is the same in both, or two such getters
1855+
with the same name but different return type, they are not eligible
18501856
getters.</li> <li>Then, the method returns a CBOR map with each
18511857
eligible getter's name or property name as each key, and with the
18521858
corresponding value returned by that getter as that key's value.

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,22 @@ public int compare(CBORObject a, CBORObject b) {
128128
}
129129

130130
private static boolean IsArrayOrMap(CBORObject a) {
131-
return a.getType() == CBORType.Array || a.getType() == CBORType.Map;
131+
return a.getType() == CBORType.Array || a.getType() == CBORType.Map;
132132
}
133133

134134
public static byte[] CtapCanonicalEncode(CBORObject a) {
135135
return CtapCanonicalEncode(a, 0);
136136
}
137137

138138
private static boolean ByteArraysEqual(byte[] bytesA, byte[] bytesB) {
139-
if (bytesA == bytesB) {
140-
return true;
141-
}
142-
if (bytesA == null || bytesB == null) {
143-
return false;
144-
}
145-
if (bytesA.length == bytesB.length) {
146-
for (int j = 0; j < bytesA.length; ++j) {
139+
if (bytesA == bytesB) {
140+
return true;
141+
}
142+
if (bytesA == null || bytesB == null) {
143+
return false;
144+
}
145+
if (bytesA.length == bytesB.length) {
146+
for (int j = 0; j < bytesA.length; ++j) {
147147
if (bytesA[j] != bytesB[j]) {
148148
return false;
149149
}

0 commit comments

Comments
 (0)