The field values are never null
. Empty fields are represented as empty strings.
- See Also:
-
Field Summary
FieldsFields inherited from class de.siegmar.fastcsv.reader.CsvRecord
comment, fields, startingLineNumber
-
Constructor Summary
ConstructorsConstructorDescriptionNamedCsvRecord
(long startingLineNumber, String[] fields, boolean comment, String[] header) -
Method Summary
Modifier and TypeMethodDescriptionprivate int
Retrieves the value of a field by its case-sensitive name, considering the first occurrence in case of duplicates.findFields
(String name) Collects all field values with the given name (case-sensitive) in the order they appear in the header.private int
findHeaderIndex
(String name) Retrieves the value of a field by its case-sensitive name, considering the first occurrence in case of duplicates.Constructs an ordered map, associating header names with corresponding field values of this record, considering the first occurrence in case of duplicates.Constructs an unordered map, associating header names with an ordered list of corresponding field values in this record.Retrieves the header names of this record.toString()
Methods inherited from class de.siegmar.fastcsv.reader.CsvRecord
getField, getFieldCount, getFields, getStartingLineNumber, isComment
-
Field Details
-
header
-
-
Constructor Details
-
NamedCsvRecord
-
-
Method Details
-
getHeader
Retrieves the header names of this record.The header names are returned in the order they appear in the CSV file.
Note that the header names are not necessarily unique. If you need to collect all fields with the same name (duplicate header), use
getFieldsAsMapList()
.Note that records for commented lines (
CsvRecord.isComment()
) do not have an empty header. To retrieve the comment value, userCsvRecord.getField(int)
with index 0.- Returns:
- the header names, never
null
-
getField
Retrieves the value of a field by its case-sensitive name, considering the first occurrence in case of duplicates.This method is equivalent to
findField(name).orElseThrow(NoSuchElementException::new)
although a more explanatory exception message is provided.- Parameters:
name
- case-sensitive name of the field to be retrieved- Returns:
- field value, never
null
- Throws:
NoSuchElementException
- if this record has no such fieldNullPointerException
- if name isnull
- See Also:
-
findHeaderIndex
-
findField
Retrieves the value of a field by its case-sensitive name, considering the first occurrence in case of duplicates.This method is equivalent to
findFields(name).stream().findFirst()
but more performant.- Parameters:
name
- case-sensitive name of the field to be retrieved- Returns:
- An
Optional
containing the value of the field if found, or an emptyOptional
if the field is not present. Never returnsnull
. - Throws:
NullPointerException
- if name isnull
- See Also:
-
findFields
Collects all field values with the given name (case-sensitive) in the order they appear in the header.- Parameters:
name
- case-sensitive name of the field to collect values for- Returns:
- the field values (empty list if record doesn't contain that field), never
null
- Throws:
NullPointerException
- if name isnull
-
getFieldsAsMap
Constructs an ordered map, associating header names with corresponding field values of this record, considering the first occurrence in case of duplicates.The constructed map will only contain entries for fields that have a key and a value. No map entry will have a
null
key or value.If you need to collect all fields with the same name (duplicate header), use
getFieldsAsMapList()
.- Returns:
- an ordered map of header names and field values of this record, never
null
- See Also:
-
getFieldsAsMapList
Constructs an unordered map, associating header names with an ordered list of corresponding field values in this record.The constructed map will only contain entries for fields that have a key and a value. No map entry will have a
null
key or value.If you don't have to handle duplicate headers, you may simply use
getFieldsAsMap()
.- Returns:
- an unordered map of header names and field values of this record, never
null
- See Also:
-
commonSize
private int commonSize() -
toString
-