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 JsonTypeProviderThe singleton instance of this class. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate 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 JsonElementempty()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, waitMethods 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:TypeProviderCreates an empty value of the type this provider is for.- Specified by:
emptyin interfaceTypeProvider<JsonElement>- Returns:
- An empty value
-
createBoolean
Description copied from interface:TypeProviderCreates a boolean value of the type this provider is for using the given value.- Specified by:
createBooleanin interfaceTypeProvider<JsonElement>- Parameters:
value- The value to create the boolean value from- Returns:
- A result containing the boolean value
-
createByte
Description copied from interface:TypeProviderCreates a byte value of the type this provider is for using the given value.- Specified by:
createBytein interfaceTypeProvider<JsonElement>- Parameters:
value- The value to create the byte value from- Returns:
- A result containing the byte value
-
createShort
Description copied from interface:TypeProviderCreates a short value of the type this provider is for using the given value.- Specified by:
createShortin interfaceTypeProvider<JsonElement>- Parameters:
value- The value to create the short value from- Returns:
- A result containing the short value
-
createInteger
Description copied from interface:TypeProviderCreates an integer value of the type this provider is for using the given value.- Specified by:
createIntegerin interfaceTypeProvider<JsonElement>- Parameters:
value- The value to create the integer value from- Returns:
- A result containing the integer value
-
createLong
Description copied from interface:TypeProviderCreates a long value of the type this provider is for using the given value.- Specified by:
createLongin interfaceTypeProvider<JsonElement>- Parameters:
value- The value to create the long value from- Returns:
- A result containing the long value
-
createFloat
Description copied from interface:TypeProviderCreates a float value of the type this provider is for using the given value.- Specified by:
createFloatin interfaceTypeProvider<JsonElement>- Parameters:
value- The value to create the float value from- Returns:
- A result containing the float value
-
createDouble
Description copied from interface:TypeProviderCreates a double value of the type this provider is for using the given value.- Specified by:
createDoublein interfaceTypeProvider<JsonElement>- Parameters:
value- The value to create the double value from- Returns:
- A result containing the double value
-
createString
Description copied from interface:TypeProviderCreates a string value of the type this provider is for using the given value.- Specified by:
createStringin 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:TypeProviderCreates a list value of the type this provider is for using the given values.- Specified by:
createListin interfaceTypeProvider<JsonElement>- Parameters:
values- The values to create the list value from- Returns:
- A result containing the list value
-
createMap
Description copied from interface:TypeProviderCreates an empty map value of the type this provider is for.- Specified by:
createMapin 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:TypeProviderCreates a map value of the type this provider is for using the given values.- Specified by:
createMapin interfaceTypeProvider<JsonElement>- Parameters:
values- The values to create the map value from- Returns:
- A result containing the map value
-
getEmpty
Description copied from interface:TypeProviderGets the given value as an empty value of the type this provider is for.- Specified by:
getEmptyin 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:TypeProviderGets the given value as a boolean value of the type this provider is for.- Specified by:
getBooleanin 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:TypeProviderGets the given value as a byte value of the type this provider is for.- Specified by:
getBytein 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:TypeProviderGets the given value as a short value of the type this provider is for.- Specified by:
getShortin 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:TypeProviderGets the given value as an integer value of the type this provider is for.- Specified by:
getIntegerin 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:TypeProviderGets the given value as a long value of the type this provider is for.- Specified by:
getLongin 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:TypeProviderGets the given value as a float value of the type this provider is for.- Specified by:
getFloatin 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:TypeProviderGets the given value as a double value of the type this provider is for.- Specified by:
getDoublein 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:TypeProviderGets the given value as a string value of the type this provider is for.- Specified by:
getStringin 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:TypeProviderGets the given value as a list value of the type this provider is for.- Specified by:
getListin 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:TypeProviderGets the given value as a map value of the type this provider is for.- Specified by:
getMapin 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:TypeProviderChecks if the given value is a map and contains the given key.
The given type must be a map.- Specified by:
hasin 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:TypeProviderGets the value of the given key from the given value.
The given type must be a map.- Specified by:
getin 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:TypeProviderSets the value for the given key in the given value.
The given type must be a map.- Specified by:
setin 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:TypeProviderMerges the given value with the current value.
The logic is specific to the type this provider is for.- Specified by:
mergein 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
-