Top Description Fields Constructors Methods
com.opencsv.bean

public Class FieldMapByPosition<T>

extends AbstractFieldMap<String, Integer, PositionToBeanField<T>, T>
implements Iterable<FieldMapByPositionEntry<T>>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Type Parameters
<T>
Type of the bean being converted
Imports
com.opencsv.ICSVParser, com.opencsv.exceptions.CsvRequiredFieldEmptyException, org.apache.commons.collections4.MultiValuedMap, org.apache.commons.collections4.iterators.LazyIteratorChain, .TransformIterator, java.lang.reflect.Field, java.util.*, java.util.stream.Collectors

This class maintains a mapping from column position out of a CSV file to bean fields.
Author
Andrew Rucker Jones
Since
4.2

Field Summary

Modifier and TypeField and Description
private int
private Comparator<Integer>
writeOrder

Holds a java.util.Comparator to sort columns on writing.

Inherited from com.opencsv.bean.AbstractFieldMap:
complexMapListerrorLocalesimpleMap

Constructor Summary

AccessConstructor and Description
public
FieldMapByPosition(final Locale
The locale to be used for error messages
errorLocale
)

Initializes this FieldMap.

Method Summary

Modifier and TypeMethod and Description
public String[]
generateHeader(final T bean)

Implements com.opencsv.bean.FieldMap.generateHeader.

This method generates a header that can be used for writing beans of the type provided back to a file.

public Iterator<FieldMapByPositionEntry<T>>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public void
putComplex(final String
A string describing the column positions to be matched.
rangeDefinition
,
final BeanField<T, Integer> field)

Implements com.opencsv.bean.FieldMap.putComplex.

Adds a BeanField to this map indexed by the data in initializer.

public void
setColumnOrderOnWrite(Comparator<Integer>
The java.util.Comparator to use. May be null, in which case the natural ordering is used.
writeOrder
)

Sets the java.util.Comparator to be used to sort columns when writing beans to a CSV file.

public void
setMaxIndex(int
The maximum index in the data being imported
maxIndex
)

Sets the maximum index for all ranges specified in the entire field map.

Inherited from com.opencsv.bean.AbstractFieldMap:
getputsetErrorLocalevalues

Field Detail

maxIndexback to summary
private int maxIndex
writeOrderback to summary
private Comparator<Integer> writeOrder

Holds a java.util.Comparator to sort columns on writing.

Constructor Detail

FieldMapByPositionback to summary
public FieldMapByPosition(final Locale errorLocale)

Initializes this FieldMap.

Parameters
errorLocale:Locale

The locale to be used for error messages

Method Detail

generateHeaderback to summary
public String[] generateHeader(final T bean) throws CsvRequiredFieldEmptyException

Implements com.opencsv.bean.FieldMap.generateHeader.

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 java.util.Comparator passed in to setColumnOrderOnWrite(Comparator). Otherwise, it is ascending according to position.

Annotations
@Override
Exceptions
CsvRequiredFieldEmptyException:

Doc from com.opencsv.bean.FieldMap.generateHeader.

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.

iteratorback to summary
public Iterator<FieldMapByPositionEntry<T>> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Annotations
@Override
putComplexback to summary
public void putComplex(final String rangeDefinition, final BeanField<T, Integer> field)

Implements com.opencsv.bean.FieldMap.putComplex.

Doc from com.opencsv.bean.FieldMap.putComplex.

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.

Parameters
rangeDefinition:String

A string describing the column positions to be matched.

Annotations
@Override
See Also
CsvBindAndJoinByPosition#position()
setColumnOrderOnWriteback to summary
public void setColumnOrderOnWrite(Comparator<Integer> writeOrder)

Sets the java.util.Comparator to be used to sort columns when writing beans to a CSV file.

Parameters
writeOrder:Comparator<Integer>

The java.util.Comparator to use. May be null, in which case the natural ordering is used.

Since
4.3
setMaxIndexback to summary
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:int

The maximum index in the data being imported