This is one workaround I thought of.... It sort of defeats the purpose of TableRow... If anyone has a better solution or advice, please post it here....
- Table table = new Table();
- table.addColumn("id");
- table.addColumn("x");
- table.addColumn("-x");
- table.addColumn("1/x");
- for(int i = 1; i <=100; i++){
- TableRow newRow = table.addRow();
- newRow.setString("id", String.valueOf(i-1));
- newRow.setString("x", String.valueOf(i));
- newRow.setString("-x", String.valueOf(i*-1));
- newRow.setString("1/x", String.valueOf(1/i));
- }
- //saveTable(table, "data/data.csv");
- //convert to array of Table
- ArrayList<Table> tables = new ArrayList<Table>();
- for(TableRow row: table.rows()){
- Table new_table = new Table();
- new_table.setColumnTitles(table.getColumnTitles());
- new_table.addRow(row);
- tables.add(new_table);
- }
- Collections.sort(tables, new Comparator<Table>(){
- @Override public int compare(Table t1, Table t2){
- return t1.getInt(0, "-x") - t2.getInt(0,"-x");
- }
- });
- for(Table t:tables){
- println(Arrays.toString(t.getStringRow(0)));
- }