/** * Remove the rows whose column value is distinct to the value * * @param list DataList to filter * @param column column to check * @param value value to check */ public static void filter(DataList list, String column, String value) { List<Map<String, CellData>> newRows = new ArrayList<>(); for (Map<String, CellData> row : list.getRows()) { if (row.containsKey(column)) { CellData cell = row.get(column); if (cell.getStringValue().equalsIgnoreCase(value)) { newRows.add(row); } } } // Set the new list list.setRows(newRows); }
/** * Keeps only distinct values of given fields * * @param list DataList * @param sortColumns Sort by field list */ public static void distinct(DataList list, List<SortColumn> sortColumns) { CompareRow comparator = new CompareRow(sortColumns); List<Map<String, CellData>> newRows = new ArrayList<>(); for (Map<String, CellData> row: list.getRows()) { if (!in(newRows, row, comparator)) { newRows.add((Map<String, CellData>) ((HashMap<String, CellData>) row).clone()); } } // Set rows and records list.setRows(newRows); list.setRecords((long) list.getRows().size()); }
/** * Get a copy of dataList object * * @param original DataList * @return DataList copy */ public static DataList copyDataList(DataList original) { DataList copy = new DataList(); copy.setTotal(original.getTotal()); copy.setPage(original.getPage()); copy.setRecords(original.getRecords()); copy.setRows((List<Map<String, CellData>>) ((ArrayList<Map<String, CellData>>) original.getRows()).clone()); return copy; }
dataList.setRows(rows); dataList.setRecords(rows.size());