public class EnumConverter extends Object implements Converter<Enum<?>,com.j256.simplecsv.converter.EnumConverter.ConfigInfo>
Use the FORMAT_IS_UNKNOWN_VALUE
flag to set the unknown enum field name set in the
CsvColumn.format()
.
Modifier and Type | Field and Description |
---|---|
static long |
FORMAT_IS_UNKNOWN_VALUE
If this flag is set then the
CsvColumn.format() string is actually the name of the enum constant that
will be used if the value in the column is unknown. |
Constructor and Description |
---|
EnumConverter() |
Modifier and Type | Method and Description |
---|---|
com.j256.simplecsv.converter.EnumConverter.ConfigInfo |
configure(String format,
long flags,
ColumnInfo<Enum<?>> columnInfo)
Configure this instance of the converter based on the associated params.
|
static EnumConverter |
getSingleton()
Get singleton for class.
|
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(com.j256.simplecsv.converter.EnumConverter.ConfigInfo configInfo)
Returns true if the field needs to be quoted in the CSV output.
|
String |
javaToString(ColumnInfo<Enum<?>> columnInfo,
Enum<?> value)
Converts from a Java representation to string.
|
Enum<?> |
stringToJava(String line,
int lineNumber,
int linePos,
ColumnInfo<Enum<?>> columnInfo,
String value,
ParseError parseError)
Converts from a string representation to Java.
|
public static final long FORMAT_IS_UNKNOWN_VALUE
CsvColumn.format()
string is actually the name of the enum constant that
will be used if the value in the column is unknown. So, for example, if the column value is "red" but there is
not an enum name that corresponds to "red" then the format value "blue" will be used instead.public static EnumConverter getSingleton()
public com.j256.simplecsv.converter.EnumConverter.ConfigInfo configure(String format, long flags, ColumnInfo<Enum<?>> columnInfo)
Converter
configure
in interface Converter<Enum<?>,com.j256.simplecsv.converter.EnumConverter.ConfigInfo>
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.columnInfo
- Information about the field associated with this converter.public boolean isNeedsQuotes(com.j256.simplecsv.converter.EnumConverter.ConfigInfo configInfo)
Converter
isNeedsQuotes
in interface Converter<Enum<?>,com.j256.simplecsv.converter.EnumConverter.ConfigInfo>
public boolean isAlwaysTrimInput()
Converter
Converter.stringToJava(String, int, int, ColumnInfo, String, ParseError)
.isAlwaysTrimInput
in interface Converter<Enum<?>,com.j256.simplecsv.converter.EnumConverter.ConfigInfo>
public String javaToString(ColumnInfo<Enum<?>> columnInfo, Enum<?> value)
Converter
javaToString
in interface Converter<Enum<?>,com.j256.simplecsv.converter.EnumConverter.ConfigInfo>
columnInfo
- Information about the column we are processing.value
- Value of the field that we are converting.public Enum<?> stringToJava(String line, int lineNumber, int linePos, ColumnInfo<Enum<?>> columnInfo, String value, ParseError parseError)
Converter
stringToJava
in interface Converter<Enum<?>,com.j256.simplecsv.converter.EnumConverter.ConfigInfo>
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
.This documentation content is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.