- 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.
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 TypeMethodDescriptioncreateBoolean
(boolean value) Creates a boolean value of the type this provider is for using the given value.createByte
(byte value) Creates a byte value of the type this provider is for using the given value.createDouble
(double value) Creates a double value of the type this provider is for using the given value.createFloat
(float value) Creates a float value of the type this provider is for using the given value.createInteger
(int value) Creates an integer value of the type this provider is for using the given value.createList
(@NotNull List<? extends T> values) Creates a list value of the type this provider is for using the given values.createLong
(long value) Creates a long value of the type this provider is for using the given value.Creates an empty map value of the type this provider is for.Creates a map value of the type this provider is for using the given values.createShort
(short value) Creates a short value of the type this provider is for using the given value.createString
(@NotNull String value) Creates a string value of the type this provider is for using the given value.empty()
Creates an empty value of the type this provider is for.Gets the value of the given key from the given value.
The given type must be a map.getBoolean
(T type) Gets the given value as a boolean value of the type this provider is for.Gets the given value as a byte value of the type this provider is for.Gets the given value as a double value of the type this provider is for.Gets the given value as an empty value of the type this provider is for.Gets the given value as a float value of the type this provider is for.getInteger
(T type) Gets the given value as an integer value of the type this provider is for.Gets the given value as a list value of the type this provider is for.Gets the given value as a long value of the type this provider is for.Gets the given value as a map value of the type this provider is for.Gets the given value as a short value of the type this provider is for.Gets the given value as a string value of the type this provider is for.Checks if the given value is a map and contains the given key.
The given type must be a map.Merges the given value with the current value.
This is an overloaded method to handle the value as aResult
.
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.Merges the given value with the current value.
The logic is specific to the type this provider is for.Sets the value for the given key in the given value.
This is an overloaded method to handle the value as aResult
.
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.Sets the value for the given key in the given value.
The given type must be a map.
-
Method Details
-
empty
Creates an empty value of the type this provider is for.- Returns:
- An empty value
-
createBoolean
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
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
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
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
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
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
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
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
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
Creates an empty map value of the type this provider is for.- Returns:
- A result containing the empty map value
-
createMap
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
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
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
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
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
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
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
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
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
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
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
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
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 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
- Throws:
NullPointerException
- If the given value or key is null
-
get
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 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
- Throws:
NullPointerException
- If the given value or key is null
-
set
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 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
- 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 aResult
.
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 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, or the given value is an error
- Throws:
NullPointerException
- If the given value, key, or value is null- See Also:
-
merge
Merges the given value with the current value.
The logic is specific to the type this provider is for.- 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
- Throws:
NullPointerException
- If the given current value or value is null
-
merge
Merges the given value with the current value.
This is an overloaded method to handle the value as aResult
.
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 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, or the given value is an error
- Throws:
NullPointerException
- If the given current value or value is null- See Also:
-