Class BeanFieldJoin<T,I>

Type Parameters:
T - The type of the bean being populated
I - The index of the MultiValuedMap in use
All Implemented Interfaces:
BeanField<T,I>
Direct Known Subclasses:
BeanFieldJoinIntegerIndex, BeanFieldJoinStringIndex

public abstract class BeanFieldJoin<T,I> extends BeanFieldSingleValue<T,I>
This class is used for combining multiple columns of the input, possibly with multiple identically named columns, into one field.
Since:
4.2
  • Field Details

    • mapType

      private final Class<? extends org.apache.commons.collections4.MultiValuedMap> mapType
      The type of the MultiValuedMap that should be instantiated for the bean field being populated.
  • Constructor Details

    • BeanFieldJoin

      public BeanFieldJoin(Class<?> type, Field field, boolean required, Locale errorLocale, CsvConverter converter, Class<? extends org.apache.commons.collections4.MultiValuedMap> mapType, String capture, String format)
      Creates a new instance.
      Parameters:
      type - The type of the class in which this field is found. This is the type as instantiated by opencsv, and not necessarily the type in which the field is declared in the case of inheritance.
      field - The bean field this object represents
      required - Whether or not a value is always required for this field
      errorLocale - The locale to use for error messages
      converter - The converter to be used for performing the data conversion on reading or writing
      mapType - The type of the MultiValuedMap that should be instantiated for the bean field being populated
      capture - See CsvBindAndJoinByName.capture()
      format - The format string used for packaging values to be written. If null or empty, it is ignored.
  • Method Details

    • putNewValue

      protected abstract Object putNewValue(org.apache.commons.collections4.MultiValuedMap<I,Object> map, String index, Object newValue)
      Puts the value given in newValue into map using index. This allows derived classes to do something special before assigning the value, such as converting the index to a different type.
      Parameters:
      map - The map to which to assign the new value. Never null.
      index - The index under which the new value should be placed in the map. Never null.
      newValue - The new value to be put in the map
      Returns:
      The previous value under this index, or null if there was no previous value
    • assignValueToField

      protected void assignValueToField(Object bean, Object obj, String header) throws CsvDataTypeMismatchException
      Assigns the value given to the proper field of the bean given. In the case of this kind of bean field, the new value will be added to an existing map, and a new map will be created if one does not already exist.
      Overrides:
      assignValueToField in class AbstractBeanField<T,I>
      Parameters:
      bean - The bean in which the field is located
      obj - The data to be assigned to this field of the destination bean
      header - The header from the CSV file under which this value was found.
      Throws:
      CsvDataTypeMismatchException - If the data to be assigned cannot be converted to the type of the destination field
    • indexAndSplitMultivaluedField

      public Object[] indexAndSplitMultivaluedField(Object value, I index) throws CsvDataTypeMismatchException
      Description copied from interface: BeanField
      Given the value of a bean field and an index into that value, determine what values need to be written. When writing a bean to a CSV file, some single fields from the bean could have values that need to be split into multiple fields when writing them to the CSV file. Given the value of the bean field and an index into the data, this method returns the objects to be converted and written.
      Specified by:
      indexAndSplitMultivaluedField in interface BeanField<T,I>
      Overrides:
      indexAndSplitMultivaluedField in class AbstractBeanField<T,I>
      Parameters:
      value - The value of the bean field that should be written
      index - An index into value that determines which of the many possible values are currently being written. For header-based mapping strategies, this will be the header name, and for column position mapping strategies, it will be the zero-based column position.
      Returns:
      An array of all objects in the MultiValuedMap addressed by this bean field answering to the key given in index
      Throws:
      CsvDataTypeMismatchException - If value is not of the type expected by the implementing class
    • isFieldEmptyForWrite

      protected boolean isFieldEmptyForWrite(Object value)
      Checks that value is not null and not empty.
      Overrides:
      isFieldEmptyForWrite in class AbstractBeanField<T,I>
      Parameters:
      value - The value of a field out of a bean that is being written to a CSV file. Can be null.
      Returns:
      Whether or not this implementation considers value to be empty for the purposes of its conversion