public abstract class CborArray extends CborObject implements Iterable<CborObject>
This class is used to represent data items of major type 4 (CborMajorType.ARRAY).
| Modifier and Type | Method and Description |
|---|---|
void |
add(CborObject cborObject)
Appends the given object to this
CborArray. |
void |
clear()
Removes all items from this
CborArray. |
CborArray |
copy()
Creates an independent, deep copy of this object.
|
static CborArray |
create()
Creates an untagged empty
CborArray. |
static CborArray |
create(int tag)
Creates a tagged empty
CborArray. |
static CborArray |
create(Iterable<CborObject> objs)
Creates an untagged
CborArray populated with the given CborObjects. |
static CborArray |
create(Iterable<CborObject> objs,
int tag)
Creates a tagged
CborArray populated with the given CborObjects. |
static CborArray |
create(Iterable<CborObject> objs,
int tag,
boolean isIndefiniteLength)
Creates a tagged
CborArray populated with the given CborObjects. |
static CborArray |
createFromJavaObject(boolean[] obj)
Converts a boolean array to a
CborArray of CborSimple objects. |
static CborArray |
createFromJavaObject(double[] obj)
|
static CborArray |
createFromJavaObject(float[] obj)
|
static CborArray |
createFromJavaObject(int[] obj)
Converts an integer array to a
CborArray of CborInteger objects. |
static CborArray |
createFromJavaObject(Iterable<?> obj)
|
static CborArray |
createFromJavaObject(long[] obj)
Converts a long array to a
CborArray of CborInteger objects. |
static CborArray |
createFromJavaObject(Object[] obj)
Converts an object array to an untagged
CborArray. |
static CborArray |
createFromJavaObject(short[] obj)
Converts a short array to a
CborArray of CborInteger objects. |
static CborArray |
createFromJSONArray(org.json.JSONArray jsonArray)
Creates a
CborArray from a given JSONArray. |
boolean |
equals(Object obj) |
int |
getAdditionalInformation()
Returns the object's "additional information" value.
|
int |
getMajorType()
Always returns
CborMajorType.ARRAY. |
int |
hashCode() |
boolean |
isEmpty()
Determines if this array is empty or not.
|
abstract boolean |
isIndefiniteLength() |
boolean |
isValidJson()
Indicates if this data item can be losslessly converted to a JSON fragment.
|
@NonNull Iterator<CborObject> |
iterator() |
abstract List<CborObject> |
listValue()
|
boolean |
remove(CborObject cborObject)
Removes the given object from this
CborArray. |
int |
size()
Indicates the number of items in this array.
|
List<Object> |
toJavaObject()
Converts the given data item into a standard java object representation.
|
<T> T |
toJavaObject(Class<T> clazz)
Attempts to convert this data item to a java object with a specific class.
|
String |
toJsonString()
Returns a representation of this data item as JSON text.
|
String |
toString(int indentLevel)
Describes this data item using CBOR diagnostic notation at the given indentation level.
|
createFromCborByteArray, createFromCborByteArray, createFromJavaObject, getTag, toCborByteArray, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic static CborArray create()
CborArray.CborArray instancepublic static CborArray create(int tag)
CborArray.tag - the integer value of the tagCborArray instancepublic static CborArray create(Iterable<CborObject> objs)
CborArray populated with the given CborObjects. The given
CborObjects are used directly and not deep-copied.objs - iterable object (like a Collection)CborArray instancepublic static CborArray create(Iterable<CborObject> objs, int tag)
CborArray populated with the given CborObjects. The given
CborObjects are used directly and not deep-copied.objs - iterable object (like a Collection)tag - the integer value of the tagCborArray instancepublic static CborArray create(Iterable<CborObject> objs, int tag, boolean isIndefiniteLength)
CborArray populated with the given CborObjects. The given
CborObjects are used directly and not deep-copied.objs - iterable object (like a Collection)tag - the integer value of the tagisIndefiniteLength - The array should be serialized as indefinite lengthCborArray instancepublic static CborArray createFromJavaObject(Iterable<?> obj) throws CborConversionException
Iterable of Java objects to an untagged CborArray. Note that this
method differs from create(Iterable) in that this method converts standard Java
objects (like String, Integer, etc) into CborObjects.obj - the iterable of java objects to convertCborArray instanceCborConversionException - if one or more of the contained objects cannot be convertedpublic static CborArray createFromJavaObject(Object[] obj) throws CborConversionException
CborArray.obj - the object array to convertCborArray instanceCborConversionException - if one or more of the contained objects cannot be convertedpublic static CborArray createFromJavaObject(int[] obj)
CborArray of CborInteger objects.obj - the integer array to convertCborArray instancepublic static CborArray createFromJavaObject(short[] obj)
CborArray of CborInteger objects.obj - the short array to convertCborArray instancepublic static CborArray createFromJavaObject(long[] obj)
CborArray of CborInteger objects.obj - the long array to convertCborArray instancepublic static CborArray createFromJavaObject(boolean[] obj)
CborArray of CborSimple objects.obj - the boolean array to convertCborArray instancepublic static CborArray createFromJavaObject(float[] obj)
obj - the float array to convertCborArray instancepublic static CborArray createFromJavaObject(double[] obj)
obj - the double array to convertCborArray instancepublic static CborArray createFromJSONArray(org.json.JSONArray jsonArray)
CborArray from a given JSONArray. The resulting CborArray
is wholly independent from the given JSONArray.CborArray instancepublic abstract List<CborObject> listValue()
List of CborObject instances.public int size()
listValue().size().public boolean isEmpty()
listValue().isEmpty().public void add(CborObject cborObject)
CborArray. This is functionally equivalent to
calling listValue().add(cborObject).cborObject - the object to append@CanIgnoreReturnValue public boolean remove(CborObject cborObject)
CborArray. This is functionally equivalent to
calling listValue().remove(o).cborObject - the object to removepublic void clear()
CborArray. This is functionally equivalent to calling
listValue().clear().public final int getMajorType()
CborMajorType.ARRAY.getMajorType in class CborObjectCborMajorType,
CborObject.getAdditionalInformation()public final int getAdditionalInformation()
CborObjectgetAdditionalInformation in class CborObjectCborObject.getMajorType()public abstract boolean isIndefiniteLength()
public boolean isValidJson()
CborObjectNote that, with few exceptions, tags are not considered in this determination, since CborObject.toJsonString()
will strip out tags anyway.
isValidJson in class CborObjecttrue if this object could be rendered as JSON, false otherwise.public final String toJsonString()
CborObjectThe result is guaranteed to be syntactically-valid RFC8259 JSON text. In the event that there is
no JSON text representation for the underlying data item, its value will be replaced with a
placeholder JSON value (usually "null"). This condition can be detected beforehand
using CborObject.isValidJson().
Note that, in some pre-RFC8259 contexts, this method could be described as returning a
"JSON fragment" unless the data item was of the types CborMap (for a JSON
object) or CborArray (for a JSON array).
toJsonString in class CborObjectString containing representation of this data item as JSON textCborObject.isValidJson(),
RFC8259public List<Object> toJavaObject()
CborObjectTags are largely ignored, except in cases where the tag itself has defined behavior when
converting to JSON, like CborTag.EXPECTED_BASE16 and CborTag.EXPECTED_BASE64.
The resulting object type is dependent on the data item:
CborMap → Map<Object,Object>
CborArray → Collection<Object>
CborFloat → Float/Double
CborInteger → Integer/Long
CborTextString → String
CborByteString → byte[]
CborSimple.TRUE/CborSimple.FALSE → Boolean
CborSimple values → null
The returned value is a wholly independent copy.
toJavaObject in class CborObjectCborObject.createFromJavaObject(Object)public <T> T toJavaObject(Class<T> clazz) throws CborConversionException
CborObjectUnlike CborObject.toJavaObject(), this method will introspect into tags to figure out
conversions to BigInteger and URI. Unknown tags are ignored.
This method will return the most expressive result that satisfies the clazz
parameter. For example, if the data item is a CborByteString tagged CborTag.BIGNUM_POS, calling this method with different classes will lead to different
results:
toJavaObject(byte[].class would return a byte[]
toJavaObject(Object.class would return a BigInteger
toJavaObject(BigInteger.class would return a BigInteger
toJavaObject(URI.class would throw CborConversionException
Whereas this method called an untagged CborByteString would behave like this:
toJavaObject(byte[].class would return a byte[]
toJavaObject(Object.class would return a byte[]
toJavaObject(BigInteger.class would throw CborConversionException
toJavaObject(URI.class would throw CborConversionException
toJavaObject in class CborObjectclazz - The desired class of the returned objectclazz or null if this data item was
CborSimple.NULL or CborSimple.UNDEFINED.CborConversionException - if the underlying data item could not be represented as an
instance of clazz.public CborArray copy()
copy in class CborObjectCborObjectpublic @NonNull Iterator<CborObject> iterator()
iterator in interface Iterable<CborObject>public final String toString(int indentLevel)
CborObjectThe output is similar to that of CborObject.toJsonString() except that it also includes tag
and encoding information that is CBOR-specific.
The returned string is intended as a diagnostic aid and not intended to be machine-readable.
toString in class CborObjectindentLevel - the indentation level of the string to output. A negative value
indicates no newlines or whitespace should be added.String describing the data item.CborObject.toString()Copyright © 2018–2023. All rights reserved.