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

pack-priv abstract Class AbstractConversionMapping<T>

Located in compilation unit of com.univocity.parsers.common.fields.FieldConversionMapping.

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Type Parameters
<T>
the FieldSelector type information used to uniquely identify a field (e.g. references to field indexes would use Integer, while references to field names would use String).

Class responsible for managing field selections and any conversion sequence associated with each.
Author
Univocity Software Pty Ltd - [email protected]
See Also
FieldNameSelector, FieldIndexSelector

Field Summary

Modifier and TypeField and Description
private List<FieldSelector>
private Map<FieldSelector, Conversion<String, ?>[]>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public AbstractConversionMapping<T>
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.
public AbstractConversionMapping<T>
clone(Map<FieldSelector, FieldSelector> clonedSelectors, List<FieldSelector> clonedConversionSequence)

public boolean

Returns:

true if no conversions were associated with any field; false otherwise
isEmpty
()

Queries if any conversions were associated with any field

protected abstract FieldSelector

Returns:

a new FieldSelector instance.
newFieldSelector
()

Creates a FieldSelector instance of the desired type.

public void
prepareExecution(boolean
flag indicating whether a writing process is being initialized.
writing
,
FieldSelector
the selected fields for a given conversion sequence.
selector
,
Map<Integer, List<Conversion<?, ?>>>
map of all conversions registered to every field index, in the order they were declared
conversionsByIndex
,
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
)

Get all indexes in the given selector and adds the conversions defined at that index to the map of conversionsByIndex.

public FieldSet<T>

Returns:

a FieldSet which provides methods to select the fields that must be converted or null if the FieldSelector returned by #newFieldSelector is not an instance of FieldSet (which is the case of AllIndexesSelector).
registerConversions
(Conversion<String, ?>...
the conversion sequence to be applied to a set of fields.
conversions
)

Registers a sequence of conversions to a set of fields.

private static void
validateDuplicates(FieldSelector
the selection of fields
selector
,
List<Conversion<?, ?>>
the sequence of conversions applied to a given index
conversionsAtIndex
,
Conversion<?, ?>[]
the sequence of conversions to add to conversionsAtIndex
conversionsToAdd
)

Ensures an individual field does not have the same conversion object applied to it more than once.

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

conversionSequenceback to summary
private List<FieldSelector> conversionSequence
conversionsMapback to summary
private Map<FieldSelector, Conversion<String, ?>[]> conversionsMap

Constructor Detail

AbstractConversionMappingback to summary
pack-priv AbstractConversionMapping(List<FieldSelector> conversionSequence)

Method Detail

cloneback to summary
public AbstractConversionMapping<T> 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:AbstractConversionMapping<T>

a clone of this instance.

cloneback to summary
public AbstractConversionMapping<T> clone(Map<FieldSelector, FieldSelector> clonedSelectors, List<FieldSelector> clonedConversionSequence)
isEmptyback to summary
public boolean isEmpty()

Queries if any conversions were associated with any field

Returns:boolean

true if no conversions were associated with any field; false otherwise

newFieldSelectorback to summary
protected abstract FieldSelector newFieldSelector()

Creates a FieldSelector instance of the desired type. Used in @link FieldConversionMapping}.

Returns:FieldSelector

a new FieldSelector instance.

prepareExecutionback to summary
public void prepareExecution(boolean writing, FieldSelector selector, Map<Integer, List<Conversion<?, ?>>> conversionsByIndex, String[] values)

Get all indexes in the given selector and adds the conversions defined at that index to the map of conversionsByIndex.

This method is called in the same sequence each selector was created (in FieldConversionMapping#prepareExecution(boolean, String[]))

At the end of the process, the map of conversionsByIndex will have each index with its list of conversions in the order they were declared.

Parameters
writing:boolean

flag indicating whether a writing process is being initialized.

selector:FieldSelector

the selected fields for a given conversion sequence.

conversionsByIndex:Map<Integer, List<Conversion<?, ?>>>

map of all conversions registered to every field index, in the order they were declared

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

registerConversionsback to summary
public FieldSet<T> registerConversions(Conversion<String, ?>... conversions)

Registers a sequence of conversions to a set of fields.

The selector instance that is used to store which fields should be converted is added to the AbstractConversionMapping#conversionSequence list in order to keep track of the correct conversion order.

This is required further conversion sequences might be added to the same fields in separate calls.

Parameters
conversions:Conversion<String, ?>[]

the conversion sequence to be applied to a set of fields.

Returns:FieldSet<T>

a FieldSet which provides methods to select the fields that must be converted or null if the FieldSelector returned by #newFieldSelector is not an instance of FieldSet (which is the case of AllIndexesSelector).

Annotations
@SuppressWarnings:unchecked
validateDuplicatesback to summary
private static void validateDuplicates(FieldSelector selector, List<Conversion<?, ?>> conversionsAtIndex, Conversion<?, ?>[] conversionsToAdd)

Ensures an individual field does not have the same conversion object applied to it more than once.

Parameters
selector:FieldSelector

the selection of fields

conversionsAtIndex:List<Conversion<?, ?>>

the sequence of conversions applied to a given index

conversionsToAdd:Conversion<?, ?>[]

the sequence of conversions to add to conversionsAtIndex