Class FieldConversionMapping
java.lang.Object
com.univocity.parsers.common.fields.FieldConversionMapping
- All Implemented Interfaces:
Cloneable
A class for mapping field selections to sequences of
Conversion
objects-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map<Integer,
List<Conversion<?, ?>>> This is the final sequence of conversions applied to each index in a record.private List<FieldSelector>
This list contains the sequence of conversions applied to sets of fields over multiple calls.private AbstractConversionMapping<Integer>
private static final Conversion[]
private AbstractConversionMapping<Enum>
private AbstractConversionMapping<Integer>
private AbstractConversionMapping<String>
int[]
private Map<Integer,
List<ValidatedConversion>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapplyConversions
(int index, String stringValue, boolean[] convertedFlags) Applies a sequence of conversions associated with a String value parsed from a given index.void
applyConversionsOnAllFields
(Conversion<String, ?>... conversions) Applies a sequence of conversions on all fields.applyConversionsOnFieldEnums
(Conversion<String, ?>... conversions) Applies a sequence of conversions on a selection of enumerations that represent fieldsapplyConversionsOnFieldIndexes
(Conversion<String, ?>... conversions) Applies a sequence of conversions on a selection of field indexesapplyConversionsOnFieldNames
(Conversion<String, ?>... conversions) Applies a sequence of conversions on a selection of field nameclone()
void
executeValidations
(int index, Object value) Applies any validations associated with a field at a given index in a recordgetConversions
(int index, Class<?> expectedType) Returns the sequence of conversions to be applied at a given column indexvoid
prepareExecution
(boolean writing, String[] values) Prepares the conversions registered in this object to be executed against a given sequence of fieldsreverseConversions
(boolean executeInReverseOrder, int index, Object value, boolean[] convertedFlags) Applies a sequence of conversions associated with an Object value at a given index in a record.
-
Field Details
-
EMPTY_CONVERSION_ARRAY
-
validatedIndexes
public int[] validatedIndexes -
conversionSequence
This list contains the sequence of conversions applied to sets of fields over multiple calls.It is shared by
fieldNameConversionMapping
,fieldIndexConversionMapping
andconvertAllMapping
.Every time the user associates a sequence of conversions to a field, conversionSequence list will receive the FieldSelector.
-
fieldNameConversionMapping
-
fieldIndexConversionMapping
-
fieldEnumConversionMapping
-
convertAllMapping
-
conversionsByIndex
This is the final sequence of conversions applied to each index in a record. It is populated whenprepareExecution(boolean, String[])
is invoked. -
validationsByIndex
-
-
Constructor Details
-
FieldConversionMapping
public FieldConversionMapping()
-
-
Method Details
-
prepareExecution
Prepares the conversions registered in this object to be executed against a given sequence of fields- Parameters:
writing
- flag indicating whether a writing process is being initialized.values
- The field sequence that identifies how records will be organized.This is generally the sequence of headers in a record, but it might be just the first parsed row from a given input (as field selection by index is allowed).
-
applyConversionsOnAllFields
Applies a sequence of conversions on all fields.- Parameters:
conversions
- the sequence of conversions to be applied
-
applyConversionsOnFieldIndexes
Applies a sequence of conversions on a selection of field indexes- Parameters:
conversions
- the sequence of conversions to be applied- Returns:
- a selector of column indexes.
-
applyConversionsOnFieldNames
Applies a sequence of conversions on a selection of field name- Parameters:
conversions
- the sequence of conversions to be applied- Returns:
- a selector of column names.
-
applyConversionsOnFieldEnums
Applies a sequence of conversions on a selection of enumerations that represent fields- Parameters:
conversions
- the sequence of conversions to be applied- Returns:
- a selector of enumerations.
-
executeValidations
Applies any validations associated with a field at a given index in a record- Parameters:
index
- The index of parsed value in a recordvalue
- The value of the record at the given index
-
reverseConversions
public Object reverseConversions(boolean executeInReverseOrder, int index, Object value, boolean[] convertedFlags) Applies a sequence of conversions associated with an Object value at a given index in a record.- Parameters:
executeInReverseOrder
- flag to indicate whether or not the conversion sequence must be executed in reverse orderindex
- The index of parsed value in a recordvalue
- The value in a recordconvertedFlags
- an array of flags that indicate whether a conversion occurred. Used to determine whether or not a default conversion by type (specified withConversionProcessor.convertType(Class, Conversion[])
) should be applied.- Returns:
- the Object resulting from a sequence of conversions against the original value.
-
applyConversions
Applies a sequence of conversions associated with a String value parsed from a given index.- Parameters:
index
- The index of parsed value in a recordstringValue
- The parsed value in a recordconvertedFlags
- an array of flags that indicate whether a conversion occurred. Used to determine whether or not a default conversion by type (specified withConversionProcessor.convertType(Class, Conversion[])
) should be applied.- Returns:
- the Object produced by a sequence of conversions against the original String value.
-
getConversions
Returns the sequence of conversions to be applied at a given column index- Parameters:
index
- the index of the column where the conversions should be executedexpectedType
- the type resulting from the conversion sequence.- Returns:
- the sequence of conversions to be applied at a given column index
-
clone
-