Package com.opencsv.bean
Class PositionToBeanField<T>
- java.lang.Object
-
- com.opencsv.bean.AbstractFieldMapEntry<java.lang.String,java.lang.Integer,T>
-
- com.opencsv.bean.PositionToBeanField<T>
-
- Type Parameters:
T- Type of the bean being converted
- All Implemented Interfaces:
ComplexFieldMapEntry<java.lang.String,java.lang.Integer,T>,java.lang.Iterable<FieldMapByPositionEntry<T>>
public class PositionToBeanField<T> extends AbstractFieldMapEntry<java.lang.String,java.lang.Integer,T> implements java.lang.Iterable<FieldMapByPositionEntry<T>>
Maps any column position matching a range definition to aBeanField.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classPositionToBeanField.PositionIteratorThis iterator is designed to iterate over every element of all of the ranges specified in the containing class.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringinitializerThis is the string used to initialize this set of ranges.private java.util.List<org.apache.commons.lang3.Range<java.lang.Integer>>rangesA list of ranges of column indices that should be mapped to the associated bean.-
Fields inherited from class com.opencsv.bean.AbstractFieldMapEntry
errorLocale, field
-
-
Constructor Summary
Constructors Constructor Description PositionToBeanField(java.lang.String rangeDefinition, int maxIndex, BeanField<T,java.lang.Integer> field, java.util.Locale errorLocale)Initializes this mapping with a list of ranges and the associatedBeanField.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidattenuateRanges(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.booleancontains(java.lang.Integer key)Determines whether or not the given key is contained in this entry.java.lang.StringgetInitializer()Returns the information used to initialize this entry.java.util.Iterator<FieldMapByPositionEntry<T>>iterator()-
Methods inherited from class com.opencsv.bean.AbstractFieldMapEntry
getBeanField, setErrorLocale
-
-
-
-
Field Detail
-
initializer
private final java.lang.String initializer
This is the string used to initialize this set of ranges. This is necessary because the ranges may be attenuated later byattenuateRanges(int), rendering a reconstruction of the original initialization information impossible.
-
ranges
private final java.util.List<org.apache.commons.lang3.Range<java.lang.Integer>> ranges
A list of ranges of column indices that should be mapped to the associated bean.
-
-
Constructor Detail
-
PositionToBeanField
public PositionToBeanField(java.lang.String rangeDefinition, int maxIndex, BeanField<T,java.lang.Integer> field, java.util.Locale errorLocale)Initializes this mapping with a list of ranges and the associatedBeanField.- Parameters:
rangeDefinition- A definition of ranges as documented inCsvBindAndJoinByPosition.position()maxIndex- The maximum index allowed for a range. Ranges will be adjusted as documented inattenuateRanges(int).field- TheBeanFieldthis mapping maps toerrorLocale- The locale for error messages- Throws:
CsvBadConverterException- IfrangeDefinitioncannot be parsed
-
-
Method Detail
-
attenuateRanges
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- The new maximum for ranges
-
contains
public boolean contains(java.lang.Integer key)
Description copied from interface:ComplexFieldMapEntryDetermines whether or not the given key is contained in this entry.- Specified by:
containsin interfaceComplexFieldMapEntry<java.lang.String,java.lang.Integer,T>- Parameters:
key- The key to be located- Returns:
- Whether
keyis represented by this entry
-
getInitializer
public java.lang.String getInitializer()
Description copied from interface:ComplexFieldMapEntryReturns 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.- Specified by:
getInitializerin interfaceComplexFieldMapEntry<java.lang.String,java.lang.Integer,T>- Returns:
- The original information used to initialize this mapping entry
-
iterator
public java.util.Iterator<FieldMapByPositionEntry<T>> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<T>
-
-