public class BooleanConverter extends Object implements Converter<Boolean,com.j256.simplecsv.converter.BooleanConverter.ConfigInfo>
The CsvColumn.format()
parameter can be set to a comma separated list of 2 strings. The string before the
comma will be printed for true, and the string after the comma will be printed for false. For example "1,0" will
output and read 1 for true and 0 for false.
The CsvColumn.converterFlags()
can be set with PARSE_ERROR_ON_INVALID_VALUE
if you want a parse
error generated on unknown values, CASE_SENSITIVE
if you want to compare the true and false values in a
case-sensitive manner, and/orNEEDS_QUOTES
if you want the output to be surrounded by quotes.
Modifier and Type | Field and Description |
---|---|
static long |
CASE_SENSITIVE
Set this flag using
CsvColumn.converterFlags() if you want the boolean formats to be compared
case-sensitively. |
static long |
NEEDS_QUOTES
Set this flag using
CsvColumn.converterFlags() if you want the output to be surrounded by quotes. |
static long |
PARSE_ERROR_ON_INVALID_VALUE
Set this flag using
CsvColumn.converterFlags() if you want a parse error to be generated if the value is
not either false or true (or the ones specified in the format). |
Constructor and Description |
---|
BooleanConverter() |
Modifier and Type | Method and Description |
---|---|
com.j256.simplecsv.converter.BooleanConverter.ConfigInfo |
configure(String format,
long flags,
ColumnInfo<Boolean> fieldInfo)
Configure this instance of the converter based on the associated params.
|
static BooleanConverter |
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.BooleanConverter.ConfigInfo configInfo)
Returns true if the field needs to be quoted in the CSV output.
|
String |
javaToString(ColumnInfo<Boolean> columnInfo,
Boolean value)
Converts from a Java representation to string.
|
Boolean |
stringToJava(String line,
int lineNumber,
int linePos,
ColumnInfo<Boolean> columnInfo,
String value,
ParseError parseError)
Converts from a string representation to Java.
|
public static final long PARSE_ERROR_ON_INVALID_VALUE
CsvColumn.converterFlags()
if you want a parse error to be generated if the value is
not either false or true (or the ones specified in the format). Default is that an invalid value will generate
false.public static final long CASE_SENSITIVE
CsvColumn.converterFlags()
if you want the boolean formats to be compared
case-sensitively. So "TRUE" and "True" would be converted into false. Default is case-insensitive.public static final long NEEDS_QUOTES
CsvColumn.converterFlags()
if you want the output to be surrounded by quotes. Default
is none.public static BooleanConverter getSingleton()
public com.j256.simplecsv.converter.BooleanConverter.ConfigInfo configure(String format, long flags, ColumnInfo<Boolean> fieldInfo)
Converter
configure
in interface Converter<Boolean,com.j256.simplecsv.converter.BooleanConverter.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.fieldInfo
- Information about the field associated with this converter.public boolean isNeedsQuotes(com.j256.simplecsv.converter.BooleanConverter.ConfigInfo configInfo)
Converter
isNeedsQuotes
in interface Converter<Boolean,com.j256.simplecsv.converter.BooleanConverter.ConfigInfo>
public boolean isAlwaysTrimInput()
Converter
Converter.stringToJava(String, int, int, ColumnInfo, String, ParseError)
.isAlwaysTrimInput
in interface Converter<Boolean,com.j256.simplecsv.converter.BooleanConverter.ConfigInfo>
public String javaToString(ColumnInfo<Boolean> columnInfo, Boolean value)
Converter
javaToString
in interface Converter<Boolean,com.j256.simplecsv.converter.BooleanConverter.ConfigInfo>
columnInfo
- Information about the column we are processing.value
- Value of the field that we are converting.public Boolean stringToJava(String line, int lineNumber, int linePos, ColumnInfo<Boolean> columnInfo, String value, ParseError parseError)
Converter
stringToJava
in interface Converter<Boolean,com.j256.simplecsv.converter.BooleanConverter.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.