Interface TypeProvider<T>

Type Parameters:
T - The type this provider is for
All Known Implementing Classes:
JsonTypeProvider, XmlTypeProvider

public interface TypeProvider<T>
A provider for a specific type.
Used to create, get, set, and merge values of a specific type.

The implementations of this interface are used in Codecs to provide type-specific encoding and decoding.
With this system the Codec can be used for any type,
as long as a TypeProvider is provided for that type.

The most methods in this interface return a Result object.
This is to provide a way to handle errors in the encoding and decoding process.
If the operation was successful, the Result will contain the result of the operation
or if the operation failed, the Result will contain an error message.

  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull Result<T>
    createBoolean(boolean value)
    Creates a boolean value of the type this provider is for using the given value.
    @NotNull Result<T>
    createByte(byte value)
    Creates a byte value of the type this provider is for using the given value.
    @NotNull Result<T>
    createDouble(double value)
    Creates a double value of the type this provider is for using the given value.
    @NotNull Result<T>
    createFloat(float value)
    Creates a float value of the type this provider is for using the given value.
    @NotNull Result<T>
    createInteger(int value)
    Creates an integer value of the type this provider is for using the given value.
    @NotNull Result<T>
    createList(@NotNull List<? extends T> values)
    Creates a list value of the type this provider is for using the given values.
    @NotNull Result<T>
    createLong(long value)
    Creates a long value of the type this provider is for using the given value.
    @NotNull Result<T>
    Creates an empty map value of the type this provider is for.
    @NotNull Result<T>
    createMap(@NotNull Map<String,? extends T> values)
    Creates a map value of the type this provider is for using the given values.
    @NotNull Result<T>
    createShort(short value)
    Creates a short value of the type this provider is for using the given value.
    @NotNull Result<T>
    createString(@NotNull String value)
    Creates a string value of the type this provider is for using the given value.
    Creates an empty value of the type this provider is for.
    @NotNull Result<T>
    get(T type, @NotNull String key)
    Gets the value of the given key from the given value.
    The given type must be a map.
    @NotNull Result<Boolean>
    getBoolean(T type)
    Gets the given value as a boolean value of the type this provider is for.
    @NotNull Result<Byte>
    getByte(T type)
    Gets the given value as a byte value of the type this provider is for.
    @NotNull Result<Double>
    getDouble(T type)
    Gets the given value as a double value of the type this provider is for.
    @NotNull Result<T>
    getEmpty(T type)
    Gets the given value as an empty value of the type this provider is for.
    @NotNull Result<Float>
    getFloat(T type)
    Gets the given value as a float value of the type this provider is for.
    @NotNull Result<Integer>
    getInteger(T type)
    Gets the given value as an integer value of the type this provider is for.
    @NotNull Result<List<T>>
    getList(T type)
    Gets the given value as a list value of the type this provider is for.
    @NotNull Result<Long>
    getLong(T type)
    Gets the given value as a long value of the type this provider is for.
    @NotNull Result<Map<String,T>>
    getMap(T type)
    Gets the given value as a map value of the type this provider is for.
    @NotNull Result<Short>
    getShort(T type)
    Gets the given value as a short value of the type this provider is for.
    @NotNull Result<String>
    getString(T type)
    Gets the given value as a string value of the type this provider is for.
    @NotNull Result<Boolean>
    has(T type, @NotNull String key)
    Checks if the given value is a map and contains the given key.
    The given type must be a map.
    default @NotNull Result<T>
    merge(T current, @NotNull Result<T> value)
    Merges the given value with the current value.
    This is an overloaded method to handle the value as a Result.
    If the given value is a success, the value will be merged.
    If the given value is an error, the value will not be merged and an error result will be returned.
    The logic is specific to the type this provider is for.
    @NotNull Result<T>
    merge(T current, T value)
    Merges the given value with the current value.
    The logic is specific to the type this provider is for.
    default @NotNull Result<T>
    set(T type, @NotNull String key, @NotNull Result<T> value)
    Sets the value for the given key in the given value.
    This is an overloaded method to handle the value as a Result.
    If the given value is a success, the value will be set.
    If the given value is an error, the value will not be set and an error result will be returned.
    @NotNull Result<T>
    set(T type, @NotNull String key, T value)
    Sets the value for the given key in the given value.
    The given type must be a map.
  • Method Details

    • empty

      @NotNull T empty()
      Creates an empty value of the type this provider is for.
      Returns:
      An empty value
    • createBoolean

      @NotNull @NotNull Result<T> createBoolean(boolean value)
      Creates a boolean value of the type this provider is for using the given value.
      Parameters:
      value - The value to create the boolean value from
      Returns:
      A result containing the boolean value
    • createByte

      @NotNull @NotNull Result<T> createByte(byte value)
      Creates a byte value of the type this provider is for using the given value.
      Parameters:
      value - The value to create the byte value from
      Returns:
      A result containing the byte value
    • createShort

      @NotNull @NotNull Result<T> createShort(short value)
      Creates a short value of the type this provider is for using the given value.
      Parameters:
      value - The value to create the short value from
      Returns:
      A result containing the short value
    • createInteger

      @NotNull @NotNull Result<T> createInteger(int value)
      Creates an integer value of the type this provider is for using the given value.
      Parameters:
      value - The value to create the integer value from
      Returns:
      A result containing the integer value
    • createLong

      @NotNull @NotNull Result<T> createLong(long value)
      Creates a long value of the type this provider is for using the given value.
      Parameters:
      value - The value to create the long value from
      Returns:
      A result containing the long value
    • createFloat

      @NotNull @NotNull Result<T> createFloat(float value)
      Creates a float value of the type this provider is for using the given value.
      Parameters:
      value - The value to create the float value from
      Returns:
      A result containing the float value
    • createDouble

      @NotNull @NotNull Result<T> createDouble(double value)
      Creates a double value of the type this provider is for using the given value.
      Parameters:
      value - The value to create the double value from
      Returns:
      A result containing the double value
    • createString

      @NotNull @NotNull Result<T> createString(@NotNull @NotNull String value)
      Creates a string value of the type this provider is for using the given value.
      Parameters:
      value - The value to create the string value from
      Returns:
      A result containing the string value
      Throws:
      NullPointerException - If the given value is null
    • createList

      @NotNull @NotNull Result<T> createList(@NotNull @NotNull List<? extends T> values)
      Creates a list value of the type this provider is for using the given values.
      Parameters:
      values - The values to create the list value from
      Returns:
      A result containing the list value
      Throws:
      NullPointerException - If the given values are null
    • createMap

      @NotNull @NotNull Result<T> createMap()
      Creates an empty map value of the type this provider is for.
      Returns:
      A result containing the empty map value
    • createMap

      @NotNull @NotNull Result<T> createMap(@NotNull @NotNull Map<String,? extends T> values)
      Creates a map value of the type this provider is for using the given values.
      Parameters:
      values - The values to create the map value from
      Returns:
      A result containing the map value
      Throws:
      NullPointerException - If the given values are null
    • getEmpty

      @NotNull @NotNull Result<T> getEmpty(@NotNull T type)
      Gets the given value as an empty value of the type this provider is for.
      Parameters:
      type - The value to get as an empty value
      Returns:
      A success result containing the empty value, or an error result if the given value is not an empty value
      Throws:
      NullPointerException - If the given value is null
    • getBoolean

      @NotNull @NotNull Result<Boolean> getBoolean(@NotNull T type)
      Gets the given value as a boolean value of the type this provider is for.
      Parameters:
      type - The value to get as a boolean value
      Returns:
      A success result containing the boolean value, or an error result if the given value is not a boolean value
      Throws:
      NullPointerException - If the given value is null
    • getByte

      @NotNull @NotNull Result<Byte> getByte(@NotNull T type)
      Gets the given value as a byte value of the type this provider is for.
      Parameters:
      type - The value to get as a byte value
      Returns:
      A success result containing the byte value, or an error result if the given value is not a byte value
      Throws:
      NullPointerException - If the given value is null
    • getShort

      @NotNull @NotNull Result<Short> getShort(@NotNull T type)
      Gets the given value as a short value of the type this provider is for.
      Parameters:
      type - The value to get as a short value
      Returns:
      A success result containing the short value, or an error result if the given value is not a short value
      Throws:
      NullPointerException - If the given value is null
    • getInteger

      @NotNull @NotNull Result<Integer> getInteger(@NotNull T type)
      Gets the given value as an integer value of the type this provider is for.
      Parameters:
      type - The value to get as an integer value
      Returns:
      A success result containing the integer value, or an error result if the given value is not an integer value
      Throws:
      NullPointerException - If the given value is null
    • getLong

      @NotNull @NotNull Result<Long> getLong(@NotNull T type)
      Gets the given value as a long value of the type this provider is for.
      Parameters:
      type - The value to get as a long value
      Returns:
      A success result containing the long value, or an error result if the given value is not a long value
      Throws:
      NullPointerException - If the given value is null
    • getFloat

      @NotNull @NotNull Result<Float> getFloat(@NotNull T type)
      Gets the given value as a float value of the type this provider is for.
      Parameters:
      type - The value to get as a float value
      Returns:
      A success result containing the float value, or an error result if the given value is not a float value
      Throws:
      NullPointerException - If the given value is null
    • getDouble

      @NotNull @NotNull Result<Double> getDouble(@NotNull T type)
      Gets the given value as a double value of the type this provider is for.
      Parameters:
      type - The value to get as a double value
      Returns:
      A success result containing the double value, or an error result if the given value is not a double value
      Throws:
      NullPointerException - If the given value is null
    • getString

      @NotNull @NotNull Result<String> getString(@NotNull T type)
      Gets the given value as a string value of the type this provider is for.
      Parameters:
      type - The value to get as a string value
      Returns:
      A success result containing the string value, or an error result if the given value is not a string value
      Throws:
      NullPointerException - If the given value is null
    • getList

      @NotNull @NotNull Result<List<T>> getList(@NotNull T type)
      Gets the given value as a list value of the type this provider is for.
      Parameters:
      type - The value to get as a list value
      Returns:
      A success result containing the list value, or an error result if the given value is not a list value
      Throws:
      NullPointerException - If the given value is null
    • getMap

      @NotNull @NotNull Result<Map<String,T>> getMap(@NotNull T type)
      Gets the given value as a map value of the type this provider is for.
      Parameters:
      type - The value to get as a map value
      Returns:
      A success result containing the map value, or an error result if the given value is not a map value
      Throws:
      NullPointerException - If the given value is null
    • has

      @NotNull @NotNull Result<Boolean> has(@NotNull T type, @NotNull @NotNull String key)
      Checks if the given value is a map and contains the given key.
      The given type must be a map.
      Parameters:
      type - The value to check
      key - The key to check
      Returns:
      A success result containing true if the map contains the key or false if not, or an error result if the given value is not a map
      Throws:
      NullPointerException - If the given value or key is null
    • get

      @NotNull @NotNull Result<T> get(@NotNull T type, @NotNull @NotNull String key)
      Gets the value of the given key from the given value.
      The given type must be a map.
      Parameters:
      type - The value to get the value from
      key - The key to get the value for
      Returns:
      A success result containing the value for the key, or an error result if the given value is not a map
      Throws:
      NullPointerException - If the given value or key is null
    • set

      @NotNull @NotNull Result<T> set(@NotNull T type, @NotNull @NotNull String key, @NotNull T value)
      Sets the value for the given key in the given value.
      The given type must be a map.
      Parameters:
      type - The value to set the value in
      key - The key to set the value for
      value - The value to set
      Returns:
      A success result containing the result of the set operation, or an error result if the given value is not a map
      Throws:
      NullPointerException - If the given value, key, or value is null
    • set

      @NotNull default @NotNull Result<T> set(@NotNull T type, @NotNull @NotNull String key, @NotNull @NotNull Result<T> value)
      Sets the value for the given key in the given value.
      This is an overloaded method to handle the value as a Result.
      If the given value is a success, the value will be set.
      If the given value is an error, the value will not be set and an error result will be returned.
      Parameters:
      type - The value to set the value in
      key - The key to set the value for
      value - The value to set
      Returns:
      A success result containing the result of the set operation, or an error result if the given value is not a map, or the given value is an error
      Throws:
      NullPointerException - If the given value, key, or value is null
      See Also:
    • merge

      @NotNull @NotNull Result<T> merge(@NotNull T current, @NotNull T value)
      Merges the given value with the current value.
      The logic is specific to the type this provider is for.
      Parameters:
      current - The current value
      value - The value to merge
      Returns:
      A success result containing the result of the merge operation, or an error result if the merge operation failed
      Throws:
      NullPointerException - If the given current value or value is null
    • merge

      @NotNull default @NotNull Result<T> merge(@NotNull T current, @NotNull @NotNull Result<T> value)
      Merges the given value with the current value.
      This is an overloaded method to handle the value as a Result.
      If the given value is a success, the value will be merged.
      If the given value is an error, the value will not be merged and an error result will be returned.
      The logic is specific to the type this provider is for.
      Parameters:
      current - The current value
      value - The value to merge
      Returns:
      A success result containing the result of the merge operation, or an error result if the merge operation failed, or the given value is an error
      Throws:
      NullPointerException - If the given current value or value is null
      See Also: