add constructor for Table to deal with iterator (#1956)

This commit is contained in:
Ben Fry
2013-08-13 22:21:19 -04:00
parent 55b7719367
commit fa07dc1dbc
3 changed files with 47 additions and 12 deletions

View File

@@ -152,6 +152,17 @@ public class Table {
}
public Table(Iterable<TableRow> 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();
}
}

View File

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

View File

@@ -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