From fa07dc1dbcef7741dd11c700e734ef459055b2ab Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Tue, 13 Aug 2013 22:21:19 -0400 Subject: [PATCH] add constructor for Table to deal with iterator (#1956) --- core/src/processing/data/Table.java | 28 ++++++++++++++++++++++++++ core/src/processing/data/TableRow.java | 6 ++++-- core/todo.txt | 25 ++++++++++++++--------- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/core/src/processing/data/Table.java b/core/src/processing/data/Table.java index a91b088b8..2a3c4f857 100644 --- a/core/src/processing/data/Table.java +++ b/core/src/processing/data/Table.java @@ -152,6 +152,17 @@ public class Table { } + public Table(Iterable rows) { + boolean typed = false; + for (TableRow row : rows) { + if (!typed) { + setColumnTypes(row.getColumnTypes()); + } + addRow(row); + } + } + + /** * @nowebref */ @@ -1546,6 +1557,13 @@ public class Table { } + public void setColumnTypes(int[] types) { + for (int col = 0; col < types.length; col++) { + setColumnType(col, types[col]); + } + } + + /** * Set the titles (and if a second column is present) the data types for * this table based on a file loaded separately. This will look for the @@ -1602,6 +1620,11 @@ public class Table { } + public int[] getColumnTypes() { + return columnTypes; + } + + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . @@ -1776,6 +1799,7 @@ public class Table { * @see Table#clearRows() */ public TableRow addRow() { + //if (rowIncrement == 0) { setRowCount(rowCount + 1); return new RowPointer(this, rowCount - 1); } @@ -2230,6 +2254,10 @@ public class Table { public int getColumnType(int column) { return table.getColumnType(column); } + + public int[] getColumnTypes() { + return table.getColumnTypes(); + } } diff --git a/core/src/processing/data/TableRow.java b/core/src/processing/data/TableRow.java index 299d6eea4..7107ee693 100644 --- a/core/src/processing/data/TableRow.java +++ b/core/src/processing/data/TableRow.java @@ -36,7 +36,7 @@ public interface TableRow { * @param columnName title of the column to reference */ public int getInt(String columnName); - + public long getLong(int column); public long getLong(String columnName); @@ -52,7 +52,7 @@ public interface TableRow { * @param columnName title of the column to reference */ public float getFloat(String columnName); - + public double getDouble(int column); public double getDouble(String columnName); @@ -107,4 +107,6 @@ public interface TableRow { public int getColumnCount(); public int getColumnType(String columnName); public int getColumnType(int column); + + public int[] getColumnTypes(); } diff --git a/core/todo.txt b/core/todo.txt index 40732ddaf..e36f5bf8b 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -42,11 +42,19 @@ o decision: useExtension() or something like that X put saveXxxx() methods inside PApplet o require people to put things in the data folder +table +X add sort() to Table +X implement version of Table that takes a dictionary file +X dictionary=blah.tsv +X tsv only, ignores extension +X if allowed extension, we couldn't use .dict instead +X and that's probably the most useful +X constructing table from an iterator is missing +X https://github.com/processing/processing/issues/1956 + andres X pixels[] array not updated with Capture and P2D/P3D X https://github.com/processing/processing/issues/1852 -_ Unable to get TAB key event with P2D/P3D renderer -_ https://github.com/processing/processing/issues/1967 high _ blendMode(ADD) is broken with default renderer @@ -68,19 +76,16 @@ _ finish PFont.getShape() implementation _ needs to have a way to set width/height properly _ draw(s) doesn't work on the returned PShape +andres +_ Unable to get TAB key event with P2D/P3D renderer +_ https://github.com/processing/processing/issues/1967 + table -X add sort() to Table -X implement version of Table that takes a dictionary file -X dictionary=blah.tsv -X tsv only, ignores extension -X if allowed extension, we couldn't use .dict instead -X and that's probably the most useful _ addRow() is not efficient, probably need to do the doubling _ or have a setIncrement() function? _ it would default to 1 on tables loaded from a file _ and default to doubling when created with "new Table" -_ constructing table from an iterator is missing -_ https://github.com/processing/processing/issues/1956 +_ row count and array size are combined.. need to break apart _ match and iterators _ add match version that returns table that's only a pointer to original _ save the constructor for the version that actually copies data