Package org.symbol.sdk
Class BaseValue<T extends BaseValue<T>>
java.lang.Object
org.symbol.sdk.BaseValue<T>
- Type Parameters:
T- Self-type — the concrete POD extending this class.
- All Implemented Interfaces:
Comparable<T>,Serializer
- Direct Known Subclasses:
Amount,BlockDuration,BlockFeeMultiplier,Difficulty,FinalizationEpoch,FinalizationPoint,Height,Importance,ImportanceHeight,MosaicId,MosaicNonce,MosaicRestrictionKey,NamespaceId,Timestamp,UnresolvedMosaicId
public abstract class BaseValue<T extends BaseValue<T>>
extends Object
implements Serializer, Comparable<T>
- BaseValue
- Fixed-size integer value (amount, height, mosaic id, …) extended by every generated integer POD; F-bounded for a type-safe
Comparable. The backinglongholds an unsigned u64>= 2^63as its negative two's-complement pattern (seevalue()).
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseValue(long value, int size, boolean isSigned) Creates a fixed-size integer value, validating that it fits insizebytes with the given signedness. -
Method Summary
Modifier and TypeMethodDescriptionfinal intfinal booleanfinal inthashCode()final booleanisSigned()Returnstrueif this value should be interpreted as signed.final byte[]Serializes this object to a fresh byte array.final intsize()Returns the size, in bytes, of the serialized form of this object.final ObjecttoJson()Returns the JSON-safe representation: a number for values below 8 bytes, a base-10 string for 8-byte values (which can exceed the 2^53 safe-integer range of JSON readers); unsigned 8-byte values render viaLong.toUnsignedString(long).final StringtoString()final longvalue()Returns the underlying value as along.
-
Constructor Details
-
BaseValue
protected BaseValue(long value, int size, boolean isSigned) Creates a fixed-size integer value, validating that it fits insizebytes with the given signedness.- Parameters:
value- Underlying value as a 64-bit two's-complement bit pattern (unsigned u64 values>= 2^63are stored negative).size- Byte width.isSigned-trueif signed.
-
-
Method Details
-
value
public final long value()- BaseValue.value
- Returns the underlying value as a
long. Javalongis signed, so unsigned 64-bit values>= 2^63are returned as negative numbers; interpret them withLong.toUnsignedString(long)andLong.compareUnsigned(long, long).
- Returns:
- Value (64-bit two's-complement bit pattern).
-
isSigned
public final boolean isSigned()- BaseValue.isSigned
- Returns
trueif this value should be interpreted as signed.
- Returns:
trueif signed.
-
size
public final int size()- BaseValue.size
- Description copied from interface:
Serializer
Returns the size, in bytes, of the serialized form of this object.- Specified by:
sizein interfaceSerializer- Returns:
- Size in bytes.
-
serialize
public final byte[] serialize()- BaseValue.serialize
- Description copied from interface:
Serializer
Serializes this object to a fresh byte array.- Specified by:
serializein interfaceSerializer- Returns:
- Serialized bytes.
-
compareTo
- Specified by:
compareToin interfaceComparable<T extends BaseValue<T>>
-
toJson
- BaseValue.toJson
- Returns the JSON-safe representation: a number for values below 8 bytes, a base-10 string for 8-byte values (which can exceed the 2^53 safe-integer range of JSON readers); unsigned 8-byte values render via
Long.toUnsignedString(long).
- Returns:
- JSON-safe representation of this value.
-
toString
-
equals
-
hashCode
public final int hashCode()
-