/** * Returns true iff any of the given {@code communityCandidates} is matched by this {@link * CommunitySetExpr} under the provided {@code environment}. */ public boolean matchAnyCommunity(Environment environment, Set<Long> communityCandidates) { return communityCandidates.stream() .anyMatch(communityCandidate -> matchCommunity(environment, communityCandidate)); }
/** * Returns the subset of the given {@code communityCandidates} matched by this {@link * CommunitySetExpr} under the provided {@code environment}. */ public SortedSet<Long> matchedCommunities( @Nullable Environment environment, Set<Long> communityCandidates) { return communityCandidates.stream() .filter(communityCandidate -> matchCommunity(environment, communityCandidate)) .collect(ImmutableSortedSet.toImmutableSortedSet(Comparator.naturalOrder())); }
/** Check if any line matches given community */ private boolean computeIfMatches(long community, @Nullable Environment environment) { Optional<CommunityListLine> matchingLine = _lines.stream() .filter(line -> line.getMatchCondition().matchCommunity(environment, community)) .findFirst(); // "invert != condition" is a concise way of inverting a boolean return matchingLine.isPresent() && _invertMatch != (matchingLine.get().getAction() == LineAction.PERMIT); }
@Override protected boolean matchesSafely(CommunitySetExpr item, Description mismatchDescription) { boolean match = item.matchCommunity(_environment, _community); if (!match) { mismatchDescription.appendText( String.format( "CommunitySetExpr: '%s' did not match the community: '%s'", item, longToCommunity(_community))); return false; } return true; } }