
com.magictools.core.text.csv.CsvData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of magic-tools-all Show documentation
Show all versions of magic-tools-all Show documentation
magic-tools 是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
The newest version!
package com.magictools.core.text.csv;
import java.io.Serializable;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* CSV数据,包括头部信息和行数据,参考:FastCSV
*
* @author Looly
*/
public class CsvData implements Iterable, Serializable {
private static final long serialVersionUID = 1L;
private final List header;
private final List rows;
/**
* 构造
*
* @param header 头信息, 可以为null
* @param rows 行
*/
public CsvData(final List header, final List rows) {
this.header = header;
this.rows = rows;
}
/**
* 总行数
*
* @return 总行数
*/
public int getRowCount() {
return this.rows.size();
}
/**
* 获取头信息列表,如果无头信息为{@code Null},返回列表为只读列表
*
* @return the header row - might be {@code null} if no header exists
*/
public List getHeader() {
if(null == this.header){
return null;
}
return Collections.unmodifiableList(this.header);
}
/**
* 获取指定行,从0开始
*
* @param index 行号
* @return 行数据
* @throws IndexOutOfBoundsException if index is out of range
*/
public CsvRow getRow(final int index) {
return this.rows.get(index);
}
/**
* 获取所有行
*
* @return 所有行
*/
public List getRows() {
return this.rows;
}
@Override
public Iterator iterator() {
return this.rows.iterator();
}
@Override
public String toString() {
return "CsvData{" +
"header=" + header +
", rows=" + rows +
'}';
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy