java.lang.Number and vice versa.
This class supports multiple Number formats. For example, you can define conversions from Numbers represented by different Strings such as "1,000,000.00 and $5.00".
Extending classes must implement the NumericConversion#configureFormatter(DecimalFormat) method to provide specific configuration to the DecimalFormat instance.
The reverse conversion from a Number to String (in NumericConversion#revert(Number) will return a formatted String using the pattern provided in this class constructor
The numeric patterns must follows the pattern rules of java.
java.text.DecimalFormat
| Modifier and Type | Field and Description |
|---|---|
| private String[] | |
| private DecimalFormat[] | |
| private Class | |
| private final ParsePosition |
| Access | Constructor and Description |
|---|---|
| public | NumericConversion(T
default Number to be returned when the input String is null. Used when valueIfStringIsNull, String ObjectConversion#execute(String) is invoked.default String value to be returned when a Number input is null. Used when valueIfObjectIsNull, String... NumericConversion#revert(Number) is invoked.list of acceptable numeric patterns. The first pattern in this sequence will be used to convert a Number into a String in numericFormats)NumericConversion#revert(Number).Defines a conversion from String to |
| public | NumericConversion(T
default Number to be returned when the input String is null. Used when valueIfStringIsNull, String ObjectConversion#execute(String) is invoked.default String value to be returned when a Number input is null. Used when valueIfObjectIsNull, DecimalFormat... NumericConversion#revert(Number) is invoked.list formatters of acceptable numeric patterns. The first formatter in this sequence will be used to convert a Number into a String in numericFormatters)NumericConversion#revert(Number).Defines a conversion from String to |
| public | NumericConversion(T
default Number to be returned when the input String is null. Used when valueIfStringIsNull, String ObjectConversion#execute(String) is invoked.default String value to be returned when a Number input is null. Used when valueIfObjectIsNull)NumericConversion#revert(Number) is invoked.Defines a conversion from String to |
| public | NumericConversion(String...
list of acceptable numeric patterns. The first pattern in this sequence will be used to convert a Number into a String in numericFormats)NumericConversion#revert(Number).Defines a conversion from String to |
| public | NumericConversion(DecimalFormat...
list formatters of acceptable numeric patterns. The first formatter in this sequence will be used to convert a Number into a String in numericFormatters)NumericConversion#revert(Number).Defines a conversion from String to |
| public | NumericConversion()
Defines a conversion from String to |
| Modifier and Type | Method and Description |
|---|---|
| public void | addFormat(String
a numeric pattern. The first pattern added to this class will be used to convert a Number into a String in format, String... NumericConversion#revert(Number).a sequence of properties and their values, used to configure the underlying formatter. Each element must be specified as formatOptions)property_name=property_value,
e.g. options={"decimalSeparator=,", "maximumFractionDigits=3"}Adds a new numeric pattern to be used to parse input Strings and convert them to numbers. |
| protected abstract void | configureFormatter(DecimalFormat
a DecimalFormat instance initialized with one of the patterns provided in the constructor of this class. formatter)Method called by the constructor of this class to apply custom configurations to each formatter instantiated with the numeric formats provided. |
| protected T | Returns: the Number instance containing the value represented by the given String, or the value ofObjectConversion#getValueIfStringIsNull() if the String input is null.the String containing a formatted number which must be converted to a number input)Implements abstract com. |
| public DecimalFormat[] | getFormatterObjects()
Implements com. |
| public Class | Returns: the implementation ofNumber that should be used when converting numeric data.Returns the implementation of |
| public String | Returns: a formatted numeric String representing the value provided by the given Number, or the value ofObjectConversion#getValueIfObjectIsNull() if the Number parameter is null.the Number to be converted to a String input)Overrides com. Implements com. |
| public void | setNumberType(Class<? extends Number>
the implementation of numberType)Number that should be used when converting numeric data.Defines a specific implementation of |
| formats | back to summary |
|---|---|
| private String[] formats | |
| formatters | back to summary |
|---|---|
| private DecimalFormat[] formatters | |
| numberType | back to summary |
|---|---|
| private Class<? extends Number> numberType | |
| position | back to summary |
|---|---|
| private final ParsePosition position | |
| NumericConversion | back to summary |
|---|---|
| public NumericConversion(T valueIfStringIsNull, String valueIfObjectIsNull, String... numericFormats) Defines a conversion from String to
| |
| NumericConversion | back to summary |
|---|---|
| public NumericConversion(T valueIfStringIsNull, String valueIfObjectIsNull, DecimalFormat... numericFormatters) Defines a conversion from String to
| |
| NumericConversion | back to summary |
|---|---|
| public NumericConversion(T valueIfStringIsNull, String valueIfObjectIsNull) Defines a conversion from String to
| |
| NumericConversion | back to summary |
|---|---|
| public NumericConversion(String... numericFormats) Defines a conversion from String to
| |
| NumericConversion | back to summary |
|---|---|
| public NumericConversion(DecimalFormat... numericFormatters) Defines a conversion from String to
| |
| NumericConversion | back to summary |
|---|---|
| public NumericConversion() Defines a conversion from String to | |
| addFormat | back to summary |
|---|---|
| public void addFormat(String format, String... formatOptions) Adds a new numeric pattern to be used to parse input Strings and convert them to numbers.
| |
| configureFormatter | back to summary |
|---|---|
| protected abstract void configureFormatter(DecimalFormat formatter) Method called by the constructor of this class to apply custom configurations to each formatter instantiated with the numeric formats provided.
| |
| fromString | back to summary |
|---|---|
| protected T fromString(String input) Implements abstract com. Converts a formatted numeric String to an instance of Number. The pattern in the formatted input must match one of the numeric patterns provided in the constructor of this class.
| |
| getFormatterObjects | back to summary |
|---|---|
| public DecimalFormat[] getFormatterObjects() Implements com. Doc from com. Returns the formatter objects
| |
| getNumberType | back to summary |
|---|---|
| public Class Returns the implementation of | |
| revert | back to summary |
|---|---|
| public String revert(T input) Overrides com. Implements com. Converts Number to a formatted numeric String. The pattern used to generate the formatted number is the first numeric pattern provided in the constructor of this class
| |
| setNumberType | back to summary |
|---|---|
| public void setNumberType(Class<? extends Number> numberType) Defines a specific implementation of | |