Class LDValue.Converter<T>
- java.lang.Object
-
- com.launchdarkly.sdk.LDValue.Converter<T>
-
- Type Parameters:
T- the type to convert from/to
- Enclosing class:
- LDValue
public abstract static class LDValue.Converter<T> extends java.lang.ObjectDefines a conversion betweenLDValueand some other type.Besides converting individual values, this provides factory methods like
arrayOf(T...)which transform a collection of the specified type to the correspondingLDValuecomplex type.
-
-
Constructor Summary
Constructors Constructor Description Converter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description LDValuearrayFrom(java.lang.Iterable<T> values)Initializes anLDValueas an array, from a sequence of this type.LDValuearrayOf(T... values)Initializes anLDValueas an array, from a sequence of this type.abstract LDValuefromType(T value)Converts a value of the specified type to anLDValue.LDValueobjectFrom(java.util.Map<java.lang.String,T> map)Initializes anLDValueas an object, from a map containing this type.abstract TtoType(LDValue value)Converts anLDValueto a value of the specified type.
-
-
-
Method Detail
-
fromType
public abstract LDValue fromType(T value)
Converts a value of the specified type to anLDValue.This method should never throw an exception; if for some reason the value is invalid, it should return
LDValue.ofNull().- Parameters:
value- a value of this type- Returns:
- an
LDValue
-
toType
public abstract T toType(LDValue value)
Converts anLDValueto 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).
- Parameters:
value- anLDValue- Returns:
- a value of this type
-
arrayFrom
public LDValue arrayFrom(java.lang.Iterable<T> values)
Initializes anLDValueas 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);- Parameters:
values- a sequence of elements of the specified type- Returns:
- a value representing a JSON array, or
LDValue.ofNull()if the parameter was null - See Also:
LDValue.buildArray()
-
arrayOf
public LDValue arrayOf(T... values)
Initializes anLDValueas 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);- Parameters:
values- a sequence of elements of the specified type- Returns:
- a value representing a JSON array, or
LDValue.ofNull()if the parameter was null - See Also:
LDValue.buildArray()
-
objectFrom
public LDValue objectFrom(java.util.Map<java.lang.String,T> map)
Initializes anLDValueas 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);- Parameters:
map- a map with string keys and values of the specified type- Returns:
- a value representing a JSON object, or
LDValue.ofNull()if the parameter was null - See Also:
LDValue.buildObject()
-
-