Class JsonTypeProvider

java.lang.Object
net.luis.utils.io.codec.provider.JsonTypeProvider
All Implemented Interfaces:
TypeProvider<JsonElement>

@Singleton public final class JsonTypeProvider extends Object implements TypeProvider<JsonElement>
Type provider implementation for json elements.
This class is a singleton and should be accessed through the INSTANCE constant.
  • Field Details

    • INSTANCE

      public static final JsonTypeProvider INSTANCE
      The singleton instance of this class.
  • Constructor Details

    • JsonTypeProvider

      private JsonTypeProvider()
      Private constructor to prevent instantiation.
  • Method Details

    • empty

      @NotNull public @NotNull JsonElement empty()
      Description copied from interface: TypeProvider
      Creates an empty value of the type this provider is for.
      Specified by:
      empty in interface TypeProvider<JsonElement>
      Returns:
      An empty value
    • createBoolean

      @NotNull public @NotNull Result<JsonElement> createBoolean(boolean value)
      Description copied from interface: TypeProvider
      Creates a boolean value of the type this provider is for using the given value.
      Specified by:
      createBoolean in interface TypeProvider<JsonElement>
      Parameters:
      value - The value to create the boolean value from
      Returns:
      A result containing the boolean value
    • createByte

      @NotNull public @NotNull Result<JsonElement> createByte(byte value)
      Description copied from interface: TypeProvider
      Creates a byte value of the type this provider is for using the given value.
      Specified by:
      createByte in interface TypeProvider<JsonElement>
      Parameters:
      value - The value to create the byte value from
      Returns:
      A result containing the byte value
    • createShort

      @NotNull public @NotNull Result<JsonElement> createShort(short value)
      Description copied from interface: TypeProvider
      Creates a short value of the type this provider is for using the given value.
      Specified by:
      createShort in interface TypeProvider<JsonElement>
      Parameters:
      value - The value to create the short value from
      Returns:
      A result containing the short value
    • createInteger

      @NotNull public @NotNull Result<JsonElement> createInteger(int value)
      Description copied from interface: TypeProvider
      Creates an integer value of the type this provider is for using the given value.
      Specified by:
      createInteger in interface TypeProvider<JsonElement>
      Parameters:
      value - The value to create the integer value from
      Returns:
      A result containing the integer value
    • createLong

      @NotNull public @NotNull Result<JsonElement> createLong(long value)
      Description copied from interface: TypeProvider
      Creates a long value of the type this provider is for using the given value.
      Specified by:
      createLong in interface TypeProvider<JsonElement>
      Parameters:
      value - The value to create the long value from
      Returns:
      A result containing the long value
    • createFloat

      @NotNull public @NotNull Result<JsonElement> createFloat(float value)
      Description copied from interface: TypeProvider
      Creates a float value of the type this provider is for using the given value.
      Specified by:
      createFloat in interface TypeProvider<JsonElement>
      Parameters:
      value - The value to create the float value from
      Returns:
      A result containing the float value
    • createDouble

      @NotNull public @NotNull Result<JsonElement> createDouble(double value)
      Description copied from interface: TypeProvider
      Creates a double value of the type this provider is for using the given value.
      Specified by:
      createDouble in interface TypeProvider<JsonElement>
      Parameters:
      value - The value to create the double value from
      Returns:
      A result containing the double value
    • createString

      @NotNull public @NotNull Result<JsonElement> createString(@NotNull @NotNull String value)
      Description copied from interface: TypeProvider
      Creates a string value of the type this provider is for using the given value.
      Specified by:
      createString in interface TypeProvider<JsonElement>
      Parameters:
      value - The value to create the string value from
      Returns:
      A result containing the string value
    • createList

      @NotNull public @NotNull Result<JsonElement> createList(@NotNull @NotNull List<? extends JsonElement> values)
      Description copied from interface: TypeProvider
      Creates a list value of the type this provider is for using the given values.
      Specified by:
      createList in interface TypeProvider<JsonElement>
      Parameters:
      values - The values to create the list value from
      Returns:
      A result containing the list value
    • createMap

      @NotNull public @NotNull Result<JsonElement> createMap()
      Description copied from interface: TypeProvider
      Creates an empty map value of the type this provider is for.
      Specified by:
      createMap in interface TypeProvider<JsonElement>
      Returns:
      A result containing the empty map value
    • createMap

      @NotNull public @NotNull Result<JsonElement> createMap(@NotNull @NotNull Map<String,? extends JsonElement> values)
      Description copied from interface: TypeProvider
      Creates a map value of the type this provider is for using the given values.
      Specified by:
      createMap in interface TypeProvider<JsonElement>
      Parameters:
      values - The values to create the map value from
      Returns:
      A result containing the map value
    • getEmpty

      @NotNull public @NotNull Result<JsonElement> getEmpty(@NotNull @NotNull JsonElement type)
      Description copied from interface: TypeProvider
      Gets the given value as an empty value of the type this provider is for.
      Specified by:
      getEmpty in interface TypeProvider<JsonElement>
      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
    • getBoolean

      @NotNull public @NotNull Result<Boolean> getBoolean(@NotNull @NotNull JsonElement type)
      Description copied from interface: TypeProvider
      Gets the given value as a boolean value of the type this provider is for.
      Specified by:
      getBoolean in interface TypeProvider<JsonElement>
      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
    • getByte

      @NotNull public @NotNull Result<Byte> getByte(@NotNull @NotNull JsonElement type)
      Description copied from interface: TypeProvider
      Gets the given value as a byte value of the type this provider is for.
      Specified by:
      getByte in interface TypeProvider<JsonElement>
      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
    • getShort

      @NotNull public @NotNull Result<Short> getShort(@NotNull @NotNull JsonElement type)
      Description copied from interface: TypeProvider
      Gets the given value as a short value of the type this provider is for.
      Specified by:
      getShort in interface TypeProvider<JsonElement>
      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
    • getInteger

      @NotNull public @NotNull Result<Integer> getInteger(@NotNull @NotNull JsonElement type)
      Description copied from interface: TypeProvider
      Gets the given value as an integer value of the type this provider is for.
      Specified by:
      getInteger in interface TypeProvider<JsonElement>
      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
    • getLong

      @NotNull public @NotNull Result<Long> getLong(@NotNull @NotNull JsonElement type)
      Description copied from interface: TypeProvider
      Gets the given value as a long value of the type this provider is for.
      Specified by:
      getLong in interface TypeProvider<JsonElement>
      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
    • getFloat

      @NotNull public @NotNull Result<Float> getFloat(@NotNull @NotNull JsonElement type)
      Description copied from interface: TypeProvider
      Gets the given value as a float value of the type this provider is for.
      Specified by:
      getFloat in interface TypeProvider<JsonElement>
      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
    • getDouble

      @NotNull public @NotNull Result<Double> getDouble(@NotNull @NotNull JsonElement type)
      Description copied from interface: TypeProvider
      Gets the given value as a double value of the type this provider is for.
      Specified by:
      getDouble in interface TypeProvider<JsonElement>
      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
    • getString

      @NotNull public @NotNull Result<String> getString(@NotNull @NotNull JsonElement type)
      Description copied from interface: TypeProvider
      Gets the given value as a string value of the type this provider is for.
      Specified by:
      getString in interface TypeProvider<JsonElement>
      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
    • getList

      @NotNull public @NotNull Result<List<JsonElement>> getList(@NotNull @NotNull JsonElement type)
      Description copied from interface: TypeProvider
      Gets the given value as a list value of the type this provider is for.
      Specified by:
      getList in interface TypeProvider<JsonElement>
      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
    • getMap

      @NotNull public @NotNull Result<Map<String,JsonElement>> getMap(@NotNull @NotNull JsonElement type)
      Description copied from interface: TypeProvider
      Gets the given value as a map value of the type this provider is for.
      Specified by:
      getMap in interface TypeProvider<JsonElement>
      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
    • has

      @NotNull public @NotNull Result<Boolean> has(@NotNull @NotNull JsonElement type, @NotNull @NotNull String key)
      Description copied from interface: TypeProvider
      Checks if the given value is a map and contains the given key.
      The given type must be a map.
      Specified by:
      has in interface TypeProvider<JsonElement>
      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
    • get

      @NotNull public @NotNull Result<JsonElement> get(@NotNull @NotNull JsonElement type, @NotNull @NotNull String key)
      Description copied from interface: TypeProvider
      Gets the value of the given key from the given value.
      The given type must be a map.
      Specified by:
      get in interface TypeProvider<JsonElement>
      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
    • set

      @NotNull public @NotNull Result<JsonElement> set(@NotNull @NotNull JsonElement type, @NotNull @NotNull String key, @NotNull @NotNull JsonElement value)
      Description copied from interface: TypeProvider
      Sets the value for the given key in the given value.
      The given type must be a map.
      Specified by:
      set in interface TypeProvider<JsonElement>
      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
    • merge

      @NotNull public @NotNull Result<JsonElement> merge(@NotNull @NotNull JsonElement current, @NotNull @NotNull JsonElement value)
      Description copied from interface: TypeProvider
      Merges the given value with the current value.
      The logic is specific to the type this provider is for.
      Specified by:
      merge in interface TypeProvider<JsonElement>
      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