Top Description Fields Constructors Methods
de.siegmar.fastcsv.reader

public Class CsvRecord

extends Object
Class Inheritance
Known Direct Subclasses
de.siegmar.fastcsv.reader.NamedCsvRecord
Annotations
@SuppressWarnings:PMD.ArrayIsStoredDirectly
Imports
java.util.Arrays, .Collections, .List, .StringJoiner

Represents an immutable CSV record with unnamed (indexed) fields.

The field values are never null. Empty fields are represented as empty strings.

CSV records are created by CsvReader or IndexedCsvReader.

See Also
CsvReader, IndexedCsvReader

Field Summary

Modifier and TypeField and Description
pack-priv final boolean
comment

If the record is a commented record.

pack-priv final String[]
fields

The fields this record is composed of.

pack-priv final long
startingLineNumber

The starting line number (starting with 1).

Constructor Summary

AccessConstructor and Description
pack-priv
CsvRecord(final long startingLineNumber, final String[] fields, final boolean comment)

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

field value, never null
getField
(final int
index of the field to return
index
)

Retrieves the value of a field based on its index, with indexing starting from 0.

public int

Returns:

the number of fields in this record
getFieldCount
()

Gets the count of fields in this record.

public List<String>

Returns:

all fields of this record, never null
getFields
()

Retrieves all fields of this record as an unmodifiable list.

public long

Returns:

the starting line number of this record, starting from 1
getStartingLineNumber
()

Provides the line number at which this record originated, starting from 1.

public boolean

Returns:

true if the record is a commented record
isComment
()

Indicates whether the record is a commented record.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

commentback to summary
pack-priv final boolean comment

If the record is a commented record.

Annotations
@SuppressWarnings:checkstyle:VisibilityModifier
See Also
isComment()
fieldsback to summary
pack-priv final String[] fields

The fields this record is composed of.

Annotations
@SuppressWarnings:checkstyle:VisibilityModifier
See Also
getField(int), getFields()
startingLineNumberback to summary
pack-priv final long startingLineNumber

The starting line number (starting with 1).

Annotations
@SuppressWarnings:checkstyle:VisibilityModifier
See Also
getStartingLineNumber()

Constructor Detail

CsvRecordback to summary
pack-priv CsvRecord(final long startingLineNumber, final String[] fields, final boolean comment)

Method Detail

getFieldback to summary
public String getField(final int index)

Retrieves the value of a field based on its index, with indexing starting from 0.

There is always at least one field, even if the line was empty.

If this records holds a comment, the comment is returned by calling this method with index 0. The comment character is not included in the returned value.

Parameters
index:int

index of the field to return

Returns:String

field value, never null

Exceptions
IndexOutOfBoundsException:
if the index is out of range
getFieldCountback to summary
public int getFieldCount()

Gets the count of fields in this record.

The minimum number of fields is 1, even if the line was empty.

Returns:int

the number of fields in this record

See Also
CsvReader.CsvReaderBuilder#allowExtraFields(boolean), CsvReader.CsvReaderBuilder#allowMissingFields(boolean)
getFieldsback to summary
public List<String> getFields()

Retrieves all fields of this record as an unmodifiable list.

The returned list has a minimum size of 1, even if the line was empty. For empty lines, the first field is an empty string.

Returns:List<String>

all fields of this record, never null

getStartingLineNumberback to summary
public long getStartingLineNumber()

Provides the line number at which this record originated, starting from 1.

This information is particularly valuable in scenarios involving CSV files containing empty lines as well as multi-line or commented records, where the record number may deviate from the line number.

Example:

1 foo,bar 2 foo,"multi 3 line bar" 4 (empty, potentially skipped) 5 #commented record (potentially skipped) 6 "latest 7 record"
1 foo,bar
2 foo,"multi
3 line bar"
4                    (empty, potentially skipped)
5 #commented record  (potentially skipped)
6 "latest
7 record"

The last record (containing the multi-line field "latest\nrecord") would have a starting line number of 6, no matter if empty lines or commented records are skipped or not.

A starting offset of 1 is used to be consistent with the line numbers shown of most text editors.

Note that this number is only correct if the CSV data was read from the very beginning. If you passed a java.io.Reader to the CsvReader and have already read from it, the line number will be incorrect.

Returns:long

the starting line number of this record, starting from 1

isCommentback to summary
public boolean isComment()

Indicates whether the record is a commented record.

Retrieve the comment by calling getField(int) with index 0.

Returns:boolean

true if the record is a commented record

See Also
CsvReader.CsvReaderBuilder#commentStrategy(CommentStrategy)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override