com.opencsv.bean.CsvBindByPosition or
com.opencsv.bean.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.
| Modifier and Type | Field and Description |
|---|---|
| private Integer[] | columnIndexForWriting
Used to store a mapping from presumed input column index to desired
output column index, as determined by applying |
| private boolean | columnsExplicitlySet
Whether the user has programmatically set the map from column positions to field names. |
| private FieldMapByPosition | |
| private Comparator | writeOrder
Holds a |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | captureHeader(CSVReader reader)
Implements com. There is no header per se for this mapping strategy, but this method checks the first line to determine how many fields are present and adjusts its field map accordingly. |
| protected Integer | chooseMultivaluedFieldIndexFromHeaderIndex(int index)
Implements abstract com. For |
| protected BeanField | findField(int col)
Implements abstract com. Gets the field for a given column position. |
| public String | findHeader(int col)
Implements abstract com. Returns the column position for the given column number. |
| public String[] | Returns: An empty arrayOverrides com. Implements com. This method returns an empty array. |
| protected Set | getBindingAnnotations()
Overrides com. Returns a set of the annotations that are used for binding in this mapping strategy. |
| public String[] | |
| public String | Returns: Column name or null if col > number of mappings.Position of the column. col)Overrides com. Gets a column name. |
| protected FieldMap | getFieldMap()
Implements abstract com. Returns the |
| protected void | initializeFieldMap()
Implements abstract com. Creates an empty binding-type-specific field map that can be filled in later steps. |
| protected void | loadAnnotatedFieldMap(ListValuedMap<Class<?>, Field> fields)
Overrides com. Creates a map of annotated fields in the bean to be processed. |
| protected void | loadUnadornedFieldMap(ListValuedMap<Class<?>, Field> fields)
Implements abstract com. Creates a map of fields in the bean to be processed that have no annotations. |
| private void | registerBinding(CsvBindByPosition
The annotation attached to the bean field annotation, Class<?> The class/type in which the field resides localType, Field The bean field localField)Register a binding between a bean field and a simple converter. |
| private void | registerCustomBinding(CsvCustomBindByPosition
The annotation attached to the bean field annotation, Class<?> The class/type in which the field resides localType, Field The bean field localField)Register a binding between a bean field and a custom converter. |
| private void | registerJoinBinding(CsvBindAndJoinByPosition
The annotation attached to the bean field annotation, Class<?> The class/type in which the field resides localType, Field The bean field localField)Register a binding between a bean field and a multi-valued converter that joins values from multiple columns. |
| private void | registerSplitBinding(CsvBindAndSplitByPosition
The annotation attached to the bean field annotation, Class<?> The class/type in which the field resides localType, Field The bean field localField)Register a binding between a bean field and a collection converter that splits input into multiple values. |
| public void | |
| public void | setColumnOrderOnWrite(Comparator<Integer>
The writeOrder)java. to use. May be
null, in which case the natural ordering is used.Sets the |
| protected void | verifyLineLength(int numberOfFields)
Implements abstract com. Must be called once the length of input for a line/record is known to verify that the line was complete. |
| columnIndexForWriting | back to summary |
|---|---|
| private Integer[] columnIndexForWriting Used to store a mapping from presumed input column index to desired
output column index, as determined by applying | |
| columnsExplicitlySet | back to summary |
|---|---|
| private boolean columnsExplicitlySet Whether the user has programmatically set the map from column positions to field names. | |
| fieldMap | back to summary |
|---|---|
| private FieldMapByPosition<T> fieldMap The map from column position to | |
| writeOrder | back to summary |
|---|---|
| private Comparator<Integer> writeOrder Holds a | |
| ColumnPositionMappingStrategy | back to summary |
|---|---|
| public ColumnPositionMappingStrategy() Default constructor. Considered stable.
| |
| captureHeader | back to summary |
|---|---|
| public void captureHeader(CSVReader reader) throws IOException Implements com. There is no header per se for this mapping strategy, but this method checks the first line to determine how many fields are present and adjusts its field map accordingly.
| |
| chooseMultivaluedFieldIndexFromHeaderIndex | back to summary |
|---|---|
| protected Integer chooseMultivaluedFieldIndexFromHeaderIndex(int index) Implements abstract com. Doc from com. For
| |
| findField | back to summary |
|---|---|
| protected BeanField Implements abstract com. Doc from com. Gets the field for a given column position.
| |
| findHeader | back to summary |
|---|---|
| public String findHeader(int col) Implements abstract com. Returns the column position for the given column number. Yes, they're the same thing. For this mapping strategy, it's a simple conversion from an integer to a string.
| |
| generateHeader | back to summary |
|---|---|
| public String[] generateHeader(T bean) throws CsvRequiredFieldEmptyException Overrides com. Implements com. This method returns an empty array. The column position mapping strategy assumes that there is no header, and thus it also does not write one, accordingly.
| |
| getBindingAnnotations | back to summary |
|---|---|
| protected Set Overrides com. Returns a set of the annotations that are used for binding in this mapping strategy. In this mapping strategy, those are currently:
| |
| getColumnMapping | back to summary |
|---|---|
| public String[] getColumnMapping() Retrieves the column mappings.
| |
| getColumnName | back to summary |
|---|---|
| public String getColumnName(int col) Overrides com. Gets a column name. | |
| getFieldMap | back to summary |
|---|---|
| protected FieldMap Implements abstract com. Doc from com. Returns the
| |
| initializeFieldMap | back to summary |
|---|---|
| protected void initializeFieldMap() Implements abstract com. Doc from com. Creates an empty binding-type-specific field map that can be filled in later steps. This method may be called multiple times and must erase any state information from previous calls.
| |
| loadAnnotatedFieldMap | back to summary |
|---|---|
| protected void loadAnnotatedFieldMap(ListValuedMap<Class<?>, Field> fields) Overrides com. Creates a map of annotated fields in the bean to be processed. This method is called by
| |
| loadUnadornedFieldMap | back to summary |
|---|---|
| protected void loadUnadornedFieldMap(ListValuedMap<Class<?>, Field> fields) Implements abstract com. Doc from com. Creates a map of fields in the bean to be processed that have no
annotations.
This method is called by
| |
| registerBinding | back to summary |
|---|---|
| private void registerBinding(CsvBindByPosition annotation, Class<?> localType, Field localField) Register a binding between a bean field and a simple converter.
| |
| registerCustomBinding | back to summary |
|---|---|
| private void registerCustomBinding(CsvCustomBindByPosition annotation, Class<?> localType, Field localField) Register a binding between a bean field and a custom converter.
| |
| registerJoinBinding | back to summary |
|---|---|
| private void registerJoinBinding(CsvBindAndJoinByPosition annotation, Class<?> localType, Field localField) Register a binding between a bean field and a multi-valued converter that joins values from multiple columns.
| |
| registerSplitBinding | back to summary |
|---|---|
| private void registerSplitBinding(CsvBindAndSplitByPosition annotation, Class<?> localType, Field localField) Register a binding between a bean field and a collection converter that splits input into multiple values.
| |
| setColumnMapping | back to summary |
|---|---|
| public void setColumnMapping(String... columnMapping) Setter for the column mapping. This mapping is for reading. Use of this method in conjunction with writing is undefined.
| |
| setColumnOrderOnWrite | back to summary |
|---|---|
| public void setColumnOrderOnWrite(Comparator<Integer> writeOrder) Sets the
| |
| verifyLineLength | back to summary |
|---|---|
| protected void verifyLineLength(int numberOfFields) throws CsvRequiredFieldEmptyException Implements abstract com. Doc from com. Must be called once the length of input for a line/record is known to verify that the line was complete. Complete in this context means, no required fields are missing. The issue here is, as long as a column is present but empty, we can check whether the field is required and throw an exception if it is not, but if the data end prematurely, we never have this chance without indication that no more data are on the way. Another validation is that the number of fields must match the number of headers to prevent a data mismatch situation.
| |