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).abstract class AbstractConversionMapping<T>
extends java.lang.Object
FieldNameSelector
,
FieldIndexSelector
Modifier and Type | Field and Description |
---|---|
private java.util.List<FieldSelector> |
conversionSequence |
private java.util.Map<FieldSelector,Conversion<java.lang.String,?>[]> |
conversionsMap |
Constructor and Description |
---|
AbstractConversionMapping(java.util.List<FieldSelector> conversionSequence) |
Modifier and Type | Method and Description |
---|---|
boolean |
isEmpty()
Queries if any conversions were associated with any field
|
protected abstract FieldSelector |
newFieldSelector()
Creates a FieldSelector instance of the desired type.
|
void |
prepareExecution(boolean writing,
FieldSelector selector,
java.util.Map<java.lang.Integer,java.util.List<Conversion<?,?>>> conversionsByIndex,
java.lang.String[] values)
Get all indexes in the given selector and adds the conversions defined at that index to the map of conversionsByIndex.
|
FieldSet<T> |
registerConversions(Conversion<java.lang.String,?>... conversions)
Registers a sequence of conversions to a set of fields.
|
private static void |
validateDuplicates(FieldSelector selector,
java.util.List<Conversion<?,?>> conversionsAtIndex,
Conversion<?,?>[] conversionsToAdd)
Ensures an individual field does not have the same conversion object applied to it more than once.
|
private java.util.Map<FieldSelector,Conversion<java.lang.String,?>[]> conversionsMap
private final java.util.List<FieldSelector> conversionSequence
AbstractConversionMapping(java.util.List<FieldSelector> conversionSequence)
public FieldSet<T> registerConversions(Conversion<java.lang.String,?>... conversions)
The selector instance that is used to store which fields should be converted is added to the 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.
conversions
- the conversion sequence to be applied to a set of fields.AllIndexesSelector
).protected abstract FieldSelector newFieldSelector()
public void prepareExecution(boolean writing, FieldSelector selector, java.util.Map<java.lang.Integer,java.util.List<Conversion<?,?>>> conversionsByIndex, java.lang.String[] values)
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.
writing
- flag indicating whether a writing process is being initialized.selector
- the selected fields for a given conversion sequence.conversionsByIndex
- map of all conversions registered to every field index, in the order they were declaredvalues
- 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).
private static void validateDuplicates(FieldSelector selector, java.util.List<Conversion<?,?>> conversionsAtIndex, Conversion<?,?>[] conversionsToAdd)
selector
- the selection of fieldsconversionsAtIndex
- the sequence of conversions applied to a given indexconversionsToAdd
- the sequence of conversions to add to conversionsAtIndexpublic boolean isEmpty()