mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
table fixes and additions
This commit is contained in:
@@ -392,7 +392,7 @@ public class Table {
|
||||
count = 0;
|
||||
// starting a new column, make sure we have room
|
||||
col++;
|
||||
checkColumn(col);
|
||||
ensureColumn(col);
|
||||
|
||||
} else { // just a regular character, add it
|
||||
if (count == c.length) {
|
||||
@@ -1309,7 +1309,7 @@ public class Table {
|
||||
|
||||
public void setColumnTitles(String[] titles) {
|
||||
if (titles != null) {
|
||||
checkColumn(titles.length - 1);
|
||||
ensureColumn(titles.length - 1);
|
||||
}
|
||||
columnTitles = titles;
|
||||
columnIndices = null; // remove the cache
|
||||
@@ -1317,7 +1317,7 @@ public class Table {
|
||||
|
||||
|
||||
public void setColumnTitle(int column, String title) {
|
||||
checkColumn(column);
|
||||
ensureColumn(column);
|
||||
if (columnTitles == null) {
|
||||
columnTitles = new String[getColumnCount()];
|
||||
}
|
||||
@@ -1449,6 +1449,37 @@ public class Table {
|
||||
}
|
||||
|
||||
|
||||
public TableRow addRow(TableRow source) {
|
||||
int row = rowCount;
|
||||
// Make sure there are enough columns to add this data
|
||||
ensureBounds(row, source.getColumnCount() - 1);
|
||||
|
||||
for (int col = 0; col < columns.length; col++) {
|
||||
switch (columnTypes[col]) {
|
||||
case CATEGORICAL:
|
||||
case INT:
|
||||
setInt(row, col, source.getInt(col));
|
||||
break;
|
||||
case LONG:
|
||||
setLong(row, col, source.getLong(col));
|
||||
break;
|
||||
case FLOAT:
|
||||
setFloat(row, col, source.getFloat(col));
|
||||
break;
|
||||
case DOUBLE:
|
||||
setDouble(row, col, source.getDouble(col));
|
||||
break;
|
||||
case STRING:
|
||||
setString(row, col, source.getString(col));
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("no types");
|
||||
}
|
||||
}
|
||||
return new RowPointer(this, row);
|
||||
}
|
||||
|
||||
|
||||
public TableRow addRow(Object[] columnData) {
|
||||
setRow(getRowCount(), columnData);
|
||||
return new RowPointer(this, rowCount - 1);
|
||||
@@ -1609,7 +1640,7 @@ public class Table {
|
||||
|
||||
|
||||
public void setRow(int row, Object[] pieces) {
|
||||
checkSize(row, pieces.length - 1);
|
||||
ensureBounds(row, pieces.length - 1);
|
||||
// pieces.length may be less than columns.length, so loop over pieces
|
||||
for (int col = 0; col < pieces.length; col++) {
|
||||
setRowCol(row, col, pieces[col]);
|
||||
@@ -1820,6 +1851,10 @@ public class Table {
|
||||
public void setDouble(String columnName, double value) {
|
||||
table.setDouble(row, columnName, value);
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
return table.getColumnCount();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2008,6 +2043,14 @@ public class Table {
|
||||
throw new IllegalArgumentException("This TableRow cannot be modified.");
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
try {
|
||||
return rs.getMetaData().getColumnCount();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2049,7 +2092,7 @@ public class Table {
|
||||
setString(row, column, String.valueOf(value));
|
||||
|
||||
} else {
|
||||
checkSize(row, column);
|
||||
ensureBounds(row, column);
|
||||
if (columnTypes[column] != INT &&
|
||||
columnTypes[column] != CATEGORICAL) {
|
||||
throw new IllegalArgumentException("Column " + column + " is not an int column.");
|
||||
@@ -2126,7 +2169,7 @@ public class Table {
|
||||
setString(row, column, String.valueOf(value));
|
||||
|
||||
} else {
|
||||
checkSize(row, column);
|
||||
ensureBounds(row, column);
|
||||
if (columnTypes[column] != LONG) {
|
||||
throw new IllegalArgumentException("Column " + column + " is not a 'long' column.");
|
||||
}
|
||||
@@ -2202,7 +2245,7 @@ public class Table {
|
||||
setString(row, column, String.valueOf(value));
|
||||
|
||||
} else {
|
||||
checkSize(row, column);
|
||||
ensureBounds(row, column);
|
||||
if (columnTypes[column] != FLOAT) {
|
||||
throw new IllegalArgumentException("Column " + column + " is not a float column.");
|
||||
}
|
||||
@@ -2277,7 +2320,7 @@ public class Table {
|
||||
setString(row, column, String.valueOf(value));
|
||||
|
||||
} else {
|
||||
checkSize(row, column);
|
||||
ensureBounds(row, column);
|
||||
if (columnTypes[column] != DOUBLE) {
|
||||
throw new IllegalArgumentException("Column " + column + " is not a 'double' column.");
|
||||
}
|
||||
@@ -2409,7 +2452,7 @@ public class Table {
|
||||
|
||||
|
||||
public void setString(int row, int column, String value) {
|
||||
checkSize(row, column);
|
||||
ensureBounds(row, column);
|
||||
if (columnTypes[column] != STRING) {
|
||||
throw new IllegalArgumentException("Column " + column + " is not a String column.");
|
||||
}
|
||||
@@ -2457,7 +2500,7 @@ public class Table {
|
||||
* @param column the column to search
|
||||
*/
|
||||
public int findRowIndex(String value, int column) {
|
||||
checkBounds(-1, column);
|
||||
checkColumn(column);
|
||||
if (columnTypes[column] == STRING) {
|
||||
String[] stringData = (String[]) columns[column];
|
||||
if (value == null) {
|
||||
@@ -2507,7 +2550,7 @@ public class Table {
|
||||
int[] outgoing = new int[rowCount];
|
||||
int count = 0;
|
||||
|
||||
checkBounds(-1, column);
|
||||
checkColumn(column);
|
||||
if (columnTypes[column] == STRING) {
|
||||
String[] stringData = (String[]) columns[column];
|
||||
if (value == null) {
|
||||
@@ -2583,7 +2626,7 @@ public class Table {
|
||||
* @param column the column to search
|
||||
*/
|
||||
public int matchRowIndex(String regexp, int column) {
|
||||
checkBounds(-1, column);
|
||||
checkColumn(column);
|
||||
if (columnTypes[column] == STRING) {
|
||||
String[] stringData = (String[]) columns[column];
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
@@ -2625,7 +2668,7 @@ public class Table {
|
||||
int[] outgoing = new int[rowCount];
|
||||
int count = 0;
|
||||
|
||||
checkBounds(-1, column);
|
||||
checkColumn(column);
|
||||
if (columnTypes[column] == STRING) {
|
||||
String[] stringData = (String[]) columns[column];
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
@@ -2727,7 +2770,7 @@ public class Table {
|
||||
|
||||
|
||||
public void replaceAll(String regex, String replacement, int column) {
|
||||
checkBounds(-1, column);
|
||||
checkColumn(column);
|
||||
if (columnTypes[column] == STRING) {
|
||||
String[] stringData = (String[]) columns[column];
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
@@ -2829,36 +2872,52 @@ public class Table {
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
protected void checkColumn(int col) {
|
||||
/** Make sure this is a legit column, and if not, expand the table. */
|
||||
protected void ensureColumn(int col) {
|
||||
if (col >= columns.length) {
|
||||
setColumnCount(col + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void checkRow(int row) {
|
||||
/** Make sure this is a legit row, and if not, expand the table. */
|
||||
protected void ensureRow(int row) {
|
||||
if (row >= rowCount) {
|
||||
setRowCount(row + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void checkSize(int row, int col) {
|
||||
checkRow(row);
|
||||
checkColumn(col);
|
||||
/** Make sure this is a legit row and column. If not, expand the table. */
|
||||
protected void ensureBounds(int row, int col) {
|
||||
ensureRow(row);
|
||||
ensureColumn(col);
|
||||
}
|
||||
|
||||
|
||||
protected void checkBounds(int row, int column) {
|
||||
/** Throw an error if this row doesn't exist. */
|
||||
protected void checkRow(int row) {
|
||||
if (row < 0 || row >= rowCount) {
|
||||
throw new ArrayIndexOutOfBoundsException("Row " + row + " does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Throw an error if this column doesn't exist. */
|
||||
protected void checkColumn(int column) {
|
||||
if (column < 0 || column >= columns.length) {
|
||||
throw new ArrayIndexOutOfBoundsException("Column " + column + " does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Throw an error if this entry is out of bounds. */
|
||||
protected void checkBounds(int row, int column) {
|
||||
checkRow(row);
|
||||
checkColumn(column);
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ public class TableHTML extends Table {
|
||||
void beginTableData(int advance) {
|
||||
colAdvance = advance;
|
||||
// expand the number of columns if necessary
|
||||
checkColumn(colIndex + colAdvance - 1);
|
||||
ensureColumn(colIndex + colAdvance - 1);
|
||||
// if (colIndex + colAdvance > data[0].length) {
|
||||
// int needed = (colIndex + colAdvance) * 2;
|
||||
// for (int i = 0; i < data.length; i++) {
|
||||
|
||||
@@ -23,4 +23,6 @@ public interface TableRow {
|
||||
public void setFloat(String columnName, float value);
|
||||
public void setDouble(int column, double value);
|
||||
public void setDouble(String columnName, double value);
|
||||
|
||||
public int getColumnCount();
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ X http://code.google.com/p/processing/issues/detail?id=1542
|
||||
X add randomGaussian()
|
||||
X Add TAU as alias for TWO_PI
|
||||
X http://code.google.com/p/processing/issues/detail?id=1488
|
||||
_ waiting on reference from Casey
|
||||
X ref assigned here: https://github.com/processing/processing-web/issues/9
|
||||
X fixes for removeColumn()
|
||||
X remove SVG warning about "#text" ignored
|
||||
X fix bug where noDelays wasn't being used in PApplet
|
||||
@@ -68,6 +68,11 @@ A OpenGL/P3D sketches show graphical corruption
|
||||
A needs to be set to other color
|
||||
X http://code.google.com/p/processing/issues/detail?id=1452
|
||||
X https://github.com/processing/processing/issues/1490
|
||||
A with DISABLE_STROKE_PERSPECTIVE, use GL lines, not triangles to draw lines
|
||||
A https://github.com/processing/processing/issues/1598
|
||||
X http://code.google.com/p/processing/issues/detail?id=1560
|
||||
A disable stroke perspective by default (but this didn't fix it)
|
||||
A fixed the disappearance, though still imperfect
|
||||
|
||||
cleaning/earlier
|
||||
C textureWrap() CLAMP and REPEAT now added
|
||||
@@ -90,6 +95,8 @@ X saveTable("filename.tsv") or saveTable("filename.txt", "tsv")
|
||||
X createTable() method in PApplet
|
||||
X removed getUniqueXxxx() and some others, pending names
|
||||
X added listUnique() and tallyUnique()
|
||||
X added getColumnCount() to TableRow
|
||||
X cleaned up checkBounds()
|
||||
|
||||
xml library
|
||||
X removed 'name' field to avoid possibility of random errors
|
||||
@@ -165,10 +172,6 @@ _ get mouseWheel() added to api ref
|
||||
_ also added to keywords.txt
|
||||
|
||||
andres
|
||||
_ with DISABLE_STROKE_PERSPECTIVE, use GL lines, not triangles to draw lines
|
||||
_ https://github.com/processing/processing/issues/1598
|
||||
X http://code.google.com/p/processing/issues/detail?id=1560
|
||||
A disable stroke perspective by default (but this didn't fix it)
|
||||
_ P2D/P3D sketches don't get focus until click
|
||||
_ also problem for Java2D when canvas is used?
|
||||
_ need to standardize canvas handling
|
||||
|
||||
1
todo.txt
1
todo.txt
@@ -559,6 +559,7 @@ _ http://code.google.com/p/processing/issues/detail?id=157
|
||||
_ don't allow people to override methods like paint()
|
||||
_ make them final? just improve the error messages?
|
||||
_ http://code.google.com/p/processing/issues/detail?id=1020
|
||||
_ https://github.com/processing/processing/issues/1058
|
||||
_ Processing chokes if a sketch defines a class with same name as the sketch
|
||||
_ http://code.google.com/p/processing/issues/detail?id=157
|
||||
_ http://code.google.com/p/processing/issues/detail?id=168
|
||||
|
||||
Reference in New Issue
Block a user