Class AbstractConversionMapping<T>

  • 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).
    All Implemented Interfaces:
    java.lang.Cloneable

    abstract class AbstractConversionMapping<T>
    extends java.lang.Object
    implements java.lang.Cloneable
    Class responsible for managing field selections and any conversion sequence associated with each.
    See Also:
    FieldNameSelector, FieldIndexSelector
    • Field Detail

      • conversionSequence

        private java.util.List<FieldSelector> conversionSequence
    • Constructor Detail

      • AbstractConversionMapping

        AbstractConversionMapping​(java.util.List<FieldSelector> conversionSequence)
    • Method Detail

      • registerConversions

        public FieldSet<T> registerConversions​(Conversion<java.lang.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 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 - the conversion sequence to be applied to a set of fields.
        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).
      • newFieldSelector

        protected abstract FieldSelector newFieldSelector()
        Creates a FieldSelector instance of the desired type. Used in @link FieldConversionMapping}.
        Returns:
        a new FieldSelector instance.
      • prepareExecution

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

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

      • validateDuplicates

        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.
        Parameters:
        selector - the selection of fields
        conversionsAtIndex - the sequence of conversions applied to a given index
        conversionsToAdd - the sequence of conversions to add to conversionsAtIndex
      • isEmpty

        public boolean isEmpty()
        Queries if any conversions were associated with any field
        Returns:
        true if no conversions were associated with any field; false otherwise