Top Description Fields Constructors Methods
com.opencsv.bean

public abstract Class BeanFieldJoin<T, I>

extends BeanFieldSingleValue<T, I>
Class Inheritance
Known Direct Subclasses
com.opencsv.bean.BeanFieldJoinIntegerIndex, com.opencsv.bean.BeanFieldJoinStringIndex
Type Parameters
<T>
The type of the bean being populated
<I>
The index of the org.apache.commons.collections4.MultiValuedMap in use
Imports
com.opencsv.ICSVParser, com.opencsv.exceptions.CsvBadConverterException, .CsvBeanIntrospectionException, .CsvDataTypeMismatchException, org.apache.commons.collections4.ListValuedMap, .MultiValuedMap, .SetValuedMap, org.apache.commons.collections4.multimap.ArrayListValuedHashMap, .HashSetValuedHashMap, org.apache.commons.lang3.ArrayUtils, java.lang.reflect.Constructor, .Field, .InvocationTargetException, java.util.Collection, .Locale, .ResourceBundle

This class is used for combining multiple columns of the input, possibly with multiple identically named columns, into one field.
Author
Andrew Rucker Jones
Since
4.2

Field Summary

Modifier and TypeField and Description
private final Class<? extends MultiValuedMap<K, V>>
mapType

The type of the org.apache.commons.collections4.MultiValuedMap that should be instantiated for the bean field being populated.

Inherited from com.opencsv.bean.BeanFieldSingleValue:
capturewriteFormat

Constructor Summary

AccessConstructor and Description
public
BeanFieldJoin(Class<?>
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.
type
,
Field
The bean field this object represents
field
,
boolean
Whether or not a value is always required for this field
required
,
Locale
The locale to use for error messages
errorLocale
,
CsvConverter
The converter to be used for performing the data conversion on reading or writing
converter
,
Class<? extends MultiValuedMap<K, V>>
The type of the org.apache.commons.collections4.MultiValuedMap that should be instantiated for the bean field being populated
mapType
,
String capture, String
The format string used for packaging values to be written. If null or empty, it is ignored.
format
)

Creates a new instance.

Method Summary

Modifier and TypeMethod and Description
protected void
assignValueToField(Object bean, Object obj, String header)

Overrides com.opencsv.bean.AbstractBeanField.assignValueToField.

Assigns the value given to the proper field of the bean given.

public Object[]

Returns:

An array of all objects in the org.apache.commons.collections4.MultiValuedMap addressed by this bean field answering to the key given in index
indexAndSplitMultivaluedField
(Object value, I index)

Overrides com.opencsv.bean.AbstractBeanField.indexAndSplitMultivaluedField.

Implements com.opencsv.bean.BeanField.indexAndSplitMultivaluedField.

Given the value of a bean field and an index into that value, determine what values need to be written.

protected boolean
isFieldEmptyForWrite(Object value)

Overrides com.opencsv.bean.AbstractBeanField.isFieldEmptyForWrite.

Checks that value is not null and not empty.

protected abstract Object

Returns:

The previous value under this index, or null if there was no previous value
putNewValue
(MultiValuedMap<I, Object>
The map to which to assign the new value. Never null.
map
,
String
The index under which the new value should be placed in the map. Never null.
index
,
Object
The new value to be put in the map
newValue
)

Puts the value given in newValue into map using index.

Inherited from com.opencsv.bean.BeanFieldSingleValue:
convertconvertToWrite

Field Detail

mapTypeback to summary
private final Class<? extends MultiValuedMap<K, V>> mapType

The type of the org.apache.commons.collections4.MultiValuedMap that should be instantiated for the bean field being populated.

Constructor Detail

BeanFieldJoinback to summary
public BeanFieldJoin(Class<?> type, Field field, boolean required, Locale errorLocale, CsvConverter converter, Class<? extends MultiValuedMap<K, V>> mapType, String capture, String format)

Creates a new instance.

Parameters
type:Class<?>

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:Field

The bean field this object represents

required:boolean

Whether or not a value is always required for this field

errorLocale:Locale

The locale to use for error messages

converter:CsvConverter

The converter to be used for performing the data conversion on reading or writing

mapType:Class<? extends MultiValuedMap<K, V>>

The type of the org.apache.commons.collections4.MultiValuedMap that should be instantiated for the bean field being populated

capture:String

See CsvBindAndJoinByName#capture()

format:String

The format string used for packaging values to be written. If null or empty, it is ignored.

Method Detail

assignValueToFieldback to summary
protected void assignValueToField(Object bean, Object obj, String header) throws CsvDataTypeMismatchException

Overrides com.opencsv.bean.AbstractBeanField.assignValueToField.

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.

Annotations
@Override
Exceptions
CsvDataTypeMismatchException:

Doc from com.opencsv.bean.AbstractBeanField.assignValueToField.

If the data to be assigned cannot be converted to the type of the destination field

indexAndSplitMultivaluedFieldback to summary
public Object[] indexAndSplitMultivaluedField(Object value, I index) throws CsvDataTypeMismatchException

Overrides com.opencsv.bean.AbstractBeanField.indexAndSplitMultivaluedField.

Implements com.opencsv.bean.BeanField.indexAndSplitMultivaluedField.

Doc from com.opencsv.bean.BeanField.indexAndSplitMultivaluedField.

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.

Returns:Object[]

An array of all objects in the org.apache.commons.collections4.MultiValuedMap addressed by this bean field answering to the key given in index

Annotations
@Override
Exceptions
CsvDataTypeMismatchException:
If value is not of the type expected by the implementing class
isFieldEmptyForWriteback to summary
protected boolean isFieldEmptyForWrite(Object value)

Overrides com.opencsv.bean.AbstractBeanField.isFieldEmptyForWrite.

Checks that value is not null and not empty.

Annotations
@Override
@SuppressWarnings:unchecked
putNewValueback to summary
protected abstract Object putNewValue(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:MultiValuedMap<I, Object>

The map to which to assign the new value. Never null.

index:String

The index under which the new value should be placed in the map. Never null.

newValue:Object

The new value to be put in the map

Returns:Object

The previous value under this index, or null if there was no previous value