Class FieldMapByPosition<T>

Type Parameters:
T - Type of the bean being converted
All Implemented Interfaces:
FieldMap<String,Integer,PositionToBeanField<T>,T>, Iterable<FieldMapByPositionEntry<T>>

public class FieldMapByPosition<T> extends AbstractFieldMap<String,Integer,PositionToBeanField<T>,T> implements Iterable<FieldMapByPositionEntry<T>>
This class maintains a mapping from column position out of a CSV file to bean fields.
Since:
4.2
  • Field Details

  • Constructor Details

    • FieldMapByPosition

      public FieldMapByPosition(Locale errorLocale)
      Initializes this FieldMap.
      Parameters:
      errorLocale - The locale to be used for error messages
  • Method Details

    • generateHeader

      public String[] generateHeader(T bean) throws CsvRequiredFieldEmptyException
      This method generates a header that can be used for writing beans of the type provided back to a file. The ordering of the headers can be determined with the Comparator passed in to setColumnOrderOnWrite(Comparator). Otherwise, it is ascending according to position.
      Specified by:
      generateHeader in interface FieldMap<String,Integer,PositionToBeanField<T>,T>
      Parameters:
      bean - One perfect, shining example of how the bean to be written should look. The most crucial thing is, for fields that result from joining multiple fields on reading and thus need to be split on writing, the MultiValuedMap in question must have the complete structure of the header to be generated, even if some values are empty.
      Returns:
      An array of header names for the output file
      Throws:
      CsvRequiredFieldEmptyException - If a required header is missing while attempting to write. Since every other header is hard-wired through the bean fields and their associated annotations, this can only happen with multi-valued fields.
    • putComplex

      public void putComplex(String rangeDefinition, BeanField<T,Integer> field)
      Description copied from interface: FieldMap
      Adds a BeanField to this map indexed by the data in initializer. This is what makes this map special: It allows one to define characteristics of a method to match multiple keys.
      Specified by:
      putComplex in interface FieldMap<String,Integer,PositionToBeanField<T>,T>
      Parameters:
      rangeDefinition - A string describing the column positions to be matched.
      field - The BeanField that is to be returned on a later match
      See Also:
    • setMaxIndex

      public void setMaxIndex(int maxIndex)
      Sets the maximum index for all ranges specified in the entire field map. No ranges or mappings are ever removed so as to preserve information about required fields, but upper boundries are shortened as much as possible. If ranges or individual column positions were specified that lie wholly above maxIndex, these are preserved, though ranges are shortened to a single value (the lower boundry).
      Parameters:
      maxIndex - The maximum index in the data being imported
    • iterator

      public Iterator<FieldMapByPositionEntry<T>> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • setColumnOrderOnWrite

      public void setColumnOrderOnWrite(Comparator<Integer> writeOrder)
      Sets the Comparator to be used to sort columns when writing beans to a CSV file.
      Parameters:
      writeOrder - The Comparator to use. May be null, in which case the natural ordering is used.
      Since:
      4.3