TableSlice extends Relation { public void sortOn(Sort key) { Preconditions.checkArgument(!key.isEmpty()); if (key.size() == 1) { IntComparator comparator = SortUtils.getComparator(table, key); this.sortOrder = sortOn(comparator); } else { IntComparatorChain chain = SortUtils.getChain(table, key); this.sortOrder = sortOn(chain); } } TableSlice(Table table, Selection rowSelection);  TableSlice(Table table); @Override Column<?> column(int columnIndex); @Override Column<?> column(String columnName); @Override int columnCount(); @Override int rowCount(); @Override List<Column<?>> columns(); @Override int columnIndex(Column<?> column); @Override Object get(int r, int c); @Override String name(); Table getTable(); @Override void clear(); void removeSort(); void removeSelection(); @Override List<String> columnNames(); @Override TableSlice addColumns(Column<?>... column); @Override TableSlice removeColumns(Column<?>... columns); @Override Table first(int nRows); @Override TableSlice setName(String name); Table asTable(); double reduce(String numberColumnName, NumericAggregateFunction function); @Override Iterator<Row> iterator(); int mappedRowNumber(int rowNumber); void sortOn(Sort key);  }
@Test public void iterateOverRowsWithSort() { Selection selection = Selection.withRange(0, 5); TableSlice tableSlice = new TableSlice(source, selection); tableSlice.sortOn(Sort.on("approval", Order.ASCEND)); Integer[] expected = new Integer[] {52, 52, 53, 53, 58}; Integer[] actual = Streams.stream(tableSlice).map(r -> r.getInt("approval")).toArray(Integer[]::new); assertArrayEquals(expected, actual); }