mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
fixing up StringDict(TableRow) and Table.trim() now removes extra rows and columns
This commit is contained in:
@@ -110,9 +110,12 @@ public class StringDict {
|
||||
|
||||
/**
|
||||
* Create a dictionary that maps between column titles and cell entries
|
||||
* in a TableRow.
|
||||
* in a TableRow. If two columns have the same name, the later column's
|
||||
* values will override the earlier values.
|
||||
*/
|
||||
public StringDict(TableRow row) {
|
||||
this(row.getColumnCount());
|
||||
|
||||
String[] titles = row.getColumnTitles();
|
||||
if (titles == null) {
|
||||
titles = new StringList(IntList.fromRange(row.getColumnCount())).array();
|
||||
@@ -120,6 +123,8 @@ public class StringDict {
|
||||
for (int col = 0; col < row.getColumnCount(); col++) {
|
||||
set(titles[col], row.getString(col));
|
||||
}
|
||||
// remove unused and overwritten entries
|
||||
crop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4059,8 +4059,58 @@ public class Table {
|
||||
for (int col = 0; col < getColumnCount(); col++) {
|
||||
trim(col);
|
||||
}
|
||||
// remove empty columns
|
||||
int lastColumn = getColumnCount() - 1;
|
||||
//while (isEmptyColumn(lastColumn) && lastColumn >= 0) {
|
||||
while (isEmptyArray(getStringColumn(lastColumn)) && lastColumn >= 0) {
|
||||
lastColumn--;
|
||||
}
|
||||
setColumnCount(lastColumn + 1);
|
||||
|
||||
// remove empty rows (starting from the end)
|
||||
int lastRow = lastRowIndex();
|
||||
//while (isEmptyRow(lastRow) && lastRow >= 0) {
|
||||
while (isEmptyArray(getStringRow(lastRow)) && lastRow >= 0) {
|
||||
lastRow--;
|
||||
}
|
||||
setRowCount(lastRow + 1);
|
||||
}
|
||||
|
||||
|
||||
protected boolean isEmptyArray(String[] contents) {
|
||||
for (String entry : contents) {
|
||||
if (entry != null && entry.length() > 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
protected boolean isEmptyColumn(int column) {
|
||||
String[] contents = getStringColumn(column);
|
||||
for (String entry : contents) {
|
||||
if (entry != null && entry.length() > 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected boolean isEmptyRow(int row) {
|
||||
String[] contents = getStringRow(row);
|
||||
for (String entry : contents) {
|
||||
if (entry != null && entry.length() > 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param column ID number of the column to trim
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user