fixing up StringDict(TableRow) and Table.trim() now removes extra rows and columns

This commit is contained in:
Ben Fry
2017-01-31 04:55:03 -05:00
parent ea65d7f034
commit c90176cf8a
3 changed files with 62 additions and 8 deletions

View File

@@ -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();
}