Tables { public Stream<List<TableCell>> getFilteredRows() { return nodes.stream() .flatMap( table -> { List<Nodes<Structure>> columns = columnPatterns.stream() .map(p -> nodes.select("TableHeader TableCell:matches(" + p.pattern() + ")")) .map(p -> p.get(0)) .map(Node::getSiblingIndex) .map( i -> nodes.select( "TableBody > TableRow > TableCell:nth-child(" + (i + 1) + ")")) .collect(Collectors.toList()); if (columns.isEmpty()) { return Stream.empty(); } int numItems = columns.get(0).size(); for (int i = 1; i < columns.size(); i++) { if (columns.get(i).size() != numItems) { return Stream.empty(); } } List<List<TableCell>> result = new ArrayList<>(); for (int i = 0; i < numItems; i++) { List<TableCell> row = new ArrayList<>(columns.size()); for (Nodes<Structure> column : columns) { row.add((TableCell) column.get(i).getItem()); } result.add(row); } return result.stream(); }); } Tables(JCas jCas); Tables withColumn(String p); Tables withColumn(Pattern p); Stream<List<TableCell>> getFilteredRows(); Stream<TableCell> getFilteredCells(); Stream<Table> getTables(); Stream<List<TableCell>> getRows(); Stream<TableCell> getCells();  }
@Test public void testGetFilteredRows() throws Exception { assertEquals(2, tables.withColumn("Name").withColumn("(?i)email").getRows().count()); }