-
Notifications
You must be signed in to change notification settings - Fork 957
make include/exclude easier to use with empty but not null arguments #8185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7d66954
c0e641d
13162bf
d159a57
4c81dc1
5035876
940a73b
65ef360
0f2f858
f7e47c4
6efcd2f
33c196b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,26 +38,28 @@ private IncludeExcludePredicate( | |||||||||||||
| @Nullable Collection<String> excluded, | ||||||||||||||
| boolean globMatchingEnabled) { | ||||||||||||||
| this.globMatchingEnabled = globMatchingEnabled; | ||||||||||||||
| this.included = included == null ? null : new LinkedHashSet<>(included); | ||||||||||||||
| this.excluded = excluded == null ? null : new LinkedHashSet<>(excluded); | ||||||||||||||
| this.included = copyIfNotEmpty(included); | ||||||||||||||
| this.excluded = copyIfNotEmpty(excluded); | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you're equating empty as the same as null. So empty = include all. In declarative config, this is impossible because IncludeExclude specified |
||||||||||||||
| if (this.included != null && this.excluded != null) { | ||||||||||||||
| this.predicate = | ||||||||||||||
| includedPredicate(this.included, globMatchingEnabled) | ||||||||||||||
| .and(excludedPredicate(this.excluded, globMatchingEnabled)); | ||||||||||||||
| } else if (this.included == null && this.excluded != null) { | ||||||||||||||
| } else if (this.excluded != null) { | ||||||||||||||
| this.predicate = excludedPredicate(this.excluded, globMatchingEnabled); | ||||||||||||||
| } else if (this.excluded == null && this.included != null) { | ||||||||||||||
| } else if (this.included != null) { | ||||||||||||||
| this.predicate = includedPredicate(this.included, globMatchingEnabled); | ||||||||||||||
| } else { | ||||||||||||||
| throw new IllegalArgumentException( | ||||||||||||||
| "At least one of includedPatterns or excludedPatterns must not be null"); | ||||||||||||||
| // include everything by default if both included and excluded are null or empt | ||||||||||||||
| this.predicate = s -> true; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Create a (case-sensitive) exact matching include exclude predicate. | ||||||||||||||
| * | ||||||||||||||
| * @throws IllegalArgumentException if {@code included} AND {@code excluded} are null. | ||||||||||||||
| * <p>When {@code included} is empty or {@literal null}, all values are included by default. | ||||||||||||||
| * | ||||||||||||||
| * <p>When {@code excluded} is empty or {@literal null}, no value is excluded by default. | ||||||||||||||
|
Comment on lines
+60
to
+62
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #nit
Suggested change
Applies below as well. |
||||||||||||||
| */ | ||||||||||||||
| public static Predicate<String> createExactMatching( | ||||||||||||||
| @Nullable Collection<String> included, @Nullable Collection<String> excluded) { | ||||||||||||||
|
|
@@ -67,9 +69,11 @@ public static Predicate<String> createExactMatching( | |||||||||||||
| /** | ||||||||||||||
| * Create a pattern matching include exclude predicate. | ||||||||||||||
| * | ||||||||||||||
| * <p>See {@link GlobUtil} for pattern matching details. | ||||||||||||||
| * <p>When {@code included} is empty or {@literal null}, all values are included by default. | ||||||||||||||
| * | ||||||||||||||
| * <p>When {@code excluded} is empty or {@literal null}, no value is excluded by default. | ||||||||||||||
| * | ||||||||||||||
| * @throws IllegalArgumentException if {@code included} AND {@code excluded} are null. | ||||||||||||||
| * <p>See {@link GlobUtil} for pattern matching details. | ||||||||||||||
| */ | ||||||||||||||
| public static Predicate<String> createPatternMatching( | ||||||||||||||
| @Nullable Collection<String> included, @Nullable Collection<String> excluded) { | ||||||||||||||
|
|
@@ -119,4 +123,9 @@ private static Predicate<String> excludedPredicate( | |||||||||||||
| } | ||||||||||||||
| return result; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| @Nullable | ||||||||||||||
| private static Set<String> copyIfNotEmpty(@Nullable Collection<String> collection) { | ||||||||||||||
| return collection == null || collection.isEmpty() ? null : new LinkedHashSet<>(collection); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,11 @@ public ViewBuilder setAggregation(Aggregation aggregation) { | |
| */ | ||
| public ViewBuilder setAttributeFilter(Set<String> keysToRetain) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [for reviewer] this is the only place where we use |
||
| Objects.requireNonNull(keysToRetain, "keysToRetain"); | ||
| if (keysToRetain.isEmpty()) { | ||
| // include/exclude predicate requires to include or exclude at least one, we have to skip it | ||
| // when we don't want to include any key. | ||
| return setAttributeFilter(s -> false); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to translate this to a predicate that has a toString implementation. |
||
| } | ||
| return setAttributeFilter(IncludeExcludePredicate.createExactMatching(keysToRetain, null)); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 ugh this was bad