Top Description Inners Fields Constructors Methods
com.opencsv.bean

public Class PositionToBeanField<T>

extends AbstractFieldMapEntry<String, Integer, 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.CsvBadConverterException, org.apache.commons.lang3.Range, .StringUtils, java.util.*

Maps any column position matching a range definition to a BeanField.
Author
Andrew Rucker Jones

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
PositionToBeanField.PositionIterator

This iterator is designed to iterate over every element of all of the ranges specified in the containing class.

Field Summary

Modifier and TypeField and Description
private final String
initializer

This is the string used to initialize this set of ranges.

private final List<Range<Integer>>
ranges

A list of ranges of column indices that should be mapped to the associated bean.

Inherited from com.opencsv.bean.AbstractFieldMapEntry:
errorLocalefield

Constructor Summary

AccessConstructor and Description
public
PositionToBeanField(final String
A definition of ranges as documented in CsvBindAndJoinByPosition#position()
rangeDefinition
,
int
The maximum index allowed for a range. Ranges will be adjusted as documented in attenuateRanges(int).
maxIndex
,
final BeanField<T, Integer>
The BeanField this mapping maps to
field
,
Locale
The locale for error messages
errorLocale
)

Initializes this mapping with a list of ranges and the associated BeanField.

Method Summary

Modifier and TypeMethod and Description
public void
attenuateRanges(int
The new maximum for ranges
maxIndex
)

If there are ranges in the list of ranges encompassed by this mapping that stretch beyond the maximum index given, they are shortened to be no longer than the maximum index.

public boolean
contains(Integer key)

Implements com.opencsv.bean.ComplexFieldMapEntry.contains.

Determines whether or not the given key is contained in this entry.

public String
getInitializer()

Implements com.opencsv.bean.ComplexFieldMapEntry.getInitializer.

Returns the information used to initialize this entry.

public Iterator<FieldMapByPositionEntry<T>>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Inherited from com.opencsv.bean.AbstractFieldMapEntry:
getBeanFieldsetErrorLocale

Field Detail

initializerback to summary
private final String initializer

This is the string used to initialize this set of ranges. This is necessary because the ranges may be attenuated later by attenuateRanges(int), rendering a reconstruction of the original initialization information impossible.

rangesback to summary
private final List<Range<Integer>> ranges

A list of ranges of column indices that should be mapped to the associated bean.

Constructor Detail

PositionToBeanFieldback to summary
public PositionToBeanField(final String rangeDefinition, int maxIndex, final BeanField<T, Integer> field, Locale errorLocale)

Initializes this mapping with a list of ranges and the associated BeanField.

Parameters
rangeDefinition:String

A definition of ranges as documented in CsvBindAndJoinByPosition#position()

maxIndex:int

The maximum index allowed for a range. Ranges will be adjusted as documented in attenuateRanges(int).

field:BeanField<T, Integer>

The BeanField this mapping maps to

errorLocale:Locale

The locale for error messages

Exceptions
CsvBadConverterException:
If rangeDefinition cannot be parsed

Method Detail

attenuateRangesback to summary
public void attenuateRanges(int maxIndex)

If there are ranges in the list of ranges encompassed by this mapping that stretch beyond the maximum index given, they are shortened to be no longer than the maximum index. Ranges that lie completely beyond the maximum index are shortened to a one-element range consisting of the range's lower boundary. No ranges are under any circumstances removed, as this might compromise checks for required fields.

Parameters
maxIndex:int

The new maximum for ranges

containsback to summary
public boolean contains(Integer key)

Implements com.opencsv.bean.ComplexFieldMapEntry.contains.

Doc from com.opencsv.bean.ComplexFieldMapEntry.contains.

Determines whether or not the given key is contained in this entry.

Annotations
@Override
getInitializerback to summary
public String getInitializer()

Implements com.opencsv.bean.ComplexFieldMapEntry.getInitializer.

Doc from com.opencsv.bean.ComplexFieldMapEntry.getInitializer.

Returns the information used to initialize this entry. This information is not guaranteed to be exactly the same as the original value, but is functionally equivalent.

Annotations
@Override
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
com.opencsv.bean back to summary

private Class PositionToBeanField.PositionIterator

extends Object
implements Iterator<FieldMapByPositionEntry<T>>
Class Inheritance
All Implemented Interfaces
java.util.Iterator

This iterator is designed to iterate over every element of all of the ranges specified in the containing class.

There is no guaranteed order.

There is one exception to returning all values: if a range ends at Integer#MAX_VALUE, only the minimum in the range is returned. This is to prevent a loop that for all practical purposes might as well be infinite. Unless someone foolishly specifies Integer#MAX_VALUE as a column position, this only occurs after reading in ranges and before the first line of the input is read. There is no reason in the opencsv code to iterate at this point, and it is not done. There should be no reason for user code to use this iterator at all, but if it does, the user is herewith warned.

Field Summary

Modifier and TypeField and Description
private Range<Integer>
private int
private ListIterator<Range<Integer>>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public FieldMapByPositionEntry<T>
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentRangeback to summary
private Range<Integer> currentRange
positionback to summary
private int position
rangeIteratorback to summary
private ListIterator<Range<Integer>> rangeIterator

Constructor Detail

PositionIteratorback to summary
pack-priv PositionIterator()

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Annotations
@Override
nextback to summary
public FieldMapByPositionEntry<T> next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Annotations
@Override
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override