T
- Type of object that is being processed.public class ColumnPositionMappingStrategy<T> extends HeaderColumnNameMappingStrategy<T>
CsvBindByPosition
or
CsvCustomBindByPosition
) requires all the columns
to be present in the CSV file and for them to be in a particular order. Using
annotations allows one to specify arbitrary zero-based column numbers for
each bean member variable to be filled. Also this strategy requires that the
file does NOT have a header. That said, the main use of this strategy is
files that do not have headers.annotationDriven, copyOfRequiredFields, descriptorMap, fieldMap, header, indexLookup, requiredFields, type
Constructor and Description |
---|
ColumnPositionMappingStrategy()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
captureHeader(CSVReader reader)
Captures the header from the reader - required by the MappingStrategy
interface and is a do nothing method for the
ColumnPositionMappingStrategy.
|
int |
findMaxFieldIndex()
Finds and returns the highest index in this mapping.
|
String[] |
generateHeader()
This method returns an empty array.
|
Integer |
getColumnIndex(String name)
Gets the column index that corresponds to a specific column name.
|
String[] |
getColumnMapping()
Retrieves the column mappings.
|
String |
getColumnName(int col)
Gets a column name.
|
protected void |
loadFieldMap()
Builds a map of fields for the bean.
|
void |
setColumnMapping(String... columnMapping)
Setter for the ColumnMappings.
|
void |
setType(Class<? extends T> type)
Sets the class type that is being mapped.
|
createBean, createIndexLookup, findDescriptor, findDescriptor, findField, getType, instantiateCustomConverter, isAnnotationDriven, loadDescriptorMap, registerBeginningOfRecordForReading, registerEndOfRecordForReading, resetIndexMap
public ColumnPositionMappingStrategy()
public void captureHeader(CSVReader reader) throws IOException
captureHeader
in interface MappingStrategy<T>
captureHeader
in class HeaderColumnNameMappingStrategy<T>
reader
- The CSVReader to use for header parsingIOException
- Would be thrown by the CSVReader if it was used :)public String[] generateHeader()
generateHeader
in interface MappingStrategy<T>
generateHeader
in class HeaderColumnNameMappingStrategy<T>
public Integer getColumnIndex(String name)
MappingStrategy
getColumnIndex
in interface MappingStrategy<T>
getColumnIndex
in class HeaderColumnNameMappingStrategy<T>
name
- The column namepublic int findMaxFieldIndex()
MappingStrategy
MappingStrategy.findField(int)
will return null for these columns, so we need
a way to know when to stop writing new columns.findMaxFieldIndex
in interface MappingStrategy<T>
findMaxFieldIndex
in class HeaderColumnNameMappingStrategy<T>
public String getColumnName(int col)
getColumnName
in class HeaderColumnNameMappingStrategy<T>
col
- Position of the column.public String[] getColumnMapping()
public void setColumnMapping(String... columnMapping)
columnMapping
- Column names to be mapped.public void setType(Class<? extends T> type) throws CsvBadConverterException
setType
in class HeaderColumnNameMappingStrategy<T>
type
- Class type.CsvBadConverterException
- If a field in the bean is annotated
with a custom converter that cannot be initialized. If you are not
using custom converters that you have written yourself, it should be
safe to catch this exception and ignore it.protected void loadFieldMap() throws CsvBadConverterException
HeaderColumnNameMappingStrategy
loadFieldMap
in class HeaderColumnNameMappingStrategy<T>
CsvBadConverterException
- If there is a problem instantiating the
custom converter for an annotated fieldCopyright © 2017. All rights reserved.