Class CsvRow
java.lang.Object
cloud.opencode.base.csv.CsvRow
CSV Row - Immutable representation of a single CSV row
CSV行 - 单行CSV数据的不可变表示
Represents a single row in a CSV document. Each row contains an ordered list of string field values and an optional 1-based row number for location tracking. All instances are immutable and thread-safe.
表示CSV文档中的单行。每行包含一个有序的字符串字段值列表和一个可选的1起始行号用于位置跟踪。 所有实例都是不可变且线程安全的。
Features | 主要功能:
- Immutable field values - 不可变字段值
- 1-based row number tracking - 1起始行号跟踪
- Index and header-based field access - 基于索引和标题的字段访问
- Conversion to Map with headers - 使用标题转换为Map
- Stream support - 流支持
Usage Examples | 使用示例:
CsvRow row = CsvRow.of("Alice", "30", "Engineer");
String name = row.get(0);
CsvRow numbered = CsvRow.of(1, "Bob", "25", "Designer");
Map<String, String> map = numbered.toMap(List.of("name", "age", "role"));
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Null-safe: Fields may contain null - 空值安全: 字段可能包含null
- Since:
- JDK 25, opencode-base-csv V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intRow number indicating unknown position | 表示未知位置的行号 -
Method Summary
Modifier and TypeMethodDescriptionbooleanfields()get(int index) Gets a field value by index 通过索引获取字段值get(String headerName, CsvDocument parent) Gets a field value by header name using the parent document's headers 使用父文档的标题通过标题名获取字段值inthashCode()booleanisEmpty()Checks if all fields are empty or the row has no fields 检查所有字段是否为空或行没有字段static CsvRowCreates a row from field values with a specific row number 创建指定行号的字段值行static CsvRowCreates a row from a list of field values with a specific row number 从字段值列表创建指定行号的行static CsvRowCreates a row from field values with unknown row number 创建字段值行(行号未知)intGets the 1-based row number 获取1起始行号intsize()Gets the number of fields in this row 获取此行的字段数stream()Returns a stream of field values 返回字段值的流Converts this row to a map using the provided headers as keys 使用提供的标题作为键将此行转换为MaptoString()values()Returns an unmodifiable list of field values 返回字段值的不可修改列表
-
Field Details
-
UNKNOWN_ROW
public static final int UNKNOWN_ROWRow number indicating unknown position | 表示未知位置的行号- See Also:
-
-
Method Details
-
of
-
of
-
of
Creates a row from a list of field values with a specific row number 从字段值列表创建指定行号的行- Parameters:
rowNumber- the 1-based row number | 1起始行号fields- the field values | 字段值- Returns:
- the row | 行
- Throws:
NullPointerException- if fields is null | 如果fields为null
-
get
Gets a field value by index 通过索引获取字段值- Parameters:
index- the 0-based field index | 0起始字段索引- Returns:
- the field value | 字段值
- Throws:
IndexOutOfBoundsException- if index is out of range | 如果索引越界
-
get
Gets a field value by header name using the parent document's headers 使用父文档的标题通过标题名获取字段值- Parameters:
headerName- the header name | 标题名parent- the parent document providing headers | 提供标题的父文档- Returns:
- the field value | 字段值
- Throws:
IllegalArgumentException- if header name is not found | 如果标题名未找到IndexOutOfBoundsException- if the header index exceeds this row's fields | 如果标题索引超过此行字段数
-
size
public int size()Gets the number of fields in this row 获取此行的字段数- Returns:
- the number of fields | 字段数
-
isEmpty
public boolean isEmpty()Checks if all fields are empty or the row has no fields 检查所有字段是否为空或行没有字段- Returns:
- true if empty | 如果为空返回true
-
rowNumber
public int rowNumber()Gets the 1-based row number 获取1起始行号- Returns:
- the row number, or -1 if unknown | 行号,未知则返回-1
-
values
-
fields
-
stream
-
toMap
Converts this row to a map using the provided headers as keys 使用提供的标题作为键将此行转换为MapIf this row has fewer fields than headers, missing fields map to null. If this row has more fields than headers, extra fields are ignored.
如果此行的字段少于标题,缺少的字段映射为null。 如果此行的字段多于标题,多余的字段被忽略。
- Parameters:
headers- the header names | 标题名- Returns:
- an unmodifiable map of header-to-value | 不可修改的标题到值的Map
- Throws:
NullPointerException- if headers is null | 如果headers为null
-
equals
-
hashCode
-
toString
-