public final class CSVRecord extends Object implements Serializable, Iterable<String>
Note: Support for Serializable
is scheduled to be removed in version 2.0.
In version 1.8 the mapping between the column header and the column index was
removed from the serialised state. The class maintains serialization compatibility
with versions pre-1.8 for the record values; these must be accessed by index
following deserialization. There will be loss of any functionally linked to the header
mapping when transferring serialised forms pre-1.8 to 1.8 and vice versa.
Modifier and Type | Method and Description |
---|---|
String |
get(Enum<?> e)
Returns a value by
Enum . |
String |
get(int i)
Returns a value by index.
|
String |
get(String name)
Returns a value by name.
|
long |
getCharacterPosition()
Returns the start position of this record as a character position in the source stream.
|
String |
getComment()
Returns the comment for this record, if any.
|
CSVParser |
getParser()
Returns the parser.
|
long |
getRecordNumber()
Returns the number of this record in the parsed CSV file.
|
boolean |
hasComment()
Checks whether this record has a comment, false otherwise.
|
boolean |
isConsistent()
Tells whether the record size matches the header size.
|
boolean |
isMapped(String name)
Checks whether a given column is mapped, i.e.
|
boolean |
isSet(int index)
Checks whether a column with given index has a value.
|
boolean |
isSet(String name)
Checks whether a given columns is mapped and has a value.
|
Iterator<String> |
iterator()
Returns an iterator over the values of this record.
|
<M extends Map<String,String>> |
putIn(M map)
Puts all values of this record into the given Map.
|
int |
size()
Returns the number of values in this record.
|
Stream<String> |
stream()
Returns a sequential ordered stream whose elements are the values.
|
List<String> |
toList()
Converts the values to a new List.
|
Map<String,String> |
toMap()
Copies this record into a new Map of header name to record value.
|
String |
toString()
Returns a string representation of the contents of this record.
|
String[] |
values()
Gets the values for this record.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public String get(Enum<?> e)
Enum
.e
- an enumpublic String get(int i)
i
- a column index (0-based)public String get(String name)
Note: This requires a field mapping obtained from the original parser.
A check using isMapped(String)
should be used to determine if a
mapping exists from the provided name
to a field index. In this case an
exception will only be thrown if the record does not contain a field corresponding
to the mapping, that is the record length is not consistent with the mapping size.
name
- the name of the column to be retrieved.CSVFormat.getNullString()
.IllegalStateException
- if no header mapping was providedIllegalArgumentException
- if name
is not mapped or if the record is inconsistentisMapped(String)
,
isConsistent()
,
getParser()
,
CSVFormat.Builder.setNullString(String)
public long getCharacterPosition()
public String getComment()
public CSVParser getParser()
Note: The parser is not part of the serialized state of the record. A null check should be used when the record may have originated from a serialized form.
public long getRecordNumber()
ATTENTION: If your CSV input has multi-line values, the returned number does not correspond to the current line number of the parser that created this record.
CSVParser.getCurrentLineNumber()
public boolean hasComment()
public boolean isConsistent()
Returns true if the sizes for this record match and false if not. Some programs can export files that fail this test but still produce parsable files.
public boolean isMapped(String name)
name
- the name of the column to be retrieved.public boolean isSet(int index)
index
- a column index (0-based)public boolean isSet(String name)
name
- the name of the column to be retrieved.public <M extends Map<String,String>> M putIn(M map)
M
- the map typemap
- The Map to populate.public int size()
public Stream<String> stream()
public List<String> toList()
Editing the list does not update this instance.
public Map<String,String> toMap()
Editing the map does not update this instance.
public String toString()
Arrays.toString(Object[])
.Copyright © 2005–2022 The Apache Software Foundation. All rights reserved.