public class ParameterConverters
extends java.lang.Object
Facade responsible for converting parameter values to Java objects. It allows
the registration of several ParameterConverters.ParameterConverter
instances, and the
first one that is found to matches the appropriate parameter type is used.
Converters for several Java types are provided out-of-the-box:
Modifier and Type | Class and Description |
---|---|
static class |
ParameterConverters.BooleanConverter |
static class |
ParameterConverters.BooleanListConverter |
static class |
ParameterConverters.DateConverter
Parses value to a
Date using an injectable DateFormat
(defaults to new SimpleDateFormat("dd/MM/yyyy")) |
static class |
ParameterConverters.EnumConverter
Parses value to any
Enum |
static class |
ParameterConverters.EnumListConverter
Parses value to list of the same
Enum , using an injectable value
separator (defaults to ",") and trimming each element of the list. |
static class |
ParameterConverters.ExamplesTableConverter
Converts value to
ExamplesTable using a
ExamplesTableFactory . |
static class |
ParameterConverters.ExamplesTableParametersConverter
Converts ExamplesTable to list of parameters, mapped to annotated custom
types.
|
static class |
ParameterConverters.MethodReturningConverter
Invokes method on instance to return value.
|
static class |
ParameterConverters.NumberConverter
Converts values to numbers, supporting any subclass of
Number
(including generic Number type), and it unboxed counterpart, using a
NumberFormat to parse to a Number and to convert it to a
specific number type:
Byte, byte: Number.byteValue()
Short, short: Number.shortValue()
Integer, int: Number.intValue()
Float, float: Number.floatValue()
Long, long: Number.longValue()
Double, double: Number.doubleValue()
BigInteger: BigInteger#valueOf(Long)
BigDecimal: BigDecimal#valueOf(Double)
If no number format is provided, it defaults to
NumberFormat#getInstance(Locale.ENGLISH) . |
static class |
ParameterConverters.NumberListConverter
Converts value to list of numbers.
|
static interface |
ParameterConverters.ParameterConverter |
static class |
ParameterConverters.ParameterConvertionFailed |
static class |
ParameterConverters.StringListConverter
Converts value to list of String.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_LIST_SEPARATOR |
static java.util.Locale |
DEFAULT_NUMBER_FORMAT_LOCAL |
static StepMonitor |
DEFAULT_STEP_MONITOR |
static boolean |
DEFAULT_THREAD_SAFETY |
Constructor and Description |
---|
ParameterConverters()
Creates a non-thread-safe instance of ParameterConverters using default
dependencies, a SilentStepMonitor, English as Locale and "," as list
separator.
|
ParameterConverters(boolean threadSafe)
Create a ParameterConverters with given thread-safety
|
ParameterConverters(StepMonitor monitor)
Creates a ParameterConverters using given StepMonitor
|
ParameterConverters(StepMonitor monitor,
java.util.Locale locale,
java.lang.String listSeparator,
boolean threadSafe)
Creates a ParameterConverters for the given StepMonitor, Locale, list
separator and thread-safety.
|
Modifier and Type | Method and Description |
---|---|
ParameterConverters |
addConverters(java.util.List<ParameterConverters.ParameterConverter> converters) |
ParameterConverters |
addConverters(ParameterConverters.ParameterConverter... converters) |
java.lang.Object |
convert(java.lang.String value,
java.lang.reflect.Type type) |
protected ParameterConverters.ParameterConverter[] |
defaultConverters(java.util.Locale locale,
java.lang.String listSeparator) |
ParameterConverters |
newInstanceAdding(ParameterConverters.ParameterConverter converter) |
static java.util.List<java.lang.String> |
trim(java.util.List<java.lang.String> values) |
public static final StepMonitor DEFAULT_STEP_MONITOR
public static final java.util.Locale DEFAULT_NUMBER_FORMAT_LOCAL
public static final java.lang.String DEFAULT_LIST_SEPARATOR
public static final boolean DEFAULT_THREAD_SAFETY
public ParameterConverters()
public ParameterConverters(StepMonitor monitor)
monitor
- the StepMonitor to usepublic ParameterConverters(boolean threadSafe)
threadSafe
- the boolean flag to determine if access to
ParameterConverters.ParameterConverter
should be thread-safepublic ParameterConverters(StepMonitor monitor, java.util.Locale locale, java.lang.String listSeparator, boolean threadSafe)
monitor
- the StepMonitor reporting the conversionslocale
- the Locale to use when reading numberslistSeparator
- the String to use as list separatorthreadSafe
- the boolean flag to determine if modification of
ParameterConverters.ParameterConverter
should be thread-safeprotected ParameterConverters.ParameterConverter[] defaultConverters(java.util.Locale locale, java.lang.String listSeparator)
public ParameterConverters addConverters(ParameterConverters.ParameterConverter... converters)
public ParameterConverters addConverters(java.util.List<ParameterConverters.ParameterConverter> converters)
public java.lang.Object convert(java.lang.String value, java.lang.reflect.Type type)
public ParameterConverters newInstanceAdding(ParameterConverters.ParameterConverter converter)
public static java.util.List<java.lang.String> trim(java.util.List<java.lang.String> values)
Copyright © 2003-2014. All Rights Reserved.