-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Use collections conveniences in static initializers #41374
Changes from 1 commit
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 |
---|---|---|
|
@@ -99,7 +99,11 @@ public static <T> Set<T> difference(Set<T> left, Set<T> right) { | |
public static <T> SortedSet<T> sortedDifference(Set<T> left, Set<T> right) { | ||
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. Not directly related to you change, but I'm seeing some inconsistencies wrt whether the return value of this method is assumed mutable. 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. I pushed e9dd166. |
||
Objects.requireNonNull(left); | ||
Objects.requireNonNull(right); | ||
return left.stream().filter(k -> !right.contains(k)).collect(new SortedSetCollector<>()); | ||
return left.stream().filter(k -> !right.contains(k)).collect(toSortedSet()); | ||
} | ||
|
||
public static <T> Collector<T, SortedSet<T>, SortedSet<T>> toSortedSet() { | ||
return new SortedSetCollector<>(); | ||
} | ||
|
||
private static class SortedSetCollector<T> implements Collector<T, SortedSet<T>, SortedSet<T>> { | ||
|
@@ -111,7 +115,7 @@ public Supplier<SortedSet<T>> supplier() { | |
|
||
@Override | ||
public BiConsumer<SortedSet<T>, T> accumulator() { | ||
return (s, e) -> s.add(e); | ||
return SortedSet::add; | ||
} | ||
|
||
@Override | ||
|
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.
I think this is creating more problems than it helps?
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.
I pushed 3cad419. My IDE was throwing a warning at me that the map lookup was suspicious because
queryClass
might not beClass<? extends Query>
but I think that 3cad419 is a better way to ensure this and remove the IDE warning.