Class FormattedBigDecimalConversion
- java.lang.Object
-
- com.univocity.parsers.conversions.NullConversion<java.lang.String,T>
-
- com.univocity.parsers.conversions.ObjectConversion<T>
-
- com.univocity.parsers.conversions.NumericConversion<java.math.BigDecimal>
-
- com.univocity.parsers.conversions.FormattedBigDecimalConversion
-
- All Implemented Interfaces:
Conversion<java.lang.String,java.math.BigDecimal>
,FormattedConversion<java.text.DecimalFormat>
public class FormattedBigDecimalConversion extends NumericConversion<java.math.BigDecimal>
Converts formatted Strings to instances ofBigDecimal
and vice versa.This class supports multiple numeric formats. For example, you can define conversions from numbers represented by different Strings such as "1,000,000.00 and $5.00".
The reverse conversion from a BigDecimal to String (in
revert(BigDecimal)
will return a formatted String using the pattern provided in this class constructorThe numeric patterns must follow the pattern rules of
DecimalFormat
- See Also:
DecimalFormat
-
-
Constructor Summary
Constructors Constructor Description FormattedBigDecimalConversion()
Defines a conversion from String toBigDecimal
using a sequence of acceptable numeric patterns.FormattedBigDecimalConversion(java.lang.String... numericFormats)
Defines a conversion from String toBigDecimal
using a sequence of acceptable numeric patterns.FormattedBigDecimalConversion(java.math.BigDecimal valueIfStringIsNull, java.lang.String valueIfObjectIsNull)
Defines a conversion from String toBigDecimal
using a sequence of acceptable numeric patterns.FormattedBigDecimalConversion(java.math.BigDecimal valueIfStringIsNull, java.lang.String valueIfObjectIsNull, java.lang.String... numericFormats)
Defines a conversion from String toBigDecimal
using a sequence of acceptable numeric patterns.FormattedBigDecimalConversion(java.text.DecimalFormat... numericFormatters)
Defines a conversion from String toBigDecimal
using a sequence of acceptable numeric patterns.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
configureFormatter(java.text.DecimalFormat formatter)
Configures the Decimal format instance created by the parent class to parse BigDecimals.-
Methods inherited from class com.univocity.parsers.conversions.NumericConversion
addFormat, fromString, getFormatterObjects, getNumberType, revert, setNumberType
-
Methods inherited from class com.univocity.parsers.conversions.ObjectConversion
execute, fromInput, getValueIfObjectIsNull, getValueIfStringIsNull, setValueIfObjectIsNull, setValueIfStringIsNull, undo
-
Methods inherited from class com.univocity.parsers.conversions.NullConversion
getValueOnNullInput, getValueOnNullOutput, setValueOnNullInput, setValueOnNullOutput
-
-
-
-
Constructor Detail
-
FormattedBigDecimalConversion
public FormattedBigDecimalConversion(java.math.BigDecimal valueIfStringIsNull, java.lang.String valueIfObjectIsNull, java.lang.String... numericFormats)
Defines a conversion from String toBigDecimal
using a sequence of acceptable numeric patterns. This constructor assumes the output of a conversion should be null when input is null- Parameters:
valueIfStringIsNull
- default BigDecimal to be returned when the input String is null. Used whenObjectConversion.execute(String)
is invoked.valueIfObjectIsNull
- default String value to be returned when a BigDecimal input is null. Used whenrevert(BigDecimal)
is invoked.numericFormats
- list of acceptable numeric patterns. The first pattern in this sequence will be used to convert a BigDecimal into a String inrevert(BigDecimal)
.
-
FormattedBigDecimalConversion
public FormattedBigDecimalConversion(java.math.BigDecimal valueIfStringIsNull, java.lang.String valueIfObjectIsNull)
Defines a conversion from String toBigDecimal
using a sequence of acceptable numeric patterns. The patterns must be added to this conversion class through theNumericConversion.addFormat(String, String...)
method.- Parameters:
valueIfStringIsNull
- default BigDecimal to be returned when the input String is null. Used whenObjectConversion.execute(String)
is invoked.valueIfObjectIsNull
- default String value to be returned when a BigDecimal input is null. Used whenNumericConversion.revert(Number)
is invoked.
-
FormattedBigDecimalConversion
public FormattedBigDecimalConversion(java.lang.String... numericFormats)
Defines a conversion from String toBigDecimal
using a sequence of acceptable numeric patterns. This constructor assumes the output of a conversion should be null when input is null- Parameters:
numericFormats
- list of acceptable numeric patterns. The first pattern in this sequence will be used to convert a BigDecimal into a String inNumericConversion.revert(Number)
.
-
FormattedBigDecimalConversion
public FormattedBigDecimalConversion(java.text.DecimalFormat... numericFormatters)
Defines a conversion from String toBigDecimal
using a sequence of acceptable numeric patterns. This constructor assumes the output of a conversion should be null when input is null- Parameters:
numericFormatters
- list formatters of acceptable numeric patterns. The first formatter in this sequence will be used to convert a BigDecimal into a String inNumericConversion.revert(Number)
.
-
FormattedBigDecimalConversion
public FormattedBigDecimalConversion()
Defines a conversion from String toBigDecimal
using a sequence of acceptable numeric patterns. The patterns must be added to this conversion class through theNumericConversion.addFormat(String, String...)
method. This constructor assumes the output of a conversion should be null when input is null
-
-
Method Detail
-
configureFormatter
protected void configureFormatter(java.text.DecimalFormat formatter)
Configures the Decimal format instance created by the parent class to parse BigDecimals.- Specified by:
configureFormatter
in classNumericConversion<java.math.BigDecimal>
- Parameters:
formatter
- a DecimalFormat instance initialized with one of the patterns provided in the constructor of this class.
-
-