public class Option<T extends Codec> extends Base<T> implements Codec
An Option is an optional field. Basically the first byte indicates that there is is value to follow. If the byte is 1
there is an actual value. So the Option implements that - decodes, checks for optionality and wraps the required structure with a value if/as required/found.
Constructor and Description |
---|
Option(Types.ConstructorCodec type,
java.lang.Object value) |
Modifier and Type | Method and Description |
---|---|
boolean |
eq(java.lang.Object other)
Compares the value of the input to see if there is a match
|
int |
getEncodedLength()
The length of the value when encoded as a Uint8Array
|
Codec |
getValue()
The actual value for the Option
|
boolean |
isEmpty()
Checks if the Option has no value
|
boolean |
isNone()
Checks if the Option has no value
|
boolean |
isSome()
Checks if the Option has a value
|
java.lang.String |
toHex()
Returns a hex string representation of the value
|
java.lang.Object |
toJson()
Converts the Object to JSON, typically used for RPC transfers
|
java.lang.String |
toString()
Returns the string representation of the value
|
byte[] |
toU8a(boolean isBare)
Encodes the value as a Uint8Array as per the parity-codec specifications
|
T |
unwrap()
Returns the value that the Option represents (if available), throws if null
|
<O> java.lang.Object |
unwrapOr(O defaultValue) |
static <O> Types.ConstructorCodec<Option> |
with(Types.ConstructorCodec type) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getConstructorCodec, toU8a
public Option(Types.ConstructorCodec type, java.lang.Object value)
public static <O> Types.ConstructorCodec<Option> with(Types.ConstructorCodec type)
public int getEncodedLength()
The length of the value when encoded as a Uint8Array
getEncodedLength
in interface Codec
public boolean isNone()
Checks if the Option has no value
public boolean isSome()
Checks if the Option has a value
public boolean isEmpty()
Checks if the Option has no value
public boolean eq(java.lang.Object other)
Compares the value of the input to see if there is a match
public java.lang.String toHex()
Returns a hex string representation of the value
public java.lang.Object toJson()
Converts the Object to JSON, typically used for RPC transfers
public java.lang.String toString()
Returns the string representation of the value
toString
in class java.lang.Object
public byte[] toU8a(boolean isBare)
Encodes the value as a Uint8Array as per the parity-codec specifications
public T unwrap()
Returns the value that the Option represents (if available), throws if null
public <O> java.lang.Object unwrapOr(O defaultValue)
defaultValue
- The value to return if the option isNone Returns the value that the Option represents (if available) or defaultValue if nonepublic Codec getValue()
The actual value for the Option