This is an automated email from the ASF dual-hosted git repository.
claude pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/creadur-rat.git
The following commit(s) were added to refs/heads/master by this push:
new ac0ebf3c RAT-98: fixed DocumentNameMatcher idiom misuse (#435)
ac0ebf3c is described below
commit ac0ebf3cc86d2a8d240d89b8053214ae13ec5b9b
Author: Claude Warren <[email protected]>
AuthorDate: Tue Feb 4 01:26:41 2025 +0100
RAT-98: fixed DocumentNameMatcher idiom misuse (#435)
* fixed DocumentNameMatcher idiom misuse
* fixed chekstyle issue
---
.../apache/rat/document/DocumentNameMatcher.java | 33 +++++++---------------
1 file changed, 10 insertions(+), 23 deletions(-)
diff --git
a/apache-rat-core/src/main/java/org/apache/rat/document/DocumentNameMatcher.java
b/apache-rat-core/src/main/java/org/apache/rat/document/DocumentNameMatcher.java
index 6b3c31bd..5082c1a2 100644
---
a/apache-rat-core/src/main/java/org/apache/rat/document/DocumentNameMatcher.java
+++
b/apache-rat-core/src/main/java/org/apache/rat/document/DocumentNameMatcher.java
@@ -23,7 +23,6 @@ import java.io.FileFilter;
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;
@@ -303,7 +302,16 @@ public final class DocumentNameMatcher {
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);
+ }
+ });
}
/**
@@ -466,27 +474,6 @@ public final class DocumentNameMatcher {
}
}
- /**
- * 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.
*/