Interface Transcoder<D>

Type Parameters:
D - the intermediary type used by the transcoder
All Known Subinterfaces:
TranscoderProxy<D>
All Known Implementing Classes:
RegistryTranscoder

public interface Transcoder<D>
Transcoders are responsible for converting "primitive" java objects into their respective D types. They are also responsible for unwrapping these objects back to their primitives.
Commonly used transcoders are accessible through static fields like JSON
  • Field Details

  • Method Details

    • createNull

      D createNull()
      Creates a null representation of D
      Returns:
      the null object, never null
    • getBoolean

      Result<Boolean> getBoolean(D value)
      Attempts to unwrap a boolean from the value D
      Parameters:
      value - the value to unwrap
      Returns:
      the result
    • createBoolean

      D createBoolean(boolean value)
      Creates a boolean representation of D
      Parameters:
      value - the boolean primitive
      Returns:
      the representation of value in D
    • getByte

      Result<Byte> getByte(D value)
      Attempts to unwrap a byte from the value D
      Parameters:
      value - the value to unwrap
      Returns:
      the result
    • createByte

      D createByte(byte value)
      Creates a byte representation of D
      Parameters:
      value - the byte primitive
      Returns:
      the representation of value in D
    • getShort

      Result<Short> getShort(D value)
      Attempts to unwrap a short from the value D
      Parameters:
      value - the value to unwrap
      Returns:
      the result
    • createShort

      D createShort(short value)
      Creates a short representation of D
      Parameters:
      value - the short primitive
      Returns:
      the representation of value in D
    • getInt

      Result<Integer> getInt(D value)
      Attempts to unwrap an int from the value D
      Parameters:
      value - the value to unwrap
      Returns:
      the result
    • createInt

      D createInt(int value)
      Creates an int representation of D
      Parameters:
      value - the int primitive
      Returns:
      the representation of value in D
    • getLong

      Result<Long> getLong(D value)
      Attempts to unwrap a long from the value D
      Parameters:
      value - the value to unwrap
      Returns:
      the result
    • createLong

      D createLong(long value)
      Creates a long representation of D
      Parameters:
      value - the long primitive
      Returns:
      the representation of value in D
    • getFloat

      Result<Float> getFloat(D value)
      Attempts to unwrap a float from the value D
      Parameters:
      value - the value to unwrap
      Returns:
      the result
    • createFloat

      D createFloat(float value)
      Creates a float representation of D
      Parameters:
      value - the float primitive
      Returns:
      the representation of value in D
    • getDouble

      Result<Double> getDouble(D value)
      Attempts to unwrap a double from the value D
      Parameters:
      value - the value to unwrap
      Returns:
      the result
    • createDouble

      D createDouble(double value)
      Creates a float representation of D
      Parameters:
      value - the float primitive
      Returns:
      the representation of value in D
    • getString

      Result<String> getString(D value)
      Attempts to unwrap a string from the value D
      Parameters:
      value - the value to unwrap
      Returns:
      the result
    • createString

      D createString(String value)
      Creates a string representation of D
      Parameters:
      value - the string primitive
      Returns:
      the representation of value in D
    • getList

      Result<@Unmodifiable List<D>> getList(D value)
      Attempts to unwrap a list from the value D
      The List decoded possibly has more of D contained inside.
      Parameters:
      value - the value to unwrap
      Returns:
      the result
    • emptyList

      default D emptyList()
      A empty list intermediary
      Returns:
      the empty list intermediary
    • createList

      @Contract(pure=true) Transcoder.ListBuilder<D> createList(int expectedSize)
      Parameters:
      expectedSize - the initial size
      Returns:
      a list builder
    • getMap

      Result<Transcoder.MapLike<D>> getMap(D value)
      Attempts to unwrap a map from the value D
      The Transcoder.MapLike decoded possibly has more of D contained inside.
      Parameters:
      value - the value to unwrap
      Returns:
      the result
    • emptyMap

      default D emptyMap()
      A emtpy map intermediary
      Returns:
      the empty map intermediary
    • createMap

      Returns:
      a new Transcoder.MapBuilder
    • getByteArray

      default Result<byte[]> getByteArray(D value)
      Attempts to unwrap a byte[] from the value D
      Parameters:
      value - the value to unwrap
      Returns:
      the result
    • createByteArray

      default D createByteArray(byte[] value)
      Creates a byte[] representation of D
      Parameters:
      value - the byte array
      Returns:
      D representation of byte[]
    • getIntArray

      default Result<int[]> getIntArray(D value)
      Attempts to unwrap a int[] from the value D
      Parameters:
      value - the value to unwrap
      Returns:
      the result
    • createIntArray

      default D createIntArray(int[] value)
      Creates a int[] representation of D
      Parameters:
      value - the int array
      Returns:
      D representation of int[]
    • getLongArray

      default Result<long[]> getLongArray(D value)
      Attempts to unwrap a long[] from the value D
      Parameters:
      value - the value to unwrap
      Returns:
      the result
    • createLongArray

      default D createLongArray(long[] value)
      Creates a long[] representation of D
      Parameters:
      value - the long array
      Returns:
      D representation of long[]
    • convertTo

      <O> Result<O> convertTo(Transcoder<O> coder, D value)
      Converts the current intermediary of D into intermediary O
      Type Parameters:
      O - the intermediary type to convert to
      Parameters:
      coder - the transcoder to convert to
      value - the value to convert
      Returns:
      the resultant of the conversion