Class HeaderNameBaseMappingStrategy<T>

    • Field Detail

      • fieldMap

        protected FieldMapByName<T> fieldMap
        Given a header name, this map allows one to find the corresponding BeanField.
      • writeOrder

        protected java.util.Comparator<java.lang.String> writeOrder
        Holds a Comparator to sort columns on writing.
    • Constructor Detail

      • HeaderNameBaseMappingStrategy

        public HeaderNameBaseMappingStrategy()
    • Method Detail

      • captureHeader

        public void captureHeader​(CSVReader reader)
                           throws java.io.IOException,
                                  CsvRequiredFieldEmptyException
        Description copied from interface: MappingStrategy
        Implementation of this method can grab the header line before parsing begins to use to map columns to bean properties.
        Parameters:
        reader - The CSVReader to use for header parsing
        Throws:
        java.io.IOException - If parsing fails
        CsvRequiredFieldEmptyException - If a field is required, but the header or column position for the field is not present in the input
      • verifyLineLength

        public void verifyLineLength​(int numberOfFields)
                              throws CsvRequiredFieldEmptyException
        Description copied from class: AbstractMappingStrategy
        Must be called once the length of input for a line/record is known to verify that the line was complete. Complete in this context means, no required fields are missing. The issue here is, as long as a column is present but empty, we can check whether the field is required and throw an exception if it is not, but if the data end prematurely, we never have this chance without indication that no more data are on the way. Another validation is that the number of fields must match the number of headers to prevent a data mismatch situation.
        Specified by:
        verifyLineLength in class AbstractMappingStrategy<java.lang.String,​java.lang.String,​ComplexFieldMapEntry<java.lang.String,​java.lang.String,​T>,​T>
        Parameters:
        numberOfFields - The number of fields present in the line of input
        Throws:
        CsvRequiredFieldEmptyException - If a required column is missing
      • loadUnadornedFieldMap

        protected void loadUnadornedFieldMap​(org.apache.commons.collections4.ListValuedMap<java.lang.Class<?>,​java.lang.reflect.Field> fields)
        Creates a map of fields in the bean to be processed that have no annotations.

        This method is called by AbstractMappingStrategy.loadFieldMap() when absolutely no annotations that are relevant for this mapping strategy are found in the type of bean being processed. It is then assumed that every field is to be included, and that the name of the member variable must exactly match the header name of the input.

        Two exceptions are made to the rule that everything is written:

        1. Any field annotated with CsvIgnore will be ignored on writing
        2. Any field named "serialVersionUID" will be ignored if the enclosing class implements Serializable.

        Specified by:
        loadUnadornedFieldMap in class AbstractMappingStrategy<java.lang.String,​java.lang.String,​ComplexFieldMapEntry<java.lang.String,​java.lang.String,​T>,​T>
        Parameters:
        fields - A list of all non-synthetic fields in the bean to be processed
      • initializeFieldMap

        protected void initializeFieldMap()
        Description copied from class: AbstractMappingStrategy
        Creates an empty binding-type-specific field map that can be filled in later steps.

        This method may be called multiple times and must erase any state information from previous calls.

        Specified by:
        initializeFieldMap in class AbstractMappingStrategy<java.lang.String,​java.lang.String,​ComplexFieldMapEntry<java.lang.String,​java.lang.String,​T>,​T>
      • findHeader

        public java.lang.String findHeader​(int col)
        Description copied from class: AbstractMappingStrategy
        Gets the name (or position number) of the header for the given column number. The column numbers are zero-based.
        Specified by:
        findHeader in class AbstractMappingStrategy<java.lang.String,​java.lang.String,​ComplexFieldMapEntry<java.lang.String,​java.lang.String,​T>,​T>
        Parameters:
        col - The column number for which the header is sought
        Returns:
        The name of the header
      • setColumnOrderOnWrite

        public void setColumnOrderOnWrite​(java.util.Comparator<java.lang.String> writeOrder)
        Sets the Comparator to be used to sort columns when writing beans to a CSV file. Behavior of this method when used on a mapping strategy intended for reading data from a CSV source is not defined.
        Parameters:
        writeOrder - The Comparator to use. May be null, in which case the natural ordering is used.
        Since:
        4.3