public abstract class AbstractNumberConverter<T extends Number> extends Object implements Converter<T,DecimalFormat>
Constructor and Description |
---|
AbstractNumberConverter() |
Modifier and Type | Method and Description |
---|---|
DecimalFormat |
configure(String format,
long flags,
ColumnInfo<T> fieldInfo)
Configure this instance of the converter based on the associated params.
|
boolean |
isAlwaysTrimInput()
Returns true if the field should trim the string before it is passed to
Converter.stringToJava(String, int, int, ColumnInfo, String, ParseError) . |
boolean |
isNeedsQuotes(DecimalFormat decimalFormat)
Returns true if the field needs to be quoted in the CSV output.
|
String |
javaToString(ColumnInfo<T> columnInfo,
T value)
Converts from a Java representation to string.
|
protected abstract T |
numberToValue(Number number)
Convert a number to the appropriate Java type.
|
protected abstract T |
parseString(String value)
Parse a string into the appropriate Java type.
|
T |
stringToJava(String line,
int lineNumber,
int linePos,
ColumnInfo<T> columnInfo,
String value,
ParseError parseError)
Converts from a string representation to Java.
|
protected abstract T numberToValue(Number number)
protected abstract T parseString(String value) throws NumberFormatException
NumberFormatException
public boolean isNeedsQuotes(DecimalFormat decimalFormat)
Converter
isNeedsQuotes
in interface Converter<T extends Number,DecimalFormat>
public boolean isAlwaysTrimInput()
Converter
Converter.stringToJava(String, int, int, ColumnInfo, String, ParseError)
.isAlwaysTrimInput
in interface Converter<T extends Number,DecimalFormat>
public DecimalFormat configure(String format, long flags, ColumnInfo<T> fieldInfo)
Converter
configure
in interface Converter<T extends Number,DecimalFormat>
format
- Optional string format which affects the output and parsing of the field. Null if none supplied in
which case the default format is used.flags
- Optional numerical flags which affect the output and parsing of the field. 0 if no flags supplied.fieldInfo
- Information about the field associated with this converter.public String javaToString(ColumnInfo<T> columnInfo, T value)
Converter
javaToString
in interface Converter<T extends Number,DecimalFormat>
columnInfo
- Information about the column we are processing.value
- Value of the field that we are converting.public T stringToJava(String line, int lineNumber, int linePos, ColumnInfo<T> columnInfo, String value, ParseError parseError) throws ParseException
Converter
stringToJava
in interface Converter<T extends Number,DecimalFormat>
line
- Line we are processing for logging purposes.lineNumber
- Number of the line we are processing for logging purposes.linePos
- Position in the line that we are converting to identify what part of the line contains the value.columnInfo
- Information about the column we are processing.value
- Value of the field that we are converting.parseError
- Parse error which can we use to set information about parse errors here. If there are no parse errors
then just ignore this field. Any exceptions thrown will also be caught and interpreted as errors.ParseError.ErrorType.NONE
.ParseException
- If there was some sort of parse or other error. It is better to return null and use the parseError
argument instead. All RuntimeExceptions will be caught as well.This documentation content is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.