adding dictionary option for table loading

This commit is contained in:
Ben Fry
2013-08-13 21:51:35 -04:00
parent d7fde748a0
commit 55b7719367
3 changed files with 48 additions and 24 deletions

View File

@@ -119,6 +119,7 @@ public class Table {
*/
public Table(File file, String options) throws IOException {
// uses createInput() to handle .gz (and eventually .bz2) files
init();
parse(PApplet.createInput(file),
extensionOptions(true, file.getName(), options));
}
@@ -146,9 +147,11 @@ public class Table {
* @throws IOException
*/
public Table(InputStream input, String options) throws IOException {
init();
parse(input, options);
}
/**
* @nowebref
*/
@@ -210,6 +213,14 @@ public class Table {
}
public Table typedParse(InputStream input, String options) throws IOException {
Table table = new Table();
table.setColumnTypes(this);
table.parse(input, options);
return table;
}
protected void init() {
columns = new Object[0];
columnTypes = new int[0];
@@ -272,7 +283,7 @@ public class Table {
protected void parse(InputStream input, String options) throws IOException {
init();
//init();
boolean awfulCSV = false;
boolean header = false;
@@ -302,6 +313,8 @@ public class Table {
header = true;
} else if (opt.startsWith(sheetParam)) {
worksheet = opt.substring(sheetParam.length());
} else if (opt.startsWith("dictionary=")) {
// ignore option, this is only handled by PApplet
} else {
throw new IllegalArgumentException("'" + opt + "' is not a valid option for loading a Table");
}
@@ -352,9 +365,9 @@ public class Table {
row++;
}
/*
// this is problematic unless we're going to calculate rowCount first
if (row % 10000 == 0) {
// this is problematic unless we're going to calculate rowCount first
if (row % 10000 == 0) {
/*
if (row < rowCount) {
int pct = (100 * row) / rowCount;
if (pct != prev) { // also prevents "0%" from showing up
@@ -362,14 +375,15 @@ public class Table {
prev = pct;
}
}
try {
Thread.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
*/
try {
// Sleep this thread so that the GC can catch up
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
*/
}
} catch (Exception e) {
throw new RuntimeException("Error reading table on line " + row, e);
}