Skip to content

Commit

Permalink
Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed May 2, 2023
1 parent db095a4 commit b653978
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import static java.util.Collections.singleton;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.SetMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.google.common.collect.Sets.SetView;
import com.google.common.collect.Streams;
Expand Down Expand Up @@ -215,7 +215,7 @@ ImmutableSet<T> after(T e1, T e2, T e3, T e4, T e5) {
}
}

/** Prefer {@link Sets#intersection(Set, Set)} ()} over more contrived alternatives. */
/** Prefer {@link Sets#intersection(Set, Set)} over more contrived alternatives. */
static final class SetsIntersection<T> {
@BeforeTemplate
ImmutableSet<T> before(Set<T> set1, Set<T> set2) {
Expand All @@ -228,8 +228,8 @@ ImmutableSet<T> after(Set<T> set1, Set<T> set2) {
}
}

/** Prefer {@link Sets#intersection(Set, Set)} ()} over more contrived alternatives. */
static final class MapKeySetIntersection<K, V> {
/** Prefer {@link Sets#intersection(Set, Set)} over more contrived alternatives. */
static final class SetsIntersectionMap<K, V> {
@BeforeTemplate
ImmutableSet<K> before(Set<K> set, Map<K, V> map) {
return set.stream().filter(map::containsKey).collect(toImmutableSet());
Expand All @@ -241,16 +241,16 @@ ImmutableSet<K> after(Set<K> set, Map<K, V> map) {
}
}

/** Prefer {@link Sets#intersection(Set, Set)} ()} over more contrived alternatives. */
static final class SetMultimapKeySetIntersection<K, V> {
/** Prefer {@link Sets#intersection(Set, Set)} over more contrived alternatives. */
static final class SetsIntersectionMultimap<K, V> {
@BeforeTemplate
ImmutableSet<K> before(Set<K> set, SetMultimap<K, V> setMultimap) {
return set.stream().filter(setMultimap::containsKey).collect(toImmutableSet());
ImmutableSet<K> before(Set<K> set, Multimap<K, V> multimap) {
return set.stream().filter(multimap::containsKey).collect(toImmutableSet());
}

@AfterTemplate
ImmutableSet<K> after(Set<K> set, SetMultimap<K, V> setMultimap) {
return Sets.intersection(set, setMultimap.keySet()).immutableCopy();
ImmutableSet<K> after(Set<K> set, Multimap<K, V> multimap) {
return Sets.intersection(set, multimap.keySet()).immutableCopy();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Sets;
import com.google.common.collect.Streams;
import java.util.Arrays;
Expand Down Expand Up @@ -77,18 +77,16 @@ Set<Integer> testImmutableSetOf5() {

ImmutableSet<Integer> testSetsIntersection() {
ImmutableSet<Integer> set = ImmutableSet.of(1);
return ImmutableSet.of(1, 2, 3).stream().filter(set::contains).collect(toImmutableSet());
return ImmutableSet.of(2).stream().filter(set::contains).collect(toImmutableSet());
}

ImmutableSet<Integer> testMapKeySetIntersection() {
ImmutableMap<Integer, Integer> map = ImmutableMap.of(1, 4);
return ImmutableSet.of(1, 2, 3).stream().filter(map::containsKey).collect(toImmutableSet());
ImmutableSet<Integer> testSetsIntersectionMap() {
ImmutableMap<Integer, Integer> map = ImmutableMap.of(1, 2);
return ImmutableSet.of(3).stream().filter(map::containsKey).collect(toImmutableSet());
}

ImmutableSet<Integer> testSetMultimapKeySetIntersection() {
ImmutableSetMultimap<Integer, Integer> setMultiMap = ImmutableSetMultimap.of(1, 4);
return ImmutableSet.of(1, 2, 3).stream()
.filter(setMultiMap::containsKey)
.collect(toImmutableSet());
ImmutableSet<Integer> testSetsIntersectionMultimap() {
ImmutableMultimap<Integer, Integer> multimap = ImmutableMultimap.of(1, 2);
return ImmutableSet.of(3).stream().filter(multimap::containsKey).collect(toImmutableSet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Sets;
import com.google.common.collect.Streams;
import java.util.Arrays;
Expand Down Expand Up @@ -72,16 +72,16 @@ Set<Integer> testImmutableSetOf5() {

ImmutableSet<Integer> testSetsIntersection() {
ImmutableSet<Integer> set = ImmutableSet.of(1);
return Sets.intersection(ImmutableSet.of(1, 2, 3), set).immutableCopy();
return Sets.intersection(ImmutableSet.of(2), set).immutableCopy();
}

ImmutableSet<Integer> testMapKeySetIntersection() {
ImmutableMap<Integer, Integer> map = ImmutableMap.of(1, 4);
return Sets.intersection(ImmutableSet.of(1, 2, 3), map.keySet()).immutableCopy();
ImmutableSet<Integer> testSetsIntersectionMap() {
ImmutableMap<Integer, Integer> map = ImmutableMap.of(1, 2);
return Sets.intersection(ImmutableSet.of(3), map.keySet()).immutableCopy();
}

ImmutableSet<Integer> testSetMultimapKeySetIntersection() {
ImmutableSetMultimap<Integer, Integer> setMultiMap = ImmutableSetMultimap.of(1, 4);
return Sets.intersection(ImmutableSet.of(1, 2, 3), setMultiMap.keySet()).immutableCopy();
ImmutableSet<Integer> testSetsIntersectionMultimap() {
ImmutableMultimap<Integer, Integer> multimap = ImmutableMultimap.of(1, 2);
return Sets.intersection(ImmutableSet.of(3), multimap.keySet()).immutableCopy();
}
}

0 comments on commit b653978

Please sign in to comment.