Skip to content

Commit

Permalink
RAT-98: fixed DocumentNameMatcher idiom misuse (#435)
Browse files Browse the repository at this point in the history
* fixed DocumentNameMatcher idiom misuse

* fixed chekstyle issue
  • Loading branch information
Claudenw authored Feb 4, 2025
1 parent c5a31fe commit ac0ebf3
Showing 1 changed file with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -303,7 +302,16 @@ public static DocumentNameMatcher matcherSet(final DocumentNameMatcher includes,
return MATCHES_ALL;
}
List<DocumentNameMatcher> workingSet = Arrays.asList(includes, excludes);
return new DocumentNameMatcher(format("matcherSet(%s)", join(workingSet)), new MatcherPredicate(workingSet));
return new DocumentNameMatcher(format("matcherSet(%s)", join(workingSet)),
new CollectionPredicateImpl(workingSet) {
@Override
public boolean test(final DocumentName documentName) {
if (includes.matches(documentName)) {
return true;
}
return !excludes.matches(documentName);
}
});
}

/**
Expand Down Expand Up @@ -466,27 +474,6 @@ public boolean test(final DocumentName documentName) {
}
}

/**
* An implementation of "or" logic across a collection of DocumentNameMatchers.
*/
// package private for testing access
static class MatcherPredicate extends CollectionPredicateImpl {
MatcherPredicate(final Iterable<DocumentNameMatcher> matchers) {
super(matchers);
}

@Override
public boolean test(final DocumentName documentName) {
Iterator<DocumentNameMatcher> iter = getMatchers().iterator();
// included
if (iter.next().matches(documentName)) {
return true;
}
// excluded
return !iter.next().matches(documentName);
}
}

/**
* Data from a {@link DocumentNameMatcher#decompose(DocumentName)} call.
*/
Expand Down

0 comments on commit ac0ebf3

Please sign in to comment.