T
- the type to convert from/topublic abstract static class LDValue.Converter<T>
extends java.lang.Object
LDValue
and some other type.
Besides converting individual values, this provides factory methods like arrayOf(T...)
which transform a collection of the specified type to the corresponding LDValue
complex type.
Constructor and Description |
---|
Converter() |
Modifier and Type | Method and Description |
---|---|
LDValue |
arrayFrom(java.lang.Iterable<T> values)
Initializes an
LDValue as an array, from a sequence of this type. |
LDValue |
arrayOf(T... values)
Initializes an
LDValue as an array, from a sequence of this type. |
abstract LDValue |
fromType(T value)
Converts a value of the specified type to an
LDValue . |
LDValue |
objectFrom(java.util.Map<java.lang.String,T> map)
Initializes an
LDValue as an object, from a map containing this type. |
abstract T |
toType(LDValue value)
Converts an
LDValue to a value of the specified type. |
public abstract LDValue fromType(T value)
LDValue
.
This method should never throw an exception; if for some reason the value is invalid,
it should return LDValue.ofNull()
.
value
- a value of this typeLDValue
public abstract T toType(LDValue value)
LDValue
to a value of the specified type.
This method should never throw an exception; if the conversion cannot be done, it should return the default value of the given type (zero for numbers, null for nullable types).
value
- an LDValue
public LDValue arrayFrom(java.lang.Iterable<T> values)
LDValue
as an array, from a sequence of this type.
Values are copied, so subsequent changes to the source values do not affect the array.
Example:
List<Integer> listOfInts = ImmutableList.<Integer>builder().add(1).add(2).add(3).build();
LDValue arrayValue = LDValue.Convert.Integer.arrayFrom(listOfInts);
values
- a sequence of elements of the specified typeLDValue.ofNull()
if the parameter was nullLDValue.buildArray()
public LDValue arrayOf(T... values)
LDValue
as an array, from a sequence of this type.
Values are copied, so subsequent changes to the source values do not affect the array.
Example:
LDValue arrayValue = LDValue.Convert.Integer.arrayOf(1, 2, 3);
values
- a sequence of elements of the specified typeLDValue.ofNull()
if the parameter was nullLDValue.buildArray()
public LDValue objectFrom(java.util.Map<java.lang.String,T> map)
LDValue
as an object, from a map containing this type.
Values are copied, so subsequent changes to the source map do not affect the array.
Example:
Map<String, Integer> mapOfInts = ImmutableMap.<String, Integer>builder().put("a", 1).build();
LDValue objectValue = LDValue.Convert.Integer.objectFrom(mapOfInts);
map
- a map with string keys and values of the specified typeLDValue.ofNull()
if the parameter was nullLDValue.buildObject()