@@ -119,6 +119,11 @@ public Table(File file, String options) throws IOException {
119119 }
120120
121121
122+ public Table (InputStream input ) throws IOException {
123+ this (input , null );
124+ }
125+
126+
122127 /**
123128 * Read the table from a stream. Possible options include:
124129 * <ul>
@@ -479,7 +484,6 @@ static protected int nextComma(char[] c, int index) {
479484 // compiler) of an inner class by the runtime.
480485
481486 /** incomplete, do not use */
482- // public void parseInto(PApplet sketch, String fieldName) {
483487 public void parseInto (Object enclosingObject , String fieldName ) {
484488 Class <?> target = null ;
485489 Object outgoing = null ;
@@ -1043,14 +1047,23 @@ public void setTableType(String type) {
10431047
10441048 /**
10451049 * Set the titles (and if a second column is present) the data types for
1046- * this table based on a file loaded separately.
1050+ * this table based on a file loaded separately. This will look for the
1051+ * title in column 0, and the type in column 1. Better yet, specify a
1052+ * column named "title" and another named "type" in the dictionary table
1053+ * to future-proof the code.
10471054 * @param dictionary
10481055 */
10491056 public void setColumnTypes (Table dictionary ) {
1050- setColumnTitles (dictionary .getStringColumn (0 ));
1057+ int titleCol = 0 ;
1058+ int typeCol = 1 ;
1059+ if (dictionary .hasColumnTitles ()) {
1060+ titleCol = dictionary .getColumnIndex ("title" , true );
1061+ typeCol = dictionary .getColumnIndex ("type" , true );
1062+ }
1063+ setColumnTitles (dictionary .getStringColumn (titleCol ));
10511064 if (dictionary .getColumnCount () > 1 ) {
10521065 for (int i = 0 ; i < dictionary .getRowCount (); i ++) {
1053- setColumnType (i , dictionary .getString (i , 1 ));
1066+ setColumnType (i , dictionary .getString (i , typeCol ));
10541067 }
10551068 }
10561069 }
@@ -1061,7 +1074,9 @@ public void setColumnTypes(Table dictionary) {
10611074
10621075 /**
10631076 * Remove the first row from the data set, and use it as the column titles.
1077+ * Use loadTable("table.csv", "header") instead.
10641078 */
1079+ @ Deprecated
10651080 public String [] removeTitleRow () {
10661081 String [] titles = getStringRow (0 );
10671082 removeRow (0 );
@@ -1089,6 +1104,11 @@ public void setColumnTitle(int column, String title) {
10891104 }
10901105
10911106
1107+ public boolean hasColumnTitles () {
1108+ return columnTitles != null ;
1109+ }
1110+
1111+
10921112 public String [] getColumnTitles () {
10931113 return columnTitles ;
10941114 }
0 commit comments