From 0f6549a7db0ebe67d8a008fd5bd9948c2470d887 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Mon, 11 Apr 2022 15:36:35 +0200 Subject: [PATCH] Statically import some methods from `Collections` --- .../refastertemplates/AssortedTemplates.java | 13 +++++++------ .../refastertemplates/ImmutableListTemplates.java | 4 ++-- .../refastertemplates/ImmutableMapTemplates.java | 5 ++--- .../refastertemplates/ImmutableSetTemplates.java | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssortedTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssortedTemplates.java index ffd4ad32376..81169772e58 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssortedTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssortedTemplates.java @@ -4,6 +4,7 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.common.collect.Sets.toImmutableEnumSet; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; +import static java.util.Collections.disjoint; import static java.util.Objects.checkIndex; import com.google.common.base.Splitter; @@ -162,7 +163,7 @@ boolean before2(Set set1, Set set2) { @AfterTemplate boolean after(Set set1, Set set2) { - return Collections.disjoint(set1, set2); + return disjoint(set1, set2); } } @@ -177,15 +178,15 @@ static final class DisjointCollections { @BeforeTemplate boolean before(Collection collection1, Collection collection2) { return Refaster.anyOf( - Collections.disjoint(ImmutableSet.copyOf(collection1), collection2), - Collections.disjoint(new HashSet<>(collection1), collection2), - Collections.disjoint(collection1, ImmutableSet.copyOf(collection2)), - Collections.disjoint(collection1, new HashSet<>(collection2))); + disjoint(ImmutableSet.copyOf(collection1), collection2), + disjoint(new HashSet<>(collection1), collection2), + disjoint(collection1, ImmutableSet.copyOf(collection2)), + disjoint(collection1, new HashSet<>(collection2))); } @AfterTemplate boolean after(Collection collection1, Collection collection2) { - return Collections.disjoint(collection1, collection2); + return disjoint(collection1, collection2); } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListTemplates.java index a7aaf0c3165..dc23195068d 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListTemplates.java @@ -3,6 +3,7 @@ import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; +import static java.util.Collections.singletonList; import static java.util.Comparator.naturalOrder; import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toList; @@ -16,7 +17,6 @@ import com.google.errorprone.refaster.annotation.UseImportPolicy; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; @@ -63,7 +63,7 @@ ImmutableList after() { static final class SingletonImmutableList { @BeforeTemplate List before(T element) { - return Collections.singletonList(element); + return singletonList(element); } @AfterTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplates.java index 5c8aa28142f..03e10ba96c6 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplates.java @@ -2,6 +2,7 @@ import static com.google.common.collect.ImmutableMap.toImmutableMap; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; +import static java.util.Collections.singletonMap; import static java.util.function.Function.identity; import com.google.common.collect.ImmutableMap; @@ -14,7 +15,6 @@ import com.google.errorprone.refaster.annotation.Placeholder; import com.google.errorprone.refaster.annotation.UseImportPolicy; import java.util.Collection; -import java.util.Collections; import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -65,8 +65,7 @@ static final class PairToImmutableMap { @BeforeTemplate Map before(K key, V value) { return Refaster.anyOf( - ImmutableMap.builder().put(key, value).build(), - Collections.singletonMap(key, value)); + ImmutableMap.builder().put(key, value).build(), singletonMap(key, value)); } @AfterTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplates.java index 7e19377eaa0..cabcb8ea1c6 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplates.java @@ -2,6 +2,7 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; +import static java.util.Collections.singleton; import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toSet; @@ -15,7 +16,6 @@ import com.google.errorprone.refaster.annotation.UseImportPolicy; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Iterator; import java.util.Set; import java.util.stream.Stream; @@ -61,7 +61,7 @@ ImmutableSet after() { static final class SingletonImmutableSet { @BeforeTemplate Set before(T element) { - return Collections.singleton(element); + return singleton(element); } @AfterTemplate