/** * Filter a list of tables through each matcher using a list of matchers sequentially. * * @param candidateTables The collection of tables to be filtered * @param matchers The matchers to apply, in order * * @return A set of tables which satisfy all matchers * * @throws NoMatchFoundException if no tables match the filter */ public Set<PhysicalTable> filter( Collection<PhysicalTable> candidateTables, List<PhysicalTableMatcher> matchers ) throws NoMatchFoundException { Collection<PhysicalTable> currentMatches = candidateTables; for (PhysicalTableMatcher matcher : matchers) { currentMatches = matcher.matchNotEmpty(currentMatches.stream()); } return new LinkedHashSet<>(currentMatches); }
/** * Run matches on each physical table in the stream, filtering down to matching tables. * * @param tables A stream of tables to match on * * @return Any tables which match the criteria from {@link #test(PhysicalTable)} * @throws NoMatchFoundException if no tables in the stream match */ default Set<PhysicalTable> matchNotEmpty(Stream<PhysicalTable> tables) throws NoMatchFoundException { Set<PhysicalTable> result = tables .filter(this) .collect(Collectors.toCollection(LinkedHashSet::new)); if (result.isEmpty()) { throw noneFoundException(); } return result; } }