Class Option<T extends Codec>

  • All Implemented Interfaces:
    Codec
    Direct Known Subclasses:
    PrefabWasmModule.PrefabWasmModuleReserved

    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.
    • Field Summary

      • Fields inherited from class org.polkadot.types.codec.Base

        raw
    • Method Summary

      Modifier and Type Method 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)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface org.polkadot.types.Codec

        toU8a
    • Method Detail

      • getEncodedLength

        public int getEncodedLength()
        The length of the value when encoded as a Uint8Array
        Specified by:
        getEncodedLength in interface Codec
      • isNone

        public boolean isNone()
        Checks if the Option has no value
      • isSome

        public boolean isSome()
        Checks if the Option has a value
      • isEmpty

        public boolean isEmpty()
        Checks if the Option has no value
        Specified by:
        isEmpty in interface Codec
      • eq

        public boolean eq​(java.lang.Object other)
        Compares the value of the input to see if there is a match
        Specified by:
        eq in interface Codec
      • toHex

        public java.lang.String toHex()
        Returns a hex string representation of the value
        Specified by:
        toHex in interface Codec
      • toJson

        public java.lang.Object toJson()
        Converts the Object to JSON, typically used for RPC transfers
        Specified by:
        toJson in interface Codec
      • toString

        public java.lang.String toString()
        Returns the string representation of the value
        Overrides:
        toString in class java.lang.Object
      • toU8a

        public byte[] toU8a​(boolean isBare)
        Encodes the value as a Uint8Array as per the parity-codec specifications
        Specified by:
        toU8a in interface Codec
        Parameters:
        isBare - true when the value has none of the type-specific prefixes (internal)
      • unwrap

        public T unwrap()
        Returns the value that the Option represents (if available), throws if null
      • unwrapOr

        public <O> java.lang.Object unwrapOr​(O defaultValue)
        Parameters:
        defaultValue - The value to return if the option isNone Returns the value that the Option represents (if available) or defaultValue if none
      • getValue

        public Codec getValue()
        The actual value for the Option