public abstract class CborFloat extends CborObject implements CborNumber
| Modifier and Type | Field and Description |
|---|---|
static int |
TYPE_DOUBLE
Value of the "additional information" field when contained value is an eight-byte
double-float.
|
static int |
TYPE_FLOAT
Value of the "additional information" field when contained value is a four-byte float.
|
static int |
TYPE_HALF
Value of the "additional information" field when contained value is a two-byte half-float.
|
| Modifier and Type | Method and Description |
|---|---|
BigInteger |
bigIntegerValue() |
CborFloat |
copy()
Creates an independent, deep copy of this data item.
|
static CborFloat |
create(double value)
Creates an untagged
CborFloat instance that will be encoded as an eight-byte
double-float. |
static CborFloat |
create(double value,
int tag)
Creates a tagged
CborFloat instance that will be encoded as a eight-byte
double-float. |
static CborFloat |
create(float value)
Creates an untagged
CborFloat instance that will be encoded as a four-byte float. |
static CborFloat |
create(float value,
int tag)
Creates a tagged
CborFloat instance that will be encoded as a four-byte float. |
static CborFloat |
createHalf(float value)
Creates an untagged
CborFloat instance that will be encoded as a two-byte half-float. |
static CborFloat |
createHalf(float value,
int tag)
Creates a tagged
CborFloat instance that will be encoded as a two-byte half-float. |
abstract double |
doubleValue()
Returns the value of this data item as a
double. |
boolean |
equals(Object obj) |
abstract float |
floatValue()
Returns the value of this data item as a
float. |
int |
getMajorType()
Returns the object's "Major Type", as defined by RFC7049.
|
int |
hashCode() |
boolean |
isValidJson()
Indicates if this data item can be losslessly converted to a JSON fragment.
|
long |
longValue()
Returns the value of the integer as a
long. |
Number |
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()
Describes this data item using CBOR diagnostic notation.
|
String |
toString(int ignore)
Describes this data item using CBOR diagnostic notation at the given indentation level.
|
createFromCborByteArray, createFromCborByteArray, createFromJavaObject, getAdditionalInformation, getTag, toCborByteArrayclone, finalize, getClass, notify, notifyAll, wait, wait, waitbyteValueExact, intValueExact, shortValueExactpublic static final int TYPE_HALF
public static final int TYPE_FLOAT
public static final int TYPE_DOUBLE
public static CborFloat createHalf(float value)
CborFloat instance that will be encoded as a two-byte half-float.public static CborFloat createHalf(float value, int tag)
CborFloat instance that will be encoded as a two-byte half-float.public static CborFloat create(float value)
CborFloat instance that will be encoded as a four-byte float.public static CborFloat create(float value, int tag)
CborFloat instance that will be encoded as a four-byte float.public static CborFloat create(double value)
CborFloat instance that will be encoded as an eight-byte
double-float.public static CborFloat create(double value, int tag)
CborFloat instance that will be encoded as a eight-byte
double-float.public abstract float floatValue()
CborNumberfloat.floatValue in interface CborNumberpublic abstract double doubleValue()
CborNumberdouble.doubleValue in interface CborNumberpublic final long longValue()
CborNumberlong. If the underlying value is a floating
point number, then the result is the floor of that value.longValue in interface CborNumberlong value of this object.public final BigInteger bigIntegerValue()
bigIntegerValue in interface CborNumberpublic final int getMajorType()
CborObjectgetMajorType in class CborObjectCborMajorType,
CborObject.getAdditionalInformation()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 final CborFloat copy()
CborObjectcopy in class CborObjectCborObjectpublic final 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 Number 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 String toString(int ignore)
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 CborObjectignore - 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()public String toString()
CborObjectNo additional whitespace is added for readability.
The 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 CborObjectString describing the data item.CborObject.toString(int)Copyright © 2018–2023. All rights reserved.