|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.univocity.parsers.common.DefaultConversionProcessor
public abstract class DefaultConversionProcessor
The base class for RowProcessor
and RowWriterProcessor
implementations that support value conversions provided by Conversion
instances.
Constructor Summary | |
---|---|
DefaultConversionProcessor()
|
Method Summary | |
---|---|
Object[] |
applyConversions(String[] row,
ParsingContext context)
Executes the sequences of conversions defined using convertFields(Conversion...) , convertIndexes(Conversion...) and convertAll(Conversion...) , for every field in the given row. |
void |
convertAll(Conversion... conversions)
Applies a set of Conversion objects over all elements of a record |
FieldSet<String> |
convertFields(Conversion... conversions)
Applies a set of Conversion objects over fields of a record by name. |
FieldSet<Integer> |
convertIndexes(Conversion... conversions)
Applies a set of Conversion objects over indexes of a record. |
void |
convertType(Class<?> type,
Conversion... conversions)
Applies a sequence of conversions over values of a given type. |
protected void |
handleConversionError(Throwable ex,
Object[] row,
int column)
|
boolean |
reverseConversions(boolean executeInReverseOrder,
Object[] row,
String[] headers,
int[] indexesToWrite)
Executes the sequences of reverse conversions defined using convertFields(Conversion...) , convertIndexes(Conversion...) and convertAll(Conversion...) , for every field in the given row. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DefaultConversionProcessor()
Method Detail |
---|
public final FieldSet<Integer> convertIndexes(Conversion... conversions)
ConversionProcessor
Conversion
objects over indexes of a record.
The idiom to define which indexes should have these conversions applies is as follows:
processor.convertIndexes(Conversions.trim(), Conversions.toUpperCase()).add(2, 5); // applies trim and uppercase conversions to fields in indexes 2 and 5
convertIndexes
in interface ConversionProcessor
conversions
- The sequence of conversions to be executed in a set of field indexes.
FieldSet
for indexes.public final void convertAll(Conversion... conversions)
ConversionProcessor
Conversion
objects over all elements of a record
convertAll
in interface ConversionProcessor
conversions
- The sequence of conversions to be executed in all elements of a recordpublic final FieldSet<String> convertFields(Conversion... conversions)
ConversionProcessor
Conversion
objects over fields of a record by name.
The idiom to define which fields should have these conversions applied is as follows:
processor.convertFields(Conversions.trim(), Conversions.toUpperCase()).add("name", "position"); // applies trim and uppercase conversions to fields with headers "name" and "position"
convertFields
in interface ConversionProcessor
conversions
- The sequence of conversions to be executed in a set of field indexes.
FieldSet
for field names.public final Object[] applyConversions(String[] row, ParsingContext context)
convertFields(Conversion...)
, convertIndexes(Conversion...)
and convertAll(Conversion...)
, for every field in the given row.
Each field will be transformed using the Conversion.execute(Object)
method.
In general the conversions will process a String and convert it to some object value (such as booleans, dates, etc).
row
- the parsed record with its individual records as extracted from the original input.context
- the current state of the parsing process.
Fields that do not have any conversion defined will just be copied to the object array into their original positions.
public final boolean reverseConversions(boolean executeInReverseOrder, Object[] row, String[] headers, int[] indexesToWrite)
convertFields(Conversion...)
, convertIndexes(Conversion...)
and convertAll(Conversion...)
, for every field in the given row.
Each field will be transformed using the Conversion.revert(Object)
method.
In general the conversions will process an Object (such as a Boolean, Date, etc), and convert it to a String representation.
executeInReverseOrder
- flag to indicate whether the conversion sequence should be executed in the reverse order of its declaration.row
- the row of objects that will be convertedheaders
- All field names used to produce records in a given destination. May be null if no headers have been defined in CommonSettings.getHeaders()
indexesToWrite
- The indexes of the headers that are actually being written. May be null if no fields have been selected using CommonSettings.selectFields(String...)
or CommonSettings.selectIndexes(Integer...)
true
if the the row should be discardedprotected final void handleConversionError(Throwable ex, Object[] row, int column)
public final void convertType(Class<?> type, Conversion... conversions)
ConversionProcessor
convertType
in interface ConversionProcessor
type
- the type over which a sequence of conversions should be appliedconversions
- the sequence of conversions to apply over values of the given type.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |