java.lang.Object
org.praxislive.core.ValueMapper<T>
- Type Parameters:
T- Java type
ValueMappers translate values of type Value to another Java type. See
find(java.lang.Class) to access pre-registered ValueMappers.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedValueMapper(Type type, Class<? extends Value> valueCls) Base constructor.protectedValueMapper(Type type, Value.Type<?> valueType) Base constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ValueMapper<T> Find a ValueMapper capable of mapping Values to and from the provided Class.abstract TMap the provided Value to a value of type T.abstract ValueMap the provided T value to a Value.final Typetype()Type of T.final Value.Type<?> The preferred Value.Type for mapping to type T.
-
Constructor Details
-
ValueMapper
Base constructor.- Parameters:
type- the Java typevalueCls- the Value class
-
ValueMapper
Base constructor.- Parameters:
type- the Java typevalueType- the Value Type
-
-
Method Details
-
fromValue
Map the provided Value to a value of type T. If the input is empty, some implementations may return null. Invalid values may cause an exception.- Parameters:
value- input Value- Returns:
- mapped value, or null
- Throws:
IllegalArgumentException- on invalid input
-
toValue
Map the provided T value to a Value. Invalid input values may cause an exception. Null input is allowed, and will return either the Value Type's empty value if present, orPString.EMPTY.- Parameters:
value- input value- Returns:
- mapped Value (never null)
- Throws:
IllegalArgumentException- on invalid input
-
type
Type of T.- Returns:
- type of T
-
valueType
The preferred Value.Type for mapping to type T. This is the type that Values will be coerced to, and will be the type usually (but not always) returned fromtoValue(java.lang.Object).- Returns:
- preferred value type
-
find
Find a ValueMapper capable of mapping Values to and from the provided Class. Mappers for String, Boolean, Integer, Float and Double are provided, along with their primitive counterparts where applicable. Mappers will be created on demand for any Enum type. Mappers for all registered Value types are provided as a convenience.- Type Parameters:
T- mapped class- Parameters:
type- mapped class- Returns:
- value mapper or null
-