Top Description Fields Constructors Methods
com.univocity.parsers.common.fields

public Class FieldConversionMapping

Additional top-level class in compilation unit: AbstractConversionMapping.

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Imports
com.univocity.parsers.annotations.helpers.*, com.univocity.parsers.common.*, com.univocity.parsers.conversions.*, java.util.*

A class for mapping field selections to sequences of Conversion objects
Author
Univocity Software Pty Ltd - [email protected]

Field Summary

Modifier and TypeField and Description
private Map<Integer, List<Conversion<?, ?>>>
conversionsByIndex

This is the final sequence of conversions applied to each index in a record.

private List<FieldSelector>
conversionSequence

This list contains the sequence of conversions applied to sets of fields over multiple calls.

private AbstractConversionMapping<Integer>
private static final Conversion<I, O>[]
private AbstractConversionMapping<Enum<E extends Enum<E>>>
private AbstractConversionMapping<Integer>
private AbstractConversionMapping<String>
public int[]
private Map<Integer, List<ValidatedConversion>>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

the Object produced by a sequence of conversions against the original String value.
applyConversions
(int
The index of parsed value in a record
index
,
String
The parsed value in a record
stringValue
,
boolean[]
an array of flags that indicate whether a conversion occurred. Used to determine whether or not a default conversion by type (specified with ConversionProcessor#convertType(Class, Conversion[])) should be applied.
convertedFlags
)

Applies a sequence of conversions associated with a String value parsed from a given index.

public void
applyConversionsOnAllFields(Conversion<String, ?>...
the sequence of conversions to be applied
conversions
)

Applies a sequence of conversions on all fields.

public FieldSet<Enum<E extends Enum<E>>>

Returns:

a selector of enumerations.
applyConversionsOnFieldEnums
(Conversion<String, ?>...
the sequence of conversions to be applied
conversions
)

Applies a sequence of conversions on a selection of enumerations that represent fields

public FieldSet<Integer>

Returns:

a selector of column indexes.
applyConversionsOnFieldIndexes
(Conversion<String, ?>...
the sequence of conversions to be applied
conversions
)

Applies a sequence of conversions on a selection of field indexes

public FieldSet<String>

Returns:

a selector of column names.
applyConversionsOnFieldNames
(Conversion<String, ?>...
the sequence of conversions to be applied
conversions
)

Applies a sequence of conversions on a selection of field name

public FieldConversionMapping
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.
public void
executeValidations(int
The index of parsed value in a record
index
,
Object
The value of the record at the given index
value
)

Applies any validations associated with a field at a given index in a record

public Conversion<I, O>[]

Returns:

the sequence of conversions to be applied at a given column index
getConversions
(int
the index of the column where the conversions should be executed
index
,
Class<?>
the type resulting from the conversion sequence.
expectedType
)

Returns the sequence of conversions to be applied at a given column index

public void
prepareExecution(boolean
flag indicating whether a writing process is being initialized.
writing
,
String[]
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).

values
)

Prepares the conversions registered in this object to be executed against a given sequence of fields

public Object

Returns:

the Object resulting from a sequence of conversions against the original value.
reverseConversions
(boolean
flag to indicate whether or not the conversion sequence must be executed in reverse order
executeInReverseOrder
,
int
The index of parsed value in a record
index
,
Object
The value in a record
value
,
boolean[]
an array of flags that indicate whether a conversion occurred. Used to determine whether or not a default conversion by type (specified with ConversionProcessor#convertType(Class, Conversion[])) should be applied.
convertedFlags
)

Applies a sequence of conversions associated with an Object value at a given index in a record.

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

conversionsByIndexback to summary
private Map<Integer, List<Conversion<?, ?>>> conversionsByIndex

This is the final sequence of conversions applied to each index in a record. It is populated when FieldConversionMapping#prepareExecution(boolean, String[]) is invoked.

conversionSequenceback to summary
private List<FieldSelector> conversionSequence

This list contains the sequence of conversions applied to sets of fields over multiple calls.

It is shared by FieldConversionMapping#fieldNameConversionMapping, FieldConversionMapping#fieldIndexConversionMapping and FieldConversionMapping#convertAllMapping.

Every time the user associates a sequence of conversions to a field, conversionSequence list will receive the FieldSelector.

convertAllMappingback to summary
private AbstractConversionMapping<Integer> convertAllMapping
EMPTY_CONVERSION_ARRAYback to summary
private static final Conversion<I, O>[] EMPTY_CONVERSION_ARRAY
Annotations
@SuppressWarnings:rawtypes
fieldEnumConversionMappingback to summary
private AbstractConversionMapping<Enum<E extends Enum<E>>> fieldEnumConversionMapping
Annotations
@SuppressWarnings:rawtypes
fieldIndexConversionMappingback to summary
private AbstractConversionMapping<Integer> fieldIndexConversionMapping
fieldNameConversionMappingback to summary
private AbstractConversionMapping<String> fieldNameConversionMapping
validatedIndexesback to summary
public int[] validatedIndexes
validationsByIndexback to summary
private Map<Integer, List<ValidatedConversion>> validationsByIndex

Constructor Detail

FieldConversionMappingback to summary
public FieldConversionMapping()

Method Detail

applyConversionsback to summary
public Object applyConversions(int index, String stringValue, boolean[] convertedFlags)

Applies a sequence of conversions associated with a String value parsed from a given index.

Parameters
index:int

The index of parsed value in a record

stringValue:String

The parsed value in a record

convertedFlags:boolean[]

an array of flags that indicate whether a conversion occurred. Used to determine whether or not a default conversion by type (specified with ConversionProcessor#convertType(Class, Conversion[])) should be applied.

Returns:Object

the Object produced by a sequence of conversions against the original String value.

Annotations
@SuppressWarnings:rawtypes, unchecked
applyConversionsOnAllFieldsback to summary
public void applyConversionsOnAllFields(Conversion<String, ?>... conversions)

Applies a sequence of conversions on all fields.

Parameters
conversions:Conversion<String, ?>[]

the sequence of conversions to be applied

applyConversionsOnFieldEnumsback to summary
public FieldSet<Enum<E extends Enum<E>>> applyConversionsOnFieldEnums(Conversion<String, ?>... conversions)

Applies a sequence of conversions on a selection of enumerations that represent fields

Parameters
conversions:Conversion<String, ?>[]

the sequence of conversions to be applied

Returns:FieldSet<Enum<E extends Enum<E>>>

a selector of enumerations.

Annotations
@SuppressWarnings:rawtypes
applyConversionsOnFieldIndexesback to summary
public FieldSet<Integer> applyConversionsOnFieldIndexes(Conversion<String, ?>... conversions)

Applies a sequence of conversions on a selection of field indexes

Parameters
conversions:Conversion<String, ?>[]

the sequence of conversions to be applied

Returns:FieldSet<Integer>

a selector of column indexes.

applyConversionsOnFieldNamesback to summary
public FieldSet<String> applyConversionsOnFieldNames(Conversion<String, ?>... conversions)

Applies a sequence of conversions on a selection of field name

Parameters
conversions:Conversion<String, ?>[]

the sequence of conversions to be applied

Returns:FieldSet<String>

a selector of column names.

cloneback to summary
public FieldConversionMapping clone()

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:FieldConversionMapping

a clone of this instance.

Annotations
@Override
executeValidationsback to summary
public void executeValidations(int index, Object value)

Applies any validations associated with a field at a given index in a record

Parameters
index:int

The index of parsed value in a record

value:Object

The value of the record at the given index

getConversionsback to summary
public Conversion<I, O>[] getConversions(int index, Class<?> expectedType)

Returns the sequence of conversions to be applied at a given column index

Parameters
index:int

the index of the column where the conversions should be executed

expectedType:Class<?>

the type resulting from the conversion sequence.

Returns:Conversion<I, O>[]

the sequence of conversions to be applied at a given column index

Annotations
@SuppressWarnings:rawtypes
prepareExecutionback to summary
public void prepareExecution(boolean writing, String[] values)

Prepares the conversions registered in this object to be executed against a given sequence of fields

Parameters
writing:boolean

flag indicating whether a writing process is being initialized.

values:String[]

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).

reverseConversionsback to summary
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:boolean

flag to indicate whether or not the conversion sequence must be executed in reverse order

index:int

The index of parsed value in a record

value:Object

The value in a record

convertedFlags:boolean[]

an array of flags that indicate whether a conversion occurred. Used to determine whether or not a default conversion by type (specified with ConversionProcessor#convertType(Class, Conversion[])) should be applied.

Returns:Object

the Object resulting from a sequence of conversions against the original value.

Annotations
@SuppressWarnings:unchecked, rawtypes