question: private List < SubTable > splitOn ( String ... columnNames ) { int columnCount = columnNames . length ; List < Column > columns = original . columns ( columnNames ) ; List < SubTable > tables = new ArrayList < > ( ) ; int [ ] columnIndices = new int [ columnCount ] ; for ( int i = 0 ; i < columnCount ; i ++ ) { columnIndices [ i ] = original . columnIndex ( columnNames [ i ] ) ; } Table empty = original . emptyCopy ( ) ; SubTable newView = new SubTable ( empty ) ; String lastKey = "" ; newView . setName ( lastKey ) ; for ( int row = 0 ; row < original . rowCount ( ) ; row ++ ) { String newKey = "" ; List < String > values = new ArrayList < > ( ) ; for ( int col = 0 ; col < columnCount ; col ++ ) { if ( col > 0 ) newKey = newKey + SPLIT_STRING ; String groupKey = original . get ( columnIndices [ col ] , row ) ; newKey = newKey + groupKey ; values . add ( groupKey ) ; } if ( ! newKey . equals ( lastKey ) ) { if ( ! newView . isEmpty ( ) ) { tables . add ( newView ) ; } newView = new SubTable ( empty ) ; newView . setName ( newKey ) ; newView . setValues ( values ) ; lastKey = newKey ; } newView . addRow ( row , original ) ; } if ( ! tables . contains ( newView ) && ! newView . isEmpty ( ) ) { if ( columnCount == 1 ) { tables . add ( newView ) ; } else { tables . add ( newView ) ; } } return tables ; }
target:  Splits the original table into sub-tables, grouping on the columns whose names are given in splitColumnNames