Top Description Fields Constructors Methods
com.opencsv.bean

public Class ConverterNumber

extends AbstractCsvConverter
Class Inheritance
Imports
com.opencsv.ICSVParser, com.opencsv.exceptions.CsvBadConverterException, .CsvDataTypeMismatchException, org.apache.commons.lang3.ClassUtils, .ObjectUtils, .StringUtils, java.math.BigDecimal, .BigInteger, .RoundingMode, java.text.DecimalFormat, .NumberFormat, .ParseException, java.util.Locale, .ResourceBundle, java.util.function.UnaryOperator

This converter class is used in combination with CsvNumber, that is, when number inputs and outputs should be formatted.
Author
Andrew Rucker Jones
Since
4.2

Field Summary

Modifier and TypeField and Description
private final UnaryOperator<Number>
private final DecimalFormat
private final DecimalFormat
Inherited from com.opencsv.bean.AbstractCsvConverter:
errorLocalelocaletypewriteLocale

Constructor Summary

AccessConstructor and Description
public
ConverterNumber(Class<?>
The class of the type of the data being processed
type
,
String
If not null or empty, specifies the locale used for converting locale-specific data types for reading
locale
,
String
If not null or empty, specifies the locale used for converting locale-specific data types for writing
writeLocale
,
Locale
The locale to use for error messages
errorLocale
,
String
The string to use for parsing the number.
readFormat
,
String
The string to use for formatting the number.
writeFormat
,
RoundingMode
The rounding mode used when converting java.math.BigDecimals.
roundingMode
)

Method Summary

Modifier and TypeMethod and Description
public Object
convertToRead(String value)

Implements com.opencsv.bean.CsvConverter.convertToRead.

Method for converting from a string to the proper data type of the destination field.

public String
convertToWrite(Object value)

Overrides com.opencsv.bean.AbstractCsvConverter.convertToWrite.

Implements com.opencsv.bean.CsvConverter.convertToWrite.

Formats the number in question according to the pattern that has been provided.

private DecimalFormat
createDecimalFormat(String format, Locale locale, RoundingMode roundingMode)

Inherited from com.opencsv.bean.AbstractCsvConverter:
setErrorLocalesetLocalesetTypesetWriteLocale

Field Detail

readConversionFunctionback to summary
private final UnaryOperator<Number> readConversionFunction
readFormatterback to summary
private final DecimalFormat readFormatter
writeFormatterback to summary
private final DecimalFormat writeFormatter

Constructor Detail

ConverterNumberback to summary
public ConverterNumber(Class<?> type, String locale, String writeLocale, Locale errorLocale, String readFormat, String writeFormat, RoundingMode roundingMode) throws CsvBadConverterException
Parameters
type:Class<?>

The class of the type of the data being processed

locale:String

If not null or empty, specifies the locale used for converting locale-specific data types for reading

writeLocale:String

If not null or empty, specifies the locale used for converting locale-specific data types for writing

errorLocale:Locale

The locale to use for error messages

readFormat:String

The string to use for parsing the number.

writeFormat:String

The string to use for formatting the number.

roundingMode:RoundingMode

The rounding mode used when converting java.math.BigDecimals.

Exceptions
CsvBadConverterException:
If the information given to initialize the converter are inconsistent (e.g. the annotation com.opencsv.bean.CsvNumber has been applied to a non-java.lang.Number type.
See Also
com.opencsv.bean.CsvNumber#value()

Method Detail

convertToReadback to summary
public Object convertToRead(String value) throws CsvDataTypeMismatchException

Implements com.opencsv.bean.CsvConverter.convertToRead.

Doc from com.opencsv.bean.CsvConverter.convertToRead.

Method for converting from a string to the proper data type of the destination field.

Annotations
@Override
Exceptions
CsvDataTypeMismatchException:
If the input string cannot be converted into the proper type
convertToWriteback to summary
public String convertToWrite(Object value) throws CsvDataTypeMismatchException

Overrides com.opencsv.bean.AbstractCsvConverter.convertToWrite.

Implements com.opencsv.bean.CsvConverter.convertToWrite.

Formats the number in question according to the pattern that has been provided.

Annotations
@Override
Exceptions
CsvDataTypeMismatchException:

Doc from com.opencsv.bean.AbstractCsvConverter.convertToWrite.

This implementation doesn't, but subclasses do, so it must be declared

createDecimalFormatback to summary
private DecimalFormat createDecimalFormat(String format, Locale locale, RoundingMode roundingMode)