T
- The Java type that we are converting from/to.C
- The configuration information object that we use to share state so we can use this converter with multiple
entities. If your converter has no config-info then you can use Void here and return null from
configure(String, long, ColumnInfo)
.public interface Converter<T,C>
Converters must have a public no-arg constructor so they can be constructed by the library. Also, they will be reused
so all local state should be saved in the config-info object that is returned by the
configure(String, long, ColumnInfo)
method and passed to the other methods.
Modifier and Type | Method and Description |
---|---|
C |
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
stringToJava(String, int, int, ColumnInfo, String, ParseError) . |
boolean |
isNeedsQuotes(C configInfo)
Returns true if the field needs to be quoted in the CSV output.
|
String |
javaToString(ColumnInfo<T> columnInfo,
T fieldValue)
Converts from a Java representation to string.
|
T |
stringToJava(String line,
int lineNumber,
int linePos,
ColumnInfo<T> columnInfo,
String value,
ParseError parseError)
Converts from a string representation to Java.
|
C configure(String format, long flags, ColumnInfo<T> fieldInfo)
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.boolean isNeedsQuotes(C configInfo)
boolean isAlwaysTrimInput()
stringToJava(String, int, int, ColumnInfo, String, ParseError)
.String javaToString(ColumnInfo<T> columnInfo, T fieldValue)
columnInfo
- Information about the column we are processing.fieldValue
- Value of the field that we are converting.T stringToJava(String line, int lineNumber, int linePos, ColumnInfo<T> columnInfo, String value, ParseError parseError) throws ParseException
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.