public class Converters
extends java.lang.Object
Converter and ConverterRegistry| Constructor and Description |
|---|
Converters() |
| Modifier and Type | Method and Description |
|---|---|
static <I,O> org.srplib.conversion.Converter<I,O> |
chain(org.srplib.conversion.Converter... converters)
Converts vararg array of converters into single converter.
|
static <I,O> org.srplib.conversion.Converter<I,O> |
chain(java.util.List<org.srplib.conversion.Converter> converters)
Converts list of converters into single converter.
|
static <I,O> org.srplib.conversion.Converter<I,O> |
choice(java.util.Map<I,O> map)
Creates converter which uses map for value conversion.
|
static <I,O> org.srplib.conversion.Converter<I,O> |
choice(java.util.Map<I,O> map,
O defaultValue)
Creates converter which uses map for value conversion.
|
static <T> org.srplib.conversion.Converter<java.lang.Boolean,T> |
choice(T trueValue,
T falseValue)
Creates converter from boolean value to specified alternatives.
|
static <I,O> org.srplib.conversion.TwoWayConverter<I,O> |
empty()
Returns
EmptyConverter which simply returns passed value back. |
static <T> org.srplib.conversion.Converter<T,java.lang.Boolean> |
equal(T object)
Creates converter from object to boolean.
|
static org.srplib.conversion.ConverterRegistry |
newDefaultRegistry()
Returns default converter registry containing basic converter set.
|
static org.srplib.conversion.ConverterRegistry |
newRegistry()
Returns empty converter registry.
|
static <T extends java.lang.Enum> |
newStringToEnumConverter(java.lang.Class<T> enumClass)
Returns string to enum converter.
|
public static org.srplib.conversion.ConverterRegistry newRegistry()
public static org.srplib.conversion.ConverterRegistry newDefaultRegistry()
public static <I,O> org.srplib.conversion.TwoWayConverter<I,O> empty()
EmptyConverter which simply returns passed value back.EmptyConverterpublic static <T extends java.lang.Enum> org.srplib.conversion.Converter<java.lang.String,T> newStringToEnumConverter(java.lang.Class<T> enumClass)
Call to this method is equivalent to new StringToEnumConverter
enumClass - Class class of enumpublic static <T> org.srplib.conversion.Converter<java.lang.Boolean,T> choice(T trueValue,
T falseValue)
Converter may be considered as IF (input) THEN trueValue ELSE falseValue
trueValue - a value to return if input value is truefalseValue - a value to return if input value is falsepublic static <I,O> org.srplib.conversion.Converter<I,O> choice(java.util.Map<I,O> map,
O defaultValue)
Converter may be considered as SWITCH (input) OF ... DEFAULT
map - Map a map where input values are keys and values are output values.defaultValue - Object default value if no matches found in mapSwitchConverterpublic static <I,O> org.srplib.conversion.Converter<I,O> choice(java.util.Map<I,O> map)
Unlike choice(Map, Object) this method doesn't accept default value and throws
IllegalStateException if no mapping is found.
map - Map a map where input values are keys and values are output values.SwitchConverterpublic static <I,O> org.srplib.conversion.Converter<I,O> chain(org.srplib.conversion.Converter... converters)
Method is useful when you have serveral converters but API expect single instance. So you can make a chain of converters.
If converters is null or empty then empty() converter is returned (null-value)
If converters.length == 1 then converters[0] is returned
If converters.length > 1 then ChainConverter is returned.
converters - vararg of Converterpublic static <I,O> org.srplib.conversion.Converter<I,O> chain(java.util.List<org.srplib.conversion.Converter> converters)
Method is similar to chain(Converter[]).
converters - vararg of Converterpublic static <T> org.srplib.conversion.Converter<T,java.lang.Boolean> equal(T object)
Converter will return true if object is equal to specified object.
object - an object to compare to. Nulls are accepted.