|
@@ -25,7 +25,7 @@ public class SimpleTable implements Serializable {
|
|
|
/**
|
|
|
* 表格数据行
|
|
|
*/
|
|
|
- private final List<List<String>> tables;
|
|
|
+ private final List<List<String>> data;
|
|
|
/**
|
|
|
* 表格列数
|
|
|
*/
|
|
@@ -39,14 +39,14 @@ public class SimpleTable implements Serializable {
|
|
|
this.tableKey = tableKey;
|
|
|
this.title = title;
|
|
|
this.colCount = colCount;
|
|
|
- this.tables = ListUtil.list(true);
|
|
|
+ this.data = ListUtil.list(true);
|
|
|
}
|
|
|
|
|
|
public void addRow(List<String> row) {
|
|
|
- tables.add(row);
|
|
|
+ data.add(row);
|
|
|
this.rowCount++;
|
|
|
if (this.colCount == 0) {
|
|
|
- this.colCount = this.tables.stream().map(List::size).max(Comparator.naturalOrder()).orElse(0);
|
|
|
+ this.colCount = this.data.stream().map(List::size).max(Comparator.naturalOrder()).orElse(0);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -66,19 +66,24 @@ public class SimpleTable implements Serializable {
|
|
|
return title;
|
|
|
}
|
|
|
|
|
|
- public List<List<String>> getTables() {
|
|
|
- int subRows = this.rowCount - this.tables.size();
|
|
|
+ /**
|
|
|
+ * 获取表格数据,如果当前表格的行不等于约定的表格行则需要追加null值行
|
|
|
+ *
|
|
|
+ * @return /
|
|
|
+ */
|
|
|
+ public List<List<String>> getData() {
|
|
|
+ int subRows = this.rowCount - this.data.size();
|
|
|
if (subRows <= 0) {
|
|
|
- return this.tables;
|
|
|
+ return this.data;
|
|
|
}
|
|
|
for (int i = 0; i < subRows; i++) {
|
|
|
List<String> row = ListUtil.list(true);
|
|
|
for (int j = 0; j < this.colCount; j++) {
|
|
|
row.add(null);
|
|
|
}
|
|
|
- this.tables.add(row);
|
|
|
+ this.data.add(row);
|
|
|
}
|
|
|
- return this.tables;
|
|
|
+ return this.data;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -87,7 +92,7 @@ public class SimpleTable implements Serializable {
|
|
|
* @return /
|
|
|
*/
|
|
|
public Iterator<List<String>> iterator() {
|
|
|
- return new TableIterator(this.getTables());
|
|
|
+ return new TableIterator(this.getData());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -98,7 +103,7 @@ public class SimpleTable implements Serializable {
|
|
|
* @return 单元格内容
|
|
|
*/
|
|
|
public String getCell(int row, int column) {
|
|
|
- List<List<String>> rows = this.getTables();
|
|
|
+ List<List<String>> rows = this.getData();
|
|
|
if (row < 0 || row >= rows.size() || column < 0 || column >= rows.get(row).size()) {
|
|
|
throw new IndexOutOfBoundsException("Invalid row or column index");
|
|
|
}
|
|
@@ -109,7 +114,7 @@ public class SimpleTable implements Serializable {
|
|
|
public String toString() {
|
|
|
return "SimpleTable{" +
|
|
|
"title='" + title + '\'' +
|
|
|
- ", tables=" + tables +
|
|
|
+ ", data=" + data +
|
|
|
'}';
|
|
|
}
|
|
|
|
|
@@ -117,21 +122,21 @@ public class SimpleTable implements Serializable {
|
|
|
* 内部迭代器类
|
|
|
*/
|
|
|
private static class TableIterator implements Iterator<List<String>> {
|
|
|
- private final List<List<String>> tables;
|
|
|
+ private final List<List<String>> data;
|
|
|
private int currentIndex = 0;
|
|
|
|
|
|
- public TableIterator(List<List<String>> tables) {
|
|
|
- this.tables = tables;
|
|
|
+ public TableIterator(List<List<String>> data) {
|
|
|
+ this.data = data;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean hasNext() {
|
|
|
- return currentIndex < tables.size();
|
|
|
+ return currentIndex < data.size();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<String> next() {
|
|
|
- return tables.get(currentIndex++);
|
|
|
+ return data.get(currentIndex++);
|
|
|
}
|
|
|
}
|
|
|
}
|