Skip to content

Commit

Permalink
Suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed May 2, 2023
1 parent 748a086 commit 5b65230
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,17 @@ ImmutableSet<T> after(Set<T> set, Multimap<K, V> multimap) {
return Sets.intersection(set, multimap.keySet()).immutableCopy();
}
}

/** Prefer an immutable copy of {@link Sets#union(Set, Set)} over more contrived alternatives. */
static final class SetsUnion<S, T extends S, U extends S> {
@BeforeTemplate
ImmutableSet<S> before(Set<T> set1, Set<U> set2) {
return Stream.concat(set1.stream(), set2.stream()).collect(toImmutableSet());
}

@AfterTemplate
ImmutableSet<S> after(Set<T> set1, Set<U> set2) {
return Sets.union(set1, set2).immutableCopy();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,9 @@ ImmutableSet<Integer> testSetsIntersectionMultimap() {
.filter(ImmutableSetMultimap.of(2, 3)::containsKey)
.collect(toImmutableSet());
}

ImmutableSet<Integer> testSetsUnion() {
return Stream.concat(ImmutableSet.of(1).stream(), ImmutableSet.of(2).stream())
.collect(toImmutableSet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,8 @@ ImmutableSet<Integer> testSetsIntersectionMultimap() {
return Sets.intersection(ImmutableSet.of(1), ImmutableSetMultimap.of(2, 3).keySet())
.immutableCopy();
}

ImmutableSet<Integer> testSetsUnion() {
return Sets.union(ImmutableSet.of(1), ImmutableSet.of(2)).immutableCopy();
}
}

0 comments on commit 5b65230

Please sign in to comment.