diff --git a/core/src/processing/data/Table.java b/core/src/processing/data/Table.java index c270dd96e..1e963abb0 100644 --- a/core/src/processing/data/Table.java +++ b/core/src/processing/data/Table.java @@ -155,11 +155,12 @@ public class Table { public Table(Iterable rows) { init(); - boolean typed = false; + boolean firstRow = true; for (TableRow row : rows) { - if (!typed) { + if (firstRow) { setColumnTypes(row.getColumnTypes()); - typed = true; + setColumnTitles(row.getColumnTitles()); + firstRow = false; } addRow(row); } @@ -505,6 +506,7 @@ public class Table { if (count > 0) { setString(row, col, new String(c, 0, count)); } + row++; // set row to row count (the current row index + 1) if (alloc != row) { setRowCount(row); // shrink to the actual size } @@ -1841,7 +1843,6 @@ public class Table { for (int col = 0; col < columns.length; col++) { switch (columnTypes[col]) { - case CATEGORY: case INT: setInt(row, col, source.getInt(col)); break; @@ -1857,6 +1858,14 @@ public class Table { case STRING: setString(row, col, source.getString(col)); break; + case CATEGORY: + int index = source.getInt(col); + setInt(row, col, index); + if (columnCategories[col].hasCategory(index)) { + columnCategories[col].setCategory(index, source.getString(col)); + } + break; + default: throw new RuntimeException("no types"); } @@ -2289,6 +2298,14 @@ public class Table { public int[] getColumnTypes() { return table.getColumnTypes(); } + + public String getColumnTitle(int column) { + return table.getColumnTitle(column); + } + + public String[] getColumnTitles() { + return table.getColumnTitles(); + } } @@ -3609,6 +3626,18 @@ public class Table { return indexToData.get(index); } + boolean hasCategory(int index) { + return index < size() && indexToData.get(index) != null; + } + + void setCategory(int index, String name) { + while (indexToData.size() <= index) { + indexToData.add(null); + } + indexToData.set(index, name); + dataToIndex.put(name, index); + } + int size() { return dataToIndex.size(); } @@ -3630,9 +3659,11 @@ public class Table { void read(DataInputStream input) throws IOException { int count = input.readInt(); + System.out.println("found " + count + " entries in category map"); dataToIndex = new HashMap(count); for (int i = 0; i < count; i++) { String str = input.readUTF(); + System.out.println(i + " " + str); dataToIndex.put(str, i); indexToData.add(str); } diff --git a/core/src/processing/data/TableRow.java b/core/src/processing/data/TableRow.java index 7107ee693..87e288825 100644 --- a/core/src/processing/data/TableRow.java +++ b/core/src/processing/data/TableRow.java @@ -109,4 +109,7 @@ public interface TableRow { public int getColumnType(int column); public int[] getColumnTypes(); + + public String getColumnTitle(int column); + public String[] getColumnTitles(); } diff --git a/core/todo.txt b/core/todo.txt index 224efcd5a..e27a87278 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -8,8 +8,13 @@ o Jer and Dan will look at their code, plus toxiclibs table X major performance improvements to 'newlines' parsing -X debugging table parsing with header rows -X bug fix for setting data type +X last row was being skipped on tables with the 'newlines' option set +X debug table parsing with header rows +X bug fix for setting data types +X add getColumnTitle(int) and getColumnTitles() to TableRow interface +X fixes for new Table(Iterable) +X category data types were not importing their dictionary +X column titles weren't set on the new table applet removal