java.lang.Object
net.luis.utils.io.codec.provider.JsonTypeProvider
- All Implemented Interfaces:
TypeProvider<JsonElement>
Type provider implementation for json elements.
This class is a singleton and should be accessed through the
This class is a singleton and should be accessed through the
INSTANCE
constant.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final JsonTypeProvider
The singleton instance of this class. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Private constructor to prevent instantiation. -
Method Summary
Modifier and TypeMethodDescription@NotNull Result
<JsonElement> createBoolean
(boolean value) Creates a boolean value of the type this provider is for using the given value.@NotNull Result
<JsonElement> createByte
(byte value) Creates a byte value of the type this provider is for using the given value.@NotNull Result
<JsonElement> createDouble
(double value) Creates a double value of the type this provider is for using the given value.@NotNull Result
<JsonElement> createFloat
(float value) Creates a float value of the type this provider is for using the given value.@NotNull Result
<JsonElement> createInteger
(int value) Creates an integer value of the type this provider is for using the given value.@NotNull Result
<JsonElement> createList
(@NotNull List<? extends JsonElement> values) Creates a list value of the type this provider is for using the given values.@NotNull Result
<JsonElement> createLong
(long value) Creates a long value of the type this provider is for using the given value.@NotNull Result
<JsonElement> Creates an empty map value of the type this provider is for.@NotNull Result
<JsonElement> createMap
(@NotNull Map<String, ? extends JsonElement> values) Creates a map value of the type this provider is for using the given values.@NotNull Result
<JsonElement> createShort
(short value) Creates a short value of the type this provider is for using the given value.@NotNull Result
<JsonElement> createString
(@NotNull String value) Creates a string value of the type this provider is for using the given value.@NotNull JsonElement
empty()
Creates an empty value of the type this provider is for.@NotNull Result
<JsonElement> get
(@NotNull JsonElement type, @NotNull String key) Gets the value of the given key from the given value.
The given type must be a map.getBoolean
(@NotNull JsonElement type) Gets the given value as a boolean value of the type this provider is for.getByte
(@NotNull JsonElement type) Gets the given value as a byte value of the type this provider is for.getDouble
(@NotNull JsonElement type) Gets the given value as a double value of the type this provider is for.@NotNull Result
<JsonElement> getEmpty
(@NotNull JsonElement type) Gets the given value as an empty value of the type this provider is for.getFloat
(@NotNull JsonElement type) Gets the given value as a float value of the type this provider is for.getInteger
(@NotNull JsonElement type) Gets the given value as an integer value of the type this provider is for.@NotNull Result
<List<JsonElement>> getList
(@NotNull JsonElement type) Gets the given value as a list value of the type this provider is for.getLong
(@NotNull JsonElement type) Gets the given value as a long value of the type this provider is for.@NotNull Result
<Map<String, JsonElement>> getMap
(@NotNull JsonElement type) Gets the given value as a map value of the type this provider is for.getShort
(@NotNull JsonElement type) Gets the given value as a short value of the type this provider is for.getString
(@NotNull JsonElement type) Gets the given value as a string value of the type this provider is for.has
(@NotNull JsonElement type, @NotNull String key) Checks if the given value is a map and contains the given key.
The given type must be a map.@NotNull Result
<JsonElement> merge
(@NotNull JsonElement current, @NotNull JsonElement value) Merges the given value with the current value.
The logic is specific to the type this provider is for.@NotNull Result
<JsonElement> set
(@NotNull JsonElement type, @NotNull String key, @NotNull JsonElement value) Sets the value for the given key in the given value.
The given type must be a map.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.luis.utils.io.codec.provider.TypeProvider
merge, set
-
Field Details
-
INSTANCE
The singleton instance of this class.
-
-
Constructor Details
-
JsonTypeProvider
private JsonTypeProvider()Private constructor to prevent instantiation.
-
-
Method Details
-
empty
Description copied from interface:TypeProvider
Creates an empty value of the type this provider is for.- Specified by:
empty
in interfaceTypeProvider<JsonElement>
- Returns:
- An empty value
-
createBoolean
Description copied from interface:TypeProvider
Creates a boolean value of the type this provider is for using the given value.- Specified by:
createBoolean
in interfaceTypeProvider<JsonElement>
- Parameters:
value
- The value to create the boolean value from- Returns:
- A result containing the boolean value
-
createByte
Description copied from interface:TypeProvider
Creates a byte value of the type this provider is for using the given value.- Specified by:
createByte
in interfaceTypeProvider<JsonElement>
- Parameters:
value
- The value to create the byte value from- Returns:
- A result containing the byte value
-
createShort
Description copied from interface:TypeProvider
Creates a short value of the type this provider is for using the given value.- Specified by:
createShort
in interfaceTypeProvider<JsonElement>
- Parameters:
value
- The value to create the short value from- Returns:
- A result containing the short value
-
createInteger
Description copied from interface:TypeProvider
Creates an integer value of the type this provider is for using the given value.- Specified by:
createInteger
in interfaceTypeProvider<JsonElement>
- Parameters:
value
- The value to create the integer value from- Returns:
- A result containing the integer value
-
createLong
Description copied from interface:TypeProvider
Creates a long value of the type this provider is for using the given value.- Specified by:
createLong
in interfaceTypeProvider<JsonElement>
- Parameters:
value
- The value to create the long value from- Returns:
- A result containing the long value
-
createFloat
Description copied from interface:TypeProvider
Creates a float value of the type this provider is for using the given value.- Specified by:
createFloat
in interfaceTypeProvider<JsonElement>
- Parameters:
value
- The value to create the float value from- Returns:
- A result containing the float value
-
createDouble
Description copied from interface:TypeProvider
Creates a double value of the type this provider is for using the given value.- Specified by:
createDouble
in interfaceTypeProvider<JsonElement>
- Parameters:
value
- The value to create the double value from- Returns:
- A result containing the double value
-
createString
Description copied from interface:TypeProvider
Creates a string value of the type this provider is for using the given value.- Specified by:
createString
in interfaceTypeProvider<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 interfaceTypeProvider<JsonElement>
- Parameters:
values
- The values to create the list value from- Returns:
- A result containing the list value
-
createMap
Description copied from interface:TypeProvider
Creates an empty map value of the type this provider is for.- Specified by:
createMap
in interfaceTypeProvider<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 interfaceTypeProvider<JsonElement>
- Parameters:
values
- The values to create the map value from- Returns:
- A result containing the map value
-
getEmpty
Description copied from interface:TypeProvider
Gets the given value as an empty value of the type this provider is for.- Specified by:
getEmpty
in interfaceTypeProvider<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
Description copied from interface:TypeProvider
Gets the given value as a boolean value of the type this provider is for.- Specified by:
getBoolean
in interfaceTypeProvider<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
Description copied from interface:TypeProvider
Gets the given value as a byte value of the type this provider is for.- Specified by:
getByte
in interfaceTypeProvider<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
Description copied from interface:TypeProvider
Gets the given value as a short value of the type this provider is for.- Specified by:
getShort
in interfaceTypeProvider<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
Description copied from interface:TypeProvider
Gets the given value as an integer value of the type this provider is for.- Specified by:
getInteger
in interfaceTypeProvider<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
Description copied from interface:TypeProvider
Gets the given value as a long value of the type this provider is for.- Specified by:
getLong
in interfaceTypeProvider<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
Description copied from interface:TypeProvider
Gets the given value as a float value of the type this provider is for.- Specified by:
getFloat
in interfaceTypeProvider<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
Description copied from interface:TypeProvider
Gets the given value as a double value of the type this provider is for.- Specified by:
getDouble
in interfaceTypeProvider<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
Description copied from interface:TypeProvider
Gets the given value as a string value of the type this provider is for.- Specified by:
getString
in interfaceTypeProvider<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
Description copied from interface:TypeProvider
Gets the given value as a list value of the type this provider is for.- Specified by:
getList
in interfaceTypeProvider<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
Description copied from interface:TypeProvider
Gets the given value as a map value of the type this provider is for.- Specified by:
getMap
in interfaceTypeProvider<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 interfaceTypeProvider<JsonElement>
- Parameters:
type
- The value to checkkey
- 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 interfaceTypeProvider<JsonElement>
- Parameters:
type
- The value to get the value fromkey
- 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 interfaceTypeProvider<JsonElement>
- Parameters:
type
- The value to set the value inkey
- The key to set the value forvalue
- 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 interfaceTypeProvider<JsonElement>
- Parameters:
current
- The current valuevalue
- The value to merge- Returns:
- A success result containing the result of the merge operation, or an error result if the merge operation failed
-