diff --git a/android/guava-testlib/src/com/google/common/testing/ArbitraryInstances.java b/android/guava-testlib/src/com/google/common/testing/ArbitraryInstances.java index ac8630362313..1175597fd49b 100644 --- a/android/guava-testlib/src/com/google/common/testing/ArbitraryInstances.java +++ b/android/guava-testlib/src/com/google/common/testing/ArbitraryInstances.java @@ -18,6 +18,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.Iterators.peekingIterator; +import static com.google.common.collect.Maps.unmodifiableNavigableMap; +import static com.google.common.collect.Sets.newTreeSet; import static com.google.common.collect.Sets.unmodifiableNavigableSet; import static com.google.common.collect.Tables.unmodifiableRowSortedTable; import static java.nio.charset.StandardCharsets.UTF_8; @@ -63,7 +65,6 @@ import com.google.common.collect.Range; import com.google.common.collect.RowSortedTable; import com.google.common.collect.SetMultimap; -import com.google.common.collect.Sets; import com.google.common.collect.SortedMapDifference; import com.google.common.collect.SortedMultiset; import com.google.common.collect.SortedSetMultimap; @@ -254,12 +255,12 @@ private static MatchResult createMatchResult() { .put(ImmutableSet.class, ImmutableSet.of()) .put(SortedSet.class, ImmutableSortedSet.of()) .put(ImmutableSortedSet.class, ImmutableSortedSet.of()) - .put(NavigableSet.class, unmodifiableNavigableSet(Sets.newTreeSet())) + .put(NavigableSet.class, unmodifiableNavigableSet(newTreeSet())) .put(Map.class, ImmutableMap.of()) .put(ImmutableMap.class, ImmutableMap.of()) .put(SortedMap.class, ImmutableSortedMap.of()) .put(ImmutableSortedMap.class, ImmutableSortedMap.of()) - .put(NavigableMap.class, Maps.unmodifiableNavigableMap(Maps.newTreeMap())) + .put(NavigableMap.class, unmodifiableNavigableMap(Maps.newTreeMap())) .put(Multimap.class, ImmutableMultimap.of()) .put(ImmutableMultimap.class, ImmutableMultimap.of()) .put(ListMultimap.class, ImmutableListMultimap.of()) diff --git a/android/guava-testlib/src/com/google/common/testing/ClassSanityTester.java b/android/guava-testlib/src/com/google/common/testing/ClassSanityTester.java index f6c5d23a4f02..5a3b0c8e7fc0 100644 --- a/android/guava-testlib/src/com/google/common/testing/ClassSanityTester.java +++ b/android/guava-testlib/src/com/google/common/testing/ClassSanityTester.java @@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Throwables.throwIfUnchecked; +import static com.google.common.collect.Lists.newArrayListWithCapacity; import static com.google.common.testing.NullPointerTester.isNullable; import static com.google.common.testing.SerializableTester.reserialize; import static com.google.common.testing.SerializableTester.reserializeAndAssert; @@ -578,8 +579,8 @@ private void testEqualsUsing(Invokable factory) InvocationTargetException, FactoryMethodReturnsNullException { List params = factory.getParameters(); - List argGenerators = Lists.newArrayListWithCapacity(params.size()); - List<@Nullable Object> args = Lists.newArrayListWithCapacity(params.size()); + List argGenerators = newArrayListWithCapacity(params.size()); + List<@Nullable Object> args = newArrayListWithCapacity(params.size()); for (Parameter param : params) { FreshValueGenerator generator = newFreshValueGenerator(); argGenerators.add(generator); diff --git a/android/guava-testlib/src/com/google/common/testing/EqualsTester.java b/android/guava-testlib/src/com/google/common/testing/EqualsTester.java index 531d7453f095..729a9a242000 100644 --- a/android/guava-testlib/src/com/google/common/testing/EqualsTester.java +++ b/android/guava-testlib/src/com/google/common/testing/EqualsTester.java @@ -17,12 +17,12 @@ package com.google.common.testing; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.concat; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import com.google.common.annotations.GwtCompatible; import com.google.common.base.Equivalence; -import com.google.common.collect.Iterables; import com.google.common.testing.RelationshipTester.Item; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.ArrayList; @@ -139,7 +139,7 @@ public EqualsTester testEquals() { } private void testItems() { - for (Object item : Iterables.concat(equalityGroups)) { + for (Object item : concat(equalityGroups)) { assertTrue(item + " must not be Object#equals to null", !item.equals(null)); assertTrue( item + " must not be Object#equals to an arbitrary object of another class", diff --git a/android/guava-testlib/src/com/google/common/testing/FreshValueGenerator.java b/android/guava-testlib/src/com/google/common/testing/FreshValueGenerator.java index c27ca43c326c..3f5e65d05960 100644 --- a/android/guava-testlib/src/com/google/common/testing/FreshValueGenerator.java +++ b/android/guava-testlib/src/com/google/common/testing/FreshValueGenerator.java @@ -18,6 +18,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Throwables.throwIfUnchecked; +import static com.google.common.collect.Lists.newArrayListWithCapacity; +import static com.google.common.collect.Sets.newTreeSet; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.asList; import static java.util.Objects.requireNonNull; @@ -52,7 +54,6 @@ import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.LinkedHashMultiset; import com.google.common.collect.ListMultimap; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.collect.Multiset; @@ -60,7 +61,6 @@ import com.google.common.collect.Range; import com.google.common.collect.RowSortedTable; import com.google.common.collect.SetMultimap; -import com.google.common.collect.Sets; import com.google.common.collect.SortedMultiset; import com.google.common.collect.Table; import com.google.common.collect.TreeBasedTable; @@ -239,7 +239,7 @@ final T newFreshProxy(Class interfaceType) { Method generate = GENERATORS.get(rawType); if (generate != null) { ImmutableList params = Invokable.from(generate).getParameters(); - List args = Lists.newArrayListWithCapacity(params.size()); + List args = newArrayListWithCapacity(params.size()); TypeVariable[] typeVars = rawType.getTypeParameters(); for (int i = 0; i < params.size(); i++) { TypeToken paramType = type.resolveType(typeVars[i]); @@ -703,7 +703,7 @@ static > NavigableSet generateNavigableSet(E @Generates static > TreeSet generateTreeSet(E freshElement) { - TreeSet set = Sets.newTreeSet(); + TreeSet set = newTreeSet(); set.add(freshElement); return set; } diff --git a/android/guava-testlib/test/com/google/common/collect/testing/SafeTreeSetTest.java b/android/guava-testlib/test/com/google/common/collect/testing/SafeTreeSetTest.java index 3cedfc02780e..6b6b0525ba11 100644 --- a/android/guava-testlib/test/com/google/common/collect/testing/SafeTreeSetTest.java +++ b/android/guava-testlib/test/com/google/common/collect/testing/SafeTreeSetTest.java @@ -16,6 +16,7 @@ package com.google.common.collect.testing; +import static com.google.common.collect.Sets.newTreeSet; import static com.google.common.testing.SerializableTester.reserialize; import static com.google.common.testing.SerializableTester.reserializeAndAssert; import static java.util.Arrays.asList; @@ -23,7 +24,6 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Ordering; -import com.google.common.collect.Sets; import com.google.common.collect.testing.features.CollectionFeature; import com.google.common.collect.testing.features.CollectionSize; import java.util.ArrayList; @@ -52,7 +52,7 @@ protected Set create(String[] elements) { @Override public List order(List insertionOrder) { - return new ArrayList<>(Sets.newTreeSet(insertionOrder)); + return new ArrayList<>(newTreeSet(insertionOrder)); } }) .withFeatures( @@ -73,7 +73,7 @@ protected Set create(String[] elements) { @Override public List order(List insertionOrder) { - return new ArrayList<>(Sets.newTreeSet(insertionOrder)); + return new ArrayList<>(newTreeSet(insertionOrder)); } }) .withFeatures( diff --git a/android/guava-tests/test/com/google/common/base/CharMatcherTest.java b/android/guava-tests/test/com/google/common/base/CharMatcherTest.java index 13087d8e10e9..a744c0bdf861 100644 --- a/android/guava-tests/test/com/google/common/base/CharMatcherTest.java +++ b/android/guava-tests/test/com/google/common/base/CharMatcherTest.java @@ -25,6 +25,7 @@ import static com.google.common.base.CharMatcher.noneOf; import static com.google.common.base.CharMatcher.whitespace; import static com.google.common.base.Predicates.equalTo; +import static com.google.common.base.Strings.repeat; import static com.google.common.truth.Truth.assertThat; import static java.util.Arrays.sort; import static org.junit.Assert.assertThrows; @@ -293,8 +294,8 @@ private void reallyTestAllMatches(CharMatcher matcher, CharSequence s) { assertTrue(matcher.matchesAllOf(s)); assertFalse(matcher.matchesNoneOf(s)); assertThat(matcher.removeFrom(s)).isEqualTo(""); - assertThat(matcher.replaceFrom(s, 'z')).isEqualTo(Strings.repeat("z", s.length())); - assertThat(matcher.replaceFrom(s, "ZZ")).isEqualTo(Strings.repeat("ZZ", s.length())); + assertThat(matcher.replaceFrom(s, 'z')).isEqualTo(repeat("z", s.length())); + assertThat(matcher.replaceFrom(s, "ZZ")).isEqualTo(repeat("ZZ", s.length())); assertThat(matcher.trimFrom(s)).isEqualTo(""); assertEquals(s.length(), matcher.countIn(s)); } diff --git a/android/guava-tests/test/com/google/common/base/PredicatesTest.java b/android/guava-tests/test/com/google/common/base/PredicatesTest.java index 5818057aaaec..3a0daccda39e 100644 --- a/android/guava-tests/test/com/google/common/base/PredicatesTest.java +++ b/android/guava-tests/test/com/google/common/base/PredicatesTest.java @@ -17,8 +17,12 @@ package com.google.common.base; import static com.google.common.base.CharMatcher.whitespace; +import static com.google.common.base.Predicates.and; import static com.google.common.base.Predicates.equalTo; +import static com.google.common.base.Predicates.instanceOf; import static com.google.common.base.Predicates.not; +import static com.google.common.base.Predicates.notNull; +import static com.google.common.base.Predicates.or; import static com.google.common.testing.SerializableTester.reserializeAndAssert; import static com.google.common.truth.Truth.assertThat; import static java.util.Arrays.asList; @@ -170,14 +174,14 @@ public void testNot_equalityForNotOfKnownValues() { new EqualsTester() .addEqualityGroup(Predicates.isNull(), Predicates.isNull()) - .addEqualityGroup(Predicates.notNull()) + .addEqualityGroup(notNull()) .addEqualityGroup(not(Predicates.isNull())) .testEquals(); new EqualsTester() - .addEqualityGroup(Predicates.notNull(), Predicates.notNull()) + .addEqualityGroup(notNull(), notNull()) .addEqualityGroup(Predicates.isNull()) - .addEqualityGroup(not(Predicates.notNull())) + .addEqualityGroup(not(notNull())) .testEquals(); } @@ -192,118 +196,116 @@ public void testNot_serialization() { */ public void testAnd_applyNoArgs() { - assertEvalsToTrue(Predicates.and()); + assertEvalsToTrue(and()); } public void testAnd_equalityNoArgs() { new EqualsTester() - .addEqualityGroup(Predicates.and(), Predicates.and()) - .addEqualityGroup(Predicates.and(FALSE)) - .addEqualityGroup(Predicates.or()) + .addEqualityGroup(and(), and()) + .addEqualityGroup(and(FALSE)) + .addEqualityGroup(or()) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testAnd_serializationNoArgs() { - checkSerialization(Predicates.and()); + checkSerialization(and()); } public void testAnd_applyOneArg() { - assertEvalsLikeOdd(Predicates.and(isOdd())); + assertEvalsLikeOdd(and(isOdd())); } public void testAnd_equalityOneArg() { - Object[] notEqualObjects = {Predicates.and(NEVER_REACHED, FALSE)}; + Object[] notEqualObjects = {and(NEVER_REACHED, FALSE)}; new EqualsTester() - .addEqualityGroup(Predicates.and(NEVER_REACHED), Predicates.and(NEVER_REACHED)) + .addEqualityGroup(and(NEVER_REACHED), and(NEVER_REACHED)) .addEqualityGroup(notEqualObjects) - .addEqualityGroup(Predicates.and(isOdd())) - .addEqualityGroup(Predicates.and()) - .addEqualityGroup(Predicates.or(NEVER_REACHED)) + .addEqualityGroup(and(isOdd())) + .addEqualityGroup(and()) + .addEqualityGroup(or(NEVER_REACHED)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testAnd_serializationOneArg() { - checkSerialization(Predicates.and(isOdd())); + checkSerialization(and(isOdd())); } public void testAnd_applyBinary() { - assertEvalsLikeOdd(Predicates.and(isOdd(), TRUE)); - assertEvalsLikeOdd(Predicates.and(TRUE, isOdd())); - assertEvalsToFalse(Predicates.and(FALSE, NEVER_REACHED)); + assertEvalsLikeOdd(and(isOdd(), TRUE)); + assertEvalsLikeOdd(and(TRUE, isOdd())); + assertEvalsToFalse(and(FALSE, NEVER_REACHED)); } public void testAnd_equalityBinary() { new EqualsTester() - .addEqualityGroup(Predicates.and(TRUE, NEVER_REACHED), Predicates.and(TRUE, NEVER_REACHED)) - .addEqualityGroup(Predicates.and(NEVER_REACHED, TRUE)) - .addEqualityGroup(Predicates.and(TRUE)) - .addEqualityGroup(Predicates.or(TRUE, NEVER_REACHED)) + .addEqualityGroup(and(TRUE, NEVER_REACHED), and(TRUE, NEVER_REACHED)) + .addEqualityGroup(and(NEVER_REACHED, TRUE)) + .addEqualityGroup(and(TRUE)) + .addEqualityGroup(or(TRUE, NEVER_REACHED)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testAnd_serializationBinary() { - checkSerialization(Predicates.and(TRUE, isOdd())); + checkSerialization(and(TRUE, isOdd())); } public void testAnd_applyTernary() { - assertEvalsLikeOdd(Predicates.and(isOdd(), TRUE, TRUE)); - assertEvalsLikeOdd(Predicates.and(TRUE, isOdd(), TRUE)); - assertEvalsLikeOdd(Predicates.and(TRUE, TRUE, isOdd())); - assertEvalsToFalse(Predicates.and(TRUE, FALSE, NEVER_REACHED)); + assertEvalsLikeOdd(and(isOdd(), TRUE, TRUE)); + assertEvalsLikeOdd(and(TRUE, isOdd(), TRUE)); + assertEvalsLikeOdd(and(TRUE, TRUE, isOdd())); + assertEvalsToFalse(and(TRUE, FALSE, NEVER_REACHED)); } public void testAnd_equalityTernary() { new EqualsTester() - .addEqualityGroup( - Predicates.and(TRUE, isOdd(), NEVER_REACHED), - Predicates.and(TRUE, isOdd(), NEVER_REACHED)) - .addEqualityGroup(Predicates.and(isOdd(), NEVER_REACHED, TRUE)) - .addEqualityGroup(Predicates.and(TRUE)) - .addEqualityGroup(Predicates.or(TRUE, isOdd(), NEVER_REACHED)) + .addEqualityGroup(and(TRUE, isOdd(), NEVER_REACHED), and(TRUE, isOdd(), NEVER_REACHED)) + .addEqualityGroup(and(isOdd(), NEVER_REACHED, TRUE)) + .addEqualityGroup(and(TRUE)) + .addEqualityGroup(or(TRUE, isOdd(), NEVER_REACHED)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testAnd_serializationTernary() { - checkSerialization(Predicates.and(TRUE, isOdd(), FALSE)); + checkSerialization(and(TRUE, isOdd(), FALSE)); } public void testAnd_applyIterable() { Collection> empty = asList(); - assertEvalsToTrue(Predicates.and(empty)); - assertEvalsLikeOdd(Predicates.and(asList(isOdd()))); - assertEvalsLikeOdd(Predicates.and(asList(TRUE, isOdd()))); - assertEvalsToFalse(Predicates.and(asList(FALSE, NEVER_REACHED))); + assertEvalsToTrue(and(empty)); + assertEvalsLikeOdd(and(asList(isOdd()))); + assertEvalsLikeOdd(and(asList(TRUE, isOdd()))); + assertEvalsToFalse(and(asList(FALSE, NEVER_REACHED))); } public void testAnd_equalityIterable() { new EqualsTester() .addEqualityGroup( - Predicates.and(asList(TRUE, NEVER_REACHED)), - Predicates.and(asList(TRUE, NEVER_REACHED)), - Predicates.and(TRUE, NEVER_REACHED)) - .addEqualityGroup(Predicates.and(FALSE, NEVER_REACHED)) - .addEqualityGroup(Predicates.or(TRUE, NEVER_REACHED)) + and(asList(TRUE, NEVER_REACHED)), + and(asList(TRUE, NEVER_REACHED)), + and(TRUE, NEVER_REACHED)) + .addEqualityGroup(and(FALSE, NEVER_REACHED)) + .addEqualityGroup(or(TRUE, NEVER_REACHED)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testAnd_serializationIterable() { - checkSerialization(Predicates.and(asList(TRUE, FALSE))); + checkSerialization(and(asList(TRUE, FALSE))); } public void testAnd_arrayDefensivelyCopied() { @SuppressWarnings("unchecked") // generic arrays Predicate[] array = (Predicate[]) new Predicate[] {Predicates.alwaysFalse()}; - Predicate predicate = Predicates.and(array); + Predicate predicate = and(array); assertFalse(predicate.apply(1)); array[0] = Predicates.alwaysTrue(); assertFalse(predicate.apply(1)); @@ -311,7 +313,7 @@ public void testAnd_arrayDefensivelyCopied() { public void testAnd_listDefensivelyCopied() { List> list = new ArrayList<>(); - Predicate predicate = Predicates.and(list); + Predicate predicate = and(list); assertTrue(predicate.apply(1)); list.add(Predicates.alwaysFalse()); assertTrue(predicate.apply(1)); @@ -326,7 +328,7 @@ public Iterator> iterator() { return list.iterator(); } }; - Predicate predicate = Predicates.and(iterable); + Predicate predicate = and(iterable); assertTrue(predicate.apply(1)); list.add(Predicates.alwaysFalse()); assertTrue(predicate.apply(1)); @@ -337,48 +339,48 @@ public Iterator> iterator() { */ public void testOr_applyNoArgs() { - assertEvalsToFalse(Predicates.or()); + assertEvalsToFalse(or()); } public void testOr_equalityNoArgs() { new EqualsTester() - .addEqualityGroup(Predicates.or(), Predicates.or()) - .addEqualityGroup(Predicates.or(TRUE)) - .addEqualityGroup(Predicates.and()) + .addEqualityGroup(or(), or()) + .addEqualityGroup(or(TRUE)) + .addEqualityGroup(and()) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testOr_serializationNoArgs() { - checkSerialization(Predicates.or()); + checkSerialization(or()); } public void testOr_applyOneArg() { - assertEvalsToTrue(Predicates.or(TRUE)); - assertEvalsToFalse(Predicates.or(FALSE)); + assertEvalsToTrue(or(TRUE)); + assertEvalsToFalse(or(FALSE)); } public void testOr_equalityOneArg() { new EqualsTester() - .addEqualityGroup(Predicates.or(NEVER_REACHED), Predicates.or(NEVER_REACHED)) - .addEqualityGroup(Predicates.or(NEVER_REACHED, TRUE)) - .addEqualityGroup(Predicates.or(TRUE)) - .addEqualityGroup(Predicates.or()) - .addEqualityGroup(Predicates.and(NEVER_REACHED)) + .addEqualityGroup(or(NEVER_REACHED), or(NEVER_REACHED)) + .addEqualityGroup(or(NEVER_REACHED, TRUE)) + .addEqualityGroup(or(TRUE)) + .addEqualityGroup(or()) + .addEqualityGroup(and(NEVER_REACHED)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testOr_serializationOneArg() { - checkSerialization(Predicates.or(isOdd())); + checkSerialization(or(isOdd())); } public void testOr_applyBinary() { - Predicate<@Nullable Integer> falseOrFalse = Predicates.or(FALSE, FALSE); - Predicate<@Nullable Integer> falseOrTrue = Predicates.or(FALSE, TRUE); - Predicate<@Nullable Integer> trueOrAnything = Predicates.or(TRUE, NEVER_REACHED); + Predicate<@Nullable Integer> falseOrFalse = or(FALSE, FALSE); + Predicate<@Nullable Integer> falseOrTrue = or(FALSE, TRUE); + Predicate<@Nullable Integer> trueOrAnything = or(TRUE, NEVER_REACHED); assertEvalsToFalse(falseOrFalse); assertEvalsToTrue(falseOrTrue); @@ -387,46 +389,45 @@ public void testOr_applyBinary() { public void testOr_equalityBinary() { new EqualsTester() - .addEqualityGroup(Predicates.or(FALSE, NEVER_REACHED), Predicates.or(FALSE, NEVER_REACHED)) - .addEqualityGroup(Predicates.or(NEVER_REACHED, FALSE)) - .addEqualityGroup(Predicates.or(TRUE)) - .addEqualityGroup(Predicates.and(FALSE, NEVER_REACHED)) + .addEqualityGroup(or(FALSE, NEVER_REACHED), or(FALSE, NEVER_REACHED)) + .addEqualityGroup(or(NEVER_REACHED, FALSE)) + .addEqualityGroup(or(TRUE)) + .addEqualityGroup(and(FALSE, NEVER_REACHED)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testOr_serializationBinary() { - checkSerialization(Predicates.or(isOdd(), TRUE)); + checkSerialization(or(isOdd(), TRUE)); } public void testOr_applyTernary() { - assertEvalsLikeOdd(Predicates.or(isOdd(), FALSE, FALSE)); - assertEvalsLikeOdd(Predicates.or(FALSE, isOdd(), FALSE)); - assertEvalsLikeOdd(Predicates.or(FALSE, FALSE, isOdd())); - assertEvalsToTrue(Predicates.or(FALSE, TRUE, NEVER_REACHED)); + assertEvalsLikeOdd(or(isOdd(), FALSE, FALSE)); + assertEvalsLikeOdd(or(FALSE, isOdd(), FALSE)); + assertEvalsLikeOdd(or(FALSE, FALSE, isOdd())); + assertEvalsToTrue(or(FALSE, TRUE, NEVER_REACHED)); } public void testOr_equalityTernary() { new EqualsTester() - .addEqualityGroup( - Predicates.or(FALSE, NEVER_REACHED, TRUE), Predicates.or(FALSE, NEVER_REACHED, TRUE)) - .addEqualityGroup(Predicates.or(TRUE, NEVER_REACHED, FALSE)) - .addEqualityGroup(Predicates.or(TRUE)) - .addEqualityGroup(Predicates.and(FALSE, NEVER_REACHED, TRUE)) + .addEqualityGroup(or(FALSE, NEVER_REACHED, TRUE), or(FALSE, NEVER_REACHED, TRUE)) + .addEqualityGroup(or(TRUE, NEVER_REACHED, FALSE)) + .addEqualityGroup(or(TRUE)) + .addEqualityGroup(and(FALSE, NEVER_REACHED, TRUE)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testOr_serializationTernary() { - checkSerialization(Predicates.or(FALSE, isOdd(), TRUE)); + checkSerialization(or(FALSE, isOdd(), TRUE)); } public void testOr_applyIterable() { - Predicate<@Nullable Integer> vacuouslyFalse = Predicates.or(ImmutableList.of()); - Predicate<@Nullable Integer> troo = Predicates.or(ImmutableList.of(TRUE)); - Predicate<@Nullable Integer> trueAndFalse = Predicates.or(ImmutableList.of(TRUE, FALSE)); + Predicate<@Nullable Integer> vacuouslyFalse = or(ImmutableList.of()); + Predicate<@Nullable Integer> troo = or(ImmutableList.of(TRUE)); + Predicate<@Nullable Integer> trueAndFalse = or(ImmutableList.of(TRUE, FALSE)); assertEvalsToFalse(vacuouslyFalse); assertEvalsToTrue(troo); @@ -436,18 +437,18 @@ public void testOr_applyIterable() { public void testOr_equalityIterable() { new EqualsTester() .addEqualityGroup( - Predicates.or(asList(FALSE, NEVER_REACHED)), - Predicates.or(asList(FALSE, NEVER_REACHED)), - Predicates.or(FALSE, NEVER_REACHED)) - .addEqualityGroup(Predicates.or(TRUE, NEVER_REACHED)) - .addEqualityGroup(Predicates.and(FALSE, NEVER_REACHED)) + or(asList(FALSE, NEVER_REACHED)), + or(asList(FALSE, NEVER_REACHED)), + or(FALSE, NEVER_REACHED)) + .addEqualityGroup(or(TRUE, NEVER_REACHED)) + .addEqualityGroup(and(FALSE, NEVER_REACHED)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testOr_serializationIterable() { - Predicate pre = Predicates.or(asList(TRUE, FALSE)); + Predicate pre = or(asList(TRUE, FALSE)); Predicate post = reserializeAndAssert(pre); assertEquals(pre.apply(0), post.apply(0)); } @@ -455,7 +456,7 @@ public void testOr_serializationIterable() { public void testOr_arrayDefensivelyCopied() { @SuppressWarnings("unchecked") // generic arrays Predicate[] array = (Predicate[]) new Predicate[] {Predicates.alwaysFalse()}; - Predicate predicate = Predicates.or(array); + Predicate predicate = or(array); assertFalse(predicate.apply(1)); array[0] = Predicates.alwaysTrue(); assertFalse(predicate.apply(1)); @@ -463,7 +464,7 @@ public void testOr_arrayDefensivelyCopied() { public void testOr_listDefensivelyCopied() { List> list = new ArrayList<>(); - Predicate predicate = Predicates.or(list); + Predicate predicate = or(list); assertFalse(predicate.apply(1)); list.add(Predicates.alwaysTrue()); assertFalse(predicate.apply(1)); @@ -478,7 +479,7 @@ public Iterator> iterator() { return list.iterator(); } }; - Predicate predicate = Predicates.or(iterable); + Predicate predicate = or(iterable); assertFalse(predicate.apply(1)); list.add(Predicates.alwaysTrue()); assertFalse(predicate.apply(1)); @@ -539,7 +540,7 @@ public void testIsEqualToNull_serialization() { */ @GwtIncompatible // Predicates.instanceOf public void testIsInstanceOf_apply() { - Predicate<@Nullable Object> isInteger = Predicates.instanceOf(Integer.class); + Predicate<@Nullable Object> isInteger = instanceOf(Integer.class); assertTrue(isInteger.apply(1)); assertFalse(isInteger.apply(2.0f)); @@ -549,7 +550,7 @@ public void testIsInstanceOf_apply() { @GwtIncompatible // Predicates.instanceOf public void testIsInstanceOf_subclass() { - Predicate<@Nullable Object> isNumber = Predicates.instanceOf(Number.class); + Predicate<@Nullable Object> isNumber = instanceOf(Number.class); assertTrue(isNumber.apply(1)); assertTrue(isNumber.apply(2.0f)); @@ -559,7 +560,7 @@ public void testIsInstanceOf_subclass() { @GwtIncompatible // Predicates.instanceOf public void testIsInstanceOf_interface() { - Predicate<@Nullable Object> isComparable = Predicates.instanceOf(Comparable.class); + Predicate<@Nullable Object> isComparable = instanceOf(Comparable.class); assertTrue(isComparable.apply(1)); assertTrue(isComparable.apply(2.0f)); @@ -570,17 +571,16 @@ public void testIsInstanceOf_interface() { @GwtIncompatible // Predicates.instanceOf public void testIsInstanceOf_equality() { new EqualsTester() - .addEqualityGroup( - Predicates.instanceOf(Integer.class), Predicates.instanceOf(Integer.class)) - .addEqualityGroup(Predicates.instanceOf(Number.class)) - .addEqualityGroup(Predicates.instanceOf(Float.class)) + .addEqualityGroup(instanceOf(Integer.class), instanceOf(Integer.class)) + .addEqualityGroup(instanceOf(Number.class)) + .addEqualityGroup(instanceOf(Float.class)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // Predicates.instanceOf, SerializableTester public void testIsInstanceOf_serialization() { - checkSerialization(Predicates.instanceOf(Integer.class)); + checkSerialization(instanceOf(Integer.class)); } @J2ktIncompatible @@ -646,7 +646,7 @@ public void testIsNull_apply() { public void testIsNull_equality() { new EqualsTester() .addEqualityGroup(Predicates.isNull(), Predicates.isNull()) - .addEqualityGroup(Predicates.notNull()) + .addEqualityGroup(notNull()) .testEquals(); } @@ -660,14 +660,14 @@ public void testIsNull_serialization() { } public void testNotNull_apply() { - Predicate<@Nullable Integer> notNull = Predicates.notNull(); + Predicate<@Nullable Integer> notNull = notNull(); assertFalse(notNull.apply(null)); assertTrue(notNull.apply(1)); } public void testNotNull_equality() { new EqualsTester() - .addEqualityGroup(Predicates.notNull(), Predicates.notNull()) + .addEqualityGroup(notNull(), notNull()) .addEqualityGroup(Predicates.isNull()) .testEquals(); } @@ -675,7 +675,7 @@ public void testNotNull_equality() { @J2ktIncompatible @GwtIncompatible // SerializableTester public void testNotNull_serialization() { - checkSerialization(Predicates.notNull()); + checkSerialization(notNull()); } public void testIn_apply() { @@ -766,14 +766,14 @@ public void testCascadingSerialization() throws Exception { // Eclipse says Predicate; javac says Predicate. Predicate nasty = not( - Predicates.and( - Predicates.or( + and( + or( equalTo((Object) 1), equalTo(null), Predicates.alwaysFalse(), Predicates.alwaysTrue(), Predicates.isNull(), - Predicates.notNull(), + notNull(), Predicates.in(asList(1))))); assertEvalsToFalse(nasty); @@ -889,13 +889,13 @@ public void testHashCodeForBooleanOperations() { // Make sure that hash codes are not computed per-instance. assertEqualHashCode(not(p1), not(p1)); - assertEqualHashCode(Predicates.and(p1, p2), Predicates.and(p1, p2)); + assertEqualHashCode(and(p1, p2), and(p1, p2)); - assertEqualHashCode(Predicates.or(p1, p2), Predicates.or(p1, p2)); + assertEqualHashCode(or(p1, p2), or(p1, p2)); // While not a contractual requirement, we'd like the hash codes for ands // & ors of the same predicates to not collide. - assertTrue(Predicates.and(p1, p2).hashCode() != Predicates.or(p1, p2).hashCode()); + assertTrue(and(p1, p2).hashCode() != or(p1, p2).hashCode()); } @J2ktIncompatible diff --git a/android/guava-tests/test/com/google/common/base/StringsTest.java b/android/guava-tests/test/com/google/common/base/StringsTest.java index 1b4921db1811..4a099e3eecb5 100644 --- a/android/guava-tests/test/com/google/common/base/StringsTest.java +++ b/android/guava-tests/test/com/google/common/base/StringsTest.java @@ -16,6 +16,7 @@ package com.google.common.base; +import static com.google.common.base.Strings.repeat; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; @@ -105,20 +106,19 @@ public void testPadEnd_null() { @SuppressWarnings("InlineMeInliner") // test of method that doesn't just delegate public void testRepeat() { String input = "20"; - assertThat(Strings.repeat(input, 0)).isEqualTo(""); - assertThat(Strings.repeat(input, 1)).isEqualTo("20"); - assertThat(Strings.repeat(input, 2)).isEqualTo("2020"); - assertThat(Strings.repeat(input, 3)).isEqualTo("202020"); + assertThat(repeat(input, 0)).isEqualTo(""); + assertThat(repeat(input, 1)).isEqualTo("20"); + assertThat(repeat(input, 2)).isEqualTo("2020"); + assertThat(repeat(input, 3)).isEqualTo("202020"); - assertThat(Strings.repeat("", 4)).isEqualTo(""); + assertThat(repeat("", 4)).isEqualTo(""); for (int i = 0; i < 100; ++i) { - assertEquals(2 * i, Strings.repeat(input, i).length()); + assertEquals(2 * i, repeat(input, i).length()); } - assertThrows(IllegalArgumentException.class, () -> Strings.repeat("x", -1)); - assertThrows( - ArrayIndexOutOfBoundsException.class, () -> Strings.repeat("12345678", (1 << 30) + 3)); + assertThrows(IllegalArgumentException.class, () -> repeat("x", -1)); + assertThrows(ArrayIndexOutOfBoundsException.class, () -> repeat("12345678", (1 << 30) + 3)); } @SuppressWarnings({ @@ -126,7 +126,7 @@ public void testRepeat() { "nullness", // test of a bogus call }) public void testRepeat_null() { - assertThrows(NullPointerException.class, () -> Strings.repeat(null, 5)); + assertThrows(NullPointerException.class, () -> repeat(null, 5)); } @SuppressWarnings("UnnecessaryStringBuilder") // We want to test a non-String CharSequence diff --git a/android/guava-tests/test/com/google/common/cache/CacheBuilderFactory.java b/android/guava-tests/test/com/google/common/cache/CacheBuilderFactory.java index f7dc4c375f20..a66e5eab3a19 100644 --- a/android/guava-tests/test/com/google/common/cache/CacheBuilderFactory.java +++ b/android/guava-tests/test/com/google/common/cache/CacheBuilderFactory.java @@ -19,12 +19,12 @@ import static com.google.common.collect.Lists.transform; import static com.google.common.collect.Sets.cartesianProduct; import static com.google.common.collect.Sets.newHashSet; +import static com.google.common.collect.Sets.newLinkedHashSet; import com.google.common.base.MoreObjects; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.cache.LocalCache.Strength; -import com.google.common.collect.Sets; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.LinkedHashSet; import java.util.List; @@ -136,7 +136,7 @@ Iterable> buildAllPermutations() { private Iterable> buildCartesianProduct(Set... sets) { List>> optionalSets = newArrayListWithExpectedSize(sets.length); for (Set set : sets) { - Set> optionalSet = Sets.newLinkedHashSet(transform(set, Optional::fromNullable)); + Set> optionalSet = newLinkedHashSet(transform(set, Optional::fromNullable)); optionalSets.add(optionalSet); } Set>> cartesianProduct = cartesianProduct(optionalSets); diff --git a/android/guava-tests/test/com/google/common/cache/CacheTesting.java b/android/guava-tests/test/com/google/common/cache/CacheTesting.java index 6c33cde9d009..b6645bb9d931 100644 --- a/android/guava-tests/test/com/google/common/cache/CacheTesting.java +++ b/android/guava-tests/test/com/google/common/cache/CacheTesting.java @@ -15,6 +15,7 @@ package com.google.common.cache; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Sets.newIdentityHashSet; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; import static java.lang.Math.max; @@ -27,7 +28,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; import com.google.common.testing.EqualsTester; import com.google.common.testing.FakeTicker; import java.lang.ref.Reference; @@ -218,7 +218,7 @@ static void checkExpiration(Cache cache) { static void checkExpiration(LocalCache cchm) { for (Segment segment : cchm.segments) { if (cchm.usesWriteQueue()) { - Set> entries = Sets.newIdentityHashSet(); + Set> entries = newIdentityHashSet(); ReferenceEntry prev = null; for (ReferenceEntry current : segment.writeQueue) { @@ -240,7 +240,7 @@ static void checkExpiration(LocalCache cchm) { } if (cchm.usesAccessQueue()) { - Set> entries = Sets.newIdentityHashSet(); + Set> entries = newIdentityHashSet(); ReferenceEntry prev = null; for (ReferenceEntry current : segment.accessQueue) { diff --git a/android/guava-tests/test/com/google/common/collect/AbstractFilteredMapTest.java b/android/guava-tests/test/com/google/common/collect/AbstractFilteredMapTest.java index 179bb2b59021..33beee99a01e 100644 --- a/android/guava-tests/test/com/google/common/collect/AbstractFilteredMapTest.java +++ b/android/guava-tests/test/com/google/common/collect/AbstractFilteredMapTest.java @@ -16,6 +16,9 @@ package com.google.common.collect; +import static com.google.common.collect.Maps.filterEntries; +import static com.google.common.collect.Maps.filterKeys; +import static com.google.common.collect.Maps.filterValues; import static org.junit.Assert.assertThrows; import com.google.common.annotations.GwtCompatible; @@ -40,7 +43,7 @@ abstract class AbstractFilteredMapTest extends TestCase { public void testFilteredKeysIllegalPut() { Map unfiltered = createUnfiltered(); - Map filtered = Maps.filterKeys(unfiltered, NOT_LENGTH_3); + Map filtered = filterKeys(unfiltered, NOT_LENGTH_3); filtered.put("a", 1); filtered.put("b", 2); assertEquals(ImmutableMap.of("a", 1, "b", 2), filtered); @@ -50,7 +53,7 @@ public void testFilteredKeysIllegalPut() { public void testFilteredKeysIllegalPutAll() { Map unfiltered = createUnfiltered(); - Map filtered = Maps.filterKeys(unfiltered, NOT_LENGTH_3); + Map filtered = filterKeys(unfiltered, NOT_LENGTH_3); filtered.put("a", 1); filtered.put("b", 2); assertEquals(ImmutableMap.of("a", 1, "b", 2), filtered); @@ -64,7 +67,7 @@ public void testFilteredKeysIllegalPutAll() { public void testFilteredKeysFilteredReflectsBackingChanges() { Map unfiltered = createUnfiltered(); - Map filtered = Maps.filterKeys(unfiltered, NOT_LENGTH_3); + Map filtered = filterKeys(unfiltered, NOT_LENGTH_3); unfiltered.put("two", 2); unfiltered.put("three", 3); unfiltered.put("four", 4); @@ -82,7 +85,7 @@ public void testFilteredKeysFilteredReflectsBackingChanges() { public void testFilteredValuesIllegalPut() { Map unfiltered = createUnfiltered(); - Map filtered = Maps.filterValues(unfiltered, EVEN); + Map filtered = filterValues(unfiltered, EVEN); filtered.put("a", 2); unfiltered.put("b", 4); unfiltered.put("c", 5); @@ -94,7 +97,7 @@ public void testFilteredValuesIllegalPut() { public void testFilteredValuesIllegalPutAll() { Map unfiltered = createUnfiltered(); - Map filtered = Maps.filterValues(unfiltered, EVEN); + Map filtered = filterValues(unfiltered, EVEN); filtered.put("a", 2); unfiltered.put("b", 4); unfiltered.put("c", 5); @@ -108,7 +111,7 @@ public void testFilteredValuesIllegalPutAll() { public void testFilteredValuesIllegalSetValue() { Map unfiltered = createUnfiltered(); - Map filtered = Maps.filterValues(unfiltered, EVEN); + Map filtered = filterValues(unfiltered, EVEN); filtered.put("a", 2); filtered.put("b", 4); assertEquals(ImmutableMap.of("a", 2, "b", 4), filtered); @@ -125,7 +128,7 @@ public void testFilteredValuesClear() { unfiltered.put("two", 2); unfiltered.put("three", 3); unfiltered.put("four", 4); - Map filtered = Maps.filterValues(unfiltered, EVEN); + Map filtered = filterValues(unfiltered, EVEN); assertEquals(ImmutableMap.of("one", 1, "two", 2, "three", 3, "four", 4), unfiltered); assertEquals(ImmutableMap.of("two", 2, "four", 4), filtered); @@ -139,7 +142,7 @@ public void testFilteredEntriesIllegalPut() { unfiltered.put("cat", 3); unfiltered.put("dog", 2); unfiltered.put("horse", 5); - Map filtered = Maps.filterEntries(unfiltered, CORRECT_LENGTH); + Map filtered = filterEntries(unfiltered, CORRECT_LENGTH); assertEquals(ImmutableMap.of("cat", 3, "horse", 5), filtered); filtered.put("chicken", 7); @@ -154,7 +157,7 @@ public void testFilteredEntriesIllegalPutAll() { unfiltered.put("cat", 3); unfiltered.put("dog", 2); unfiltered.put("horse", 5); - Map filtered = Maps.filterEntries(unfiltered, CORRECT_LENGTH); + Map filtered = filterEntries(unfiltered, CORRECT_LENGTH); assertEquals(ImmutableMap.of("cat", 3, "horse", 5), filtered); filtered.put("chicken", 7); @@ -172,7 +175,7 @@ public void testFilteredEntriesObjectPredicate() { unfiltered.put("dog", 2); unfiltered.put("horse", 5); Predicate predicate = Predicates.alwaysFalse(); - Map filtered = Maps.filterEntries(unfiltered, predicate); + Map filtered = filterEntries(unfiltered, predicate); assertTrue(filtered.isEmpty()); } @@ -182,7 +185,7 @@ public void testFilteredEntriesWildCardEntryPredicate() { unfiltered.put("dog", 2); unfiltered.put("horse", 5); Predicate> predicate = e -> e.getKey().equals("cat") || e.getValue().equals(2); - Map filtered = Maps.filterEntries(unfiltered, predicate); + Map filtered = filterEntries(unfiltered, predicate); assertEquals(ImmutableMap.of("cat", 3, "dog", 2), filtered); } } diff --git a/android/guava-tests/test/com/google/common/collect/CollectionBenchmarkSampleData.java b/android/guava-tests/test/com/google/common/collect/CollectionBenchmarkSampleData.java index 47671aa92701..ce6d74292ce6 100644 --- a/android/guava-tests/test/com/google/common/collect/CollectionBenchmarkSampleData.java +++ b/android/guava-tests/test/com/google/common/collect/CollectionBenchmarkSampleData.java @@ -17,6 +17,7 @@ package com.google.common.collect; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Lists.newArrayListWithCapacity; import static java.util.Collections.shuffle; import java.util.ArrayList; @@ -64,7 +65,7 @@ Element[] getQueries() { } private Element[] createQueries(Set elementsInSet, int numQueries) { - List queryList = Lists.newArrayListWithCapacity(numQueries); + List queryList = newArrayListWithCapacity(numQueries); int numGoodQueries = (int) (numQueries * hitRate + 0.5); diff --git a/android/guava-tests/test/com/google/common/collect/EnumBiMapTest.java b/android/guava-tests/test/com/google/common/collect/EnumBiMapTest.java index d710e0384c03..994c42dc225c 100644 --- a/android/guava-tests/test/com/google/common/collect/EnumBiMapTest.java +++ b/android/guava-tests/test/com/google/common/collect/EnumBiMapTest.java @@ -16,6 +16,7 @@ package com.google.common.collect; +import static com.google.common.collect.Sets.newIdentityHashSet; import static com.google.common.collect.testing.Helpers.mapEntry; import static com.google.common.collect.testing.Helpers.orderEntriesByKey; import static com.google.common.testing.SerializableTester.reserializeAndAssert; @@ -286,7 +287,7 @@ public void testEntrySet() { Currency.PESO, Country.CHILE, Currency.FRANC, Country.SWITZERLAND); EnumBiMap bimap = EnumBiMap.create(map); - Set uniqueEntries = Sets.newIdentityHashSet(); + Set uniqueEntries = newIdentityHashSet(); uniqueEntries.addAll(bimap.entrySet()); assertEquals(3, uniqueEntries.size()); } diff --git a/android/guava-tests/test/com/google/common/collect/EnumHashBiMapTest.java b/android/guava-tests/test/com/google/common/collect/EnumHashBiMapTest.java index ff8fcd247d36..14ae1c93bfcb 100644 --- a/android/guava-tests/test/com/google/common/collect/EnumHashBiMapTest.java +++ b/android/guava-tests/test/com/google/common/collect/EnumHashBiMapTest.java @@ -17,6 +17,7 @@ package com.google.common.collect; import static com.google.common.collect.Maps.immutableEntry; +import static com.google.common.collect.Sets.newIdentityHashSet; import static com.google.common.testing.SerializableTester.reserializeAndAssert; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; @@ -221,7 +222,7 @@ public void testEntrySet() { Currency.FRANC, "franc"); EnumHashBiMap bimap = EnumHashBiMap.create(map); - Set uniqueEntries = Sets.newIdentityHashSet(); + Set uniqueEntries = newIdentityHashSet(); uniqueEntries.addAll(bimap.entrySet()); assertEquals(3, uniqueEntries.size()); } diff --git a/android/guava-tests/test/com/google/common/collect/EnumMultisetTest.java b/android/guava-tests/test/com/google/common/collect/EnumMultisetTest.java index 5cbcce256ef5..2df8fb6d5793 100644 --- a/android/guava-tests/test/com/google/common/collect/EnumMultisetTest.java +++ b/android/guava-tests/test/com/google/common/collect/EnumMultisetTest.java @@ -16,6 +16,7 @@ package com.google.common.collect; +import static com.google.common.collect.Sets.newIdentityHashSet; import static com.google.common.testing.SerializableTester.reserialize; import static com.google.common.truth.Truth.assertThat; import static java.util.Arrays.asList; @@ -148,7 +149,7 @@ public void testEntrySet() { ms.add(Color.YELLOW, 1); ms.add(Color.RED, 2); - Set uniqueEntries = Sets.newIdentityHashSet(); + Set uniqueEntries = newIdentityHashSet(); uniqueEntries.addAll(ms.entrySet()); assertEquals(3, uniqueEntries.size()); } diff --git a/android/guava-tests/test/com/google/common/collect/FilteredCollectionsTestUtil.java b/android/guava-tests/test/com/google/common/collect/FilteredCollectionsTestUtil.java index a5dfeff3053b..3be3d97badbd 100644 --- a/android/guava-tests/test/com/google/common/collect/FilteredCollectionsTestUtil.java +++ b/android/guava-tests/test/com/google/common/collect/FilteredCollectionsTestUtil.java @@ -16,6 +16,7 @@ package com.google.common.collect; +import static com.google.common.base.Predicates.and; import static com.google.common.base.Predicates.not; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; @@ -188,8 +189,7 @@ public void testClearFilterFiltered() { C filtered1 = filter(unfiltered, EVEN); C filtered2 = filter(filtered1, PRIME_DIGIT); - C inverseFiltered = - filter(createUnfiltered(contents), not(Predicates.and(EVEN, PRIME_DIGIT))); + C inverseFiltered = filter(createUnfiltered(contents), not(and(EVEN, PRIME_DIGIT))); filtered2.clear(); assertThat(unfiltered).containsExactlyElementsIn(inverseFiltered); diff --git a/android/guava-tests/test/com/google/common/collect/FilteredSortedMapTest.java b/android/guava-tests/test/com/google/common/collect/FilteredSortedMapTest.java index 9102201a9b0b..05f0f26dd791 100644 --- a/android/guava-tests/test/com/google/common/collect/FilteredSortedMapTest.java +++ b/android/guava-tests/test/com/google/common/collect/FilteredSortedMapTest.java @@ -16,6 +16,7 @@ package com.google.common.collect; +import static com.google.common.collect.Maps.filterEntries; import static com.google.common.truth.Truth.assertThat; import com.google.common.annotations.GwtCompatible; @@ -37,7 +38,7 @@ public void testFirstAndLastKeyFilteredMap() { unfiltered.put("cat", 3); unfiltered.put("dog", 5); - SortedMap filtered = Maps.filterEntries(unfiltered, CORRECT_LENGTH); + SortedMap filtered = filterEntries(unfiltered, CORRECT_LENGTH); assertThat(filtered.firstKey()).isEqualTo("banana"); assertThat(filtered.lastKey()).isEqualTo("cat"); } @@ -48,7 +49,7 @@ public void testHeadSubTailMap_filteredMap() { unfiltered.put("banana", 6); unfiltered.put("cat", 4); unfiltered.put("dog", 3); - SortedMap filtered = Maps.filterEntries(unfiltered, CORRECT_LENGTH); + SortedMap filtered = filterEntries(unfiltered, CORRECT_LENGTH); assertEquals(ImmutableMap.of("banana", 6), filtered.headMap("dog")); assertEquals(ImmutableMap.of(), filtered.headMap("banana")); diff --git a/android/guava-tests/test/com/google/common/collect/ForwardingNavigableSetTest.java b/android/guava-tests/test/com/google/common/collect/ForwardingNavigableSetTest.java index 7a10c294792b..1605a35e8f4f 100644 --- a/android/guava-tests/test/com/google/common/collect/ForwardingNavigableSetTest.java +++ b/android/guava-tests/test/com/google/common/collect/ForwardingNavigableSetTest.java @@ -16,6 +16,7 @@ package com.google.common.collect; +import static com.google.common.collect.Sets.newTreeSet; import static java.util.Arrays.asList; import com.google.common.base.Function; @@ -180,7 +181,7 @@ protected Set create(String[] elements) { @Override public List order(List insertionOrder) { - return new ArrayList<>(Sets.newTreeSet(insertionOrder)); + return new ArrayList<>(newTreeSet(insertionOrder)); } }) .named("ForwardingNavigableSet[SafeTreeSet] with standard implementations") @@ -201,7 +202,7 @@ protected Set create(String[] elements) { @Override public List order(List insertionOrder) { - return new ArrayList<>(Sets.newTreeSet(insertionOrder)); + return new ArrayList<>(newTreeSet(insertionOrder)); } }) .named( diff --git a/android/guava-tests/test/com/google/common/collect/ForwardingSortedSetTest.java b/android/guava-tests/test/com/google/common/collect/ForwardingSortedSetTest.java index 0598544a13fa..6a661a278e71 100644 --- a/android/guava-tests/test/com/google/common/collect/ForwardingSortedSetTest.java +++ b/android/guava-tests/test/com/google/common/collect/ForwardingSortedSetTest.java @@ -16,6 +16,7 @@ package com.google.common.collect; +import static com.google.common.collect.Sets.newTreeSet; import static java.util.Arrays.asList; import com.google.common.base.Function; @@ -137,7 +138,7 @@ protected SortedSet create(String[] elements) { @Override public List order(List insertionOrder) { - return new ArrayList<>(Sets.newTreeSet(insertionOrder)); + return new ArrayList<>(newTreeSet(insertionOrder)); } }) .named("ForwardingSortedSet[SafeTreeSet] with standard implementations") diff --git a/android/guava-tests/test/com/google/common/collect/IterablesTest.java b/android/guava-tests/test/com/google/common/collect/IterablesTest.java index b52e09d6c5f5..920eccfdb108 100644 --- a/android/guava-tests/test/com/google/common/collect/IterablesTest.java +++ b/android/guava-tests/test/com/google/common/collect/IterablesTest.java @@ -19,6 +19,7 @@ import static com.google.common.base.Predicates.equalTo; import static com.google.common.collect.Iterables.all; import static com.google.common.collect.Iterables.any; +import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.Iterables.elementsEqual; import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.find; @@ -370,7 +371,7 @@ public void testConcatIterable() { List> input = newArrayList(list1, list2); - Iterable result = Iterables.concat(input); + Iterable result = concat(input); assertEquals(asList(1, 4), newArrayList(result)); // Now change the inputs and see result dynamically change as well @@ -389,7 +390,7 @@ public void testConcatVarargs() { List list3 = newArrayList(7, 8); List list4 = newArrayList(9); List list5 = newArrayList(10); - Iterable result = Iterables.concat(list1, list2, list3, list4, list5); + Iterable result = concat(list1, list2, list3, list4, list5); assertEquals(asList(1, 4, 7, 8, 9, 10), newArrayList(result)); assertThat(result.toString()).isEqualTo("[1, 4, 7, 8, 9, 10]"); } @@ -398,13 +399,13 @@ public void testConcatNullPointerException() { List list1 = newArrayList(1); List list2 = newArrayList(4); - assertThrows(NullPointerException.class, () -> Iterables.concat(list1, null, list2)); + assertThrows(NullPointerException.class, () -> concat(list1, null, list2)); } public void testConcatPeformingFiniteCycle() { Iterable iterable = asList(1, 2, 3); int n = 4; - Iterable repeated = Iterables.concat(nCopies(n, iterable)); + Iterable repeated = concat(nCopies(n, iterable)); assertThat(repeated).containsExactly(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3).inOrder(); } diff --git a/android/guava-tests/test/com/google/common/collect/IteratorsTest.java b/android/guava-tests/test/com/google/common/collect/IteratorsTest.java index 4c8a532c46a3..c98637ad816c 100644 --- a/android/guava-tests/test/com/google/common/collect/IteratorsTest.java +++ b/android/guava-tests/test/com/google/common/collect/IteratorsTest.java @@ -21,6 +21,7 @@ import static com.google.common.collect.Iterators.advance; import static com.google.common.collect.Iterators.all; import static com.google.common.collect.Iterators.any; +import static com.google.common.collect.Iterators.concat; import static com.google.common.collect.Iterators.elementsEqual; import static com.google.common.collect.Iterators.emptyIterator; import static com.google.common.collect.Iterators.filter; @@ -32,6 +33,7 @@ import static com.google.common.collect.Iterators.mergeSorted; import static com.google.common.collect.Iterators.peekingIterator; import static com.google.common.collect.Iterators.singletonIterator; +import static com.google.common.collect.Iterators.transform; import static com.google.common.collect.Iterators.tryFind; import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.testing.IteratorFeature.MODIFIABLE; @@ -42,6 +44,7 @@ import static java.util.Collections.emptySet; import static java.util.Collections.singleton; import static java.util.Collections.singletonList; +import static java.util.Comparator.comparing; import static org.junit.Assert.assertThrows; import com.google.common.annotations.GwtCompatible; @@ -425,7 +428,7 @@ public void testTryFind_alwaysFalse_isPresent() { public void testTransform() { Iterator input = asList("1", "2", "3").iterator(); Iterator result = - Iterators.transform( + transform( input, new Function() { @Override @@ -443,7 +446,7 @@ public void testTransformRemove() { List list = Lists.newArrayList("1", "2", "3"); Iterator input = list.iterator(); Iterator iterator = - Iterators.transform( + transform( input, new Function() { @Override @@ -461,7 +464,7 @@ public Integer apply(String from) { public void testPoorlyBehavedTransform() { Iterator input = asList("1", "not a number", "3").iterator(); Iterator result = - Iterators.transform( + transform( input, new Function() { @Override @@ -477,7 +480,7 @@ public Integer apply(String from) { public void testNullFriendlyTransform() { Iterator<@Nullable Integer> input = Arrays.<@Nullable Integer>asList(1, 2, null, 3).iterator(); Iterator result = - Iterators.transform( + transform( input, new Function<@Nullable Integer, String>() { @Override @@ -668,7 +671,7 @@ public void testConcatNoIteratorsYieldsEmpty() { new EmptyIteratorTester() { @Override protected Iterator newTargetIterator() { - return Iterators.concat(); + return concat(); } }.test(); } @@ -678,7 +681,7 @@ public void testConcatOneEmptyIteratorYieldsEmpty() { new EmptyIteratorTester() { @Override protected Iterator newTargetIterator() { - return Iterators.concat(iterateOver()); + return concat(iterateOver()); } }.test(); } @@ -688,7 +691,7 @@ public void testConcatMultipleEmptyIteratorsYieldsEmpty() { new EmptyIteratorTester() { @Override protected Iterator newTargetIterator() { - return Iterators.concat(iterateOver(), iterateOver()); + return concat(iterateOver(), iterateOver()); } }.test(); } @@ -698,7 +701,7 @@ public void testConcatSingletonYieldsSingleton() { new SingletonIteratorTester() { @Override protected Iterator newTargetIterator() { - return Iterators.concat(iterateOver(1)); + return concat(iterateOver(1)); } }.test(); } @@ -708,7 +711,7 @@ public void testConcatEmptyAndSingletonAndEmptyYieldsSingleton() { new SingletonIteratorTester() { @Override protected Iterator newTargetIterator() { - return Iterators.concat(iterateOver(), iterateOver(1), iterateOver()); + return concat(iterateOver(), iterateOver(1), iterateOver()); } }.test(); } @@ -718,7 +721,7 @@ public void testConcatSingletonAndSingletonYieldsDoubleton() { new DoubletonIteratorTester() { @Override protected Iterator newTargetIterator() { - return Iterators.concat(iterateOver(1), iterateOver(2)); + return concat(iterateOver(1), iterateOver(2)); } }.test(); } @@ -728,7 +731,7 @@ public void testConcatSingletonAndSingletonWithEmptiesYieldsDoubleton() { new DoubletonIteratorTester() { @Override protected Iterator newTargetIterator() { - return Iterators.concat(iterateOver(1), iterateOver(), iterateOver(), iterateOver(2)); + return concat(iterateOver(1), iterateOver(), iterateOver(), iterateOver(2)); } }.test(); } @@ -739,26 +742,26 @@ public void testConcatUnmodifiable() { 5, UNMODIFIABLE, asList(1, 2), IteratorTester.KnownOrder.KNOWN_ORDER) { @Override protected Iterator newTargetIterator() { - return Iterators.concat( + return concat( asList(1).iterator(), Arrays.asList().iterator(), asList(2).iterator()); } }.test(); } public void testConcatPartiallyAdvancedSecond() { - Iterator itr1 = Iterators.concat(singletonIterator("a"), Iterators.forArray("b", "c")); + Iterator itr1 = concat(singletonIterator("a"), Iterators.forArray("b", "c")); assertThat(itr1.next()).isEqualTo("a"); assertThat(itr1.next()).isEqualTo("b"); - Iterator itr2 = Iterators.concat(singletonIterator("d"), itr1); + Iterator itr2 = concat(singletonIterator("d"), itr1); assertThat(itr2.next()).isEqualTo("d"); assertThat(itr2.next()).isEqualTo("c"); } public void testConcatPartiallyAdvancedFirst() { - Iterator itr1 = Iterators.concat(singletonIterator("a"), Iterators.forArray("b", "c")); + Iterator itr1 = concat(singletonIterator("a"), Iterators.forArray("b", "c")); assertThat(itr1.next()).isEqualTo("a"); assertThat(itr1.next()).isEqualTo("b"); - Iterator itr2 = Iterators.concat(itr1, singletonIterator("d")); + Iterator itr2 = concat(itr1, singletonIterator("d")); assertThat(itr2.next()).isEqualTo("c"); assertThat(itr2.next()).isEqualTo("d"); } @@ -769,7 +772,7 @@ public void testConcatContainingNull() { (Iterator>) Arrays.<@Nullable Iterator>asList(iterateOver(1, 2), null, iterateOver(3)) .iterator(); - Iterator result = Iterators.concat(input); + Iterator result = concat(input); assertEquals(1, (int) result.next()); assertEquals(2, (int) result.next()); assertThrows(NullPointerException.class, () -> result.hasNext()); @@ -780,16 +783,14 @@ public void testConcatContainingNull() { public void testConcatVarArgsContainingNull() { assertThrows( NullPointerException.class, - () -> - Iterators.concat( - iterateOver(1, 2), null, iterateOver(3), iterateOver(4), iterateOver(5))); + () -> concat(iterateOver(1, 2), null, iterateOver(3), iterateOver(4), iterateOver(5))); } public void testConcatNested_appendToEnd() { int nestingDepth = 128; Iterator iterator = iterateOver(); for (int i = 0; i < nestingDepth; i++) { - iterator = Iterators.concat(iterator, iterateOver(1)); + iterator = concat(iterator, iterateOver(1)); } assertEquals(nestingDepth, Iterators.size(iterator)); } @@ -798,7 +799,7 @@ public void testConcatNested_appendToBeginning() { int nestingDepth = 128; Iterator iterator = iterateOver(); for (int i = 0; i < nestingDepth; i++) { - iterator = Iterators.concat(iterateOver(1), iterator); + iterator = concat(iterateOver(1), iterator); } assertEquals(nestingDepth, Iterators.size(iterator)); } @@ -1555,7 +1556,7 @@ public void testMergeSorted_stable_issue5773Example() { ImmutableList left = ImmutableList.of(new TestDatum("B", 1), new TestDatum("C", 1)); ImmutableList right = ImmutableList.of(new TestDatum("A", 2), new TestDatum("C", 2)); - Comparator comparator = Comparator.comparing(d -> d.letter); + Comparator comparator = comparing(d -> d.letter); // When elements compare as equal (both C's have same letter), our merge should always return C1 // before C2, since C1 is from the first iterator. @@ -1579,7 +1580,7 @@ public void testMergeSorted_stable_allEqual() { ImmutableList second = ImmutableList.of(new TestDatum("A", 3), new TestDatum("A", 4)); - Comparator comparator = Comparator.comparing(d -> d.letter); + Comparator comparator = comparing(d -> d.letter); Iterator merged = mergeSorted(ImmutableList.of(first.iterator(), second.iterator()), comparator); diff --git a/android/guava-tests/test/com/google/common/collect/ListsTest.java b/android/guava-tests/test/com/google/common/collect/ListsTest.java index d4eacce82f18..35b22930109f 100644 --- a/android/guava-tests/test/com/google/common/collect/ListsTest.java +++ b/android/guava-tests/test/com/google/common/collect/ListsTest.java @@ -21,6 +21,7 @@ import static com.google.common.collect.Lists.cartesianProduct; import static com.google.common.collect.Lists.charactersOf; import static com.google.common.collect.Lists.computeArrayListCapacity; +import static com.google.common.collect.Lists.newArrayListWithCapacity; import static com.google.common.collect.Lists.newArrayListWithExpectedSize; import static com.google.common.collect.Lists.partition; import static com.google.common.collect.Lists.transform; @@ -335,15 +336,15 @@ public void testNewArrayListEmpty() { } public void testNewArrayListWithCapacity() { - ArrayList list = Lists.newArrayListWithCapacity(0); + ArrayList list = newArrayListWithCapacity(0); assertEquals(emptyList(), list); - ArrayList bigger = Lists.newArrayListWithCapacity(256); + ArrayList bigger = newArrayListWithCapacity(256); assertEquals(emptyList(), bigger); } public void testNewArrayListWithCapacity_negative() { - assertThrows(IllegalArgumentException.class, () -> Lists.newArrayListWithCapacity(-1)); + assertThrows(IllegalArgumentException.class, () -> newArrayListWithCapacity(-1)); } public void testNewArrayListWithExpectedSize() { diff --git a/android/guava-tests/test/com/google/common/collect/MapsCollectionTest.java b/android/guava-tests/test/com/google/common/collect/MapsCollectionTest.java index 2bd475175ebb..2a071559b9a4 100644 --- a/android/guava-tests/test/com/google/common/collect/MapsCollectionTest.java +++ b/android/guava-tests/test/com/google/common/collect/MapsCollectionTest.java @@ -18,7 +18,13 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Maps.filterEntries; +import static com.google.common.collect.Maps.filterKeys; +import static com.google.common.collect.Maps.filterValues; +import static com.google.common.collect.Maps.transformEntries; import static com.google.common.collect.Maps.transformValues; +import static com.google.common.collect.Maps.unmodifiableNavigableMap; +import static com.google.common.collect.Sets.newTreeSet; import static com.google.common.collect.testing.Helpers.mapEntry; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Collections.sort; @@ -77,7 +83,7 @@ public static Test suite() { protected SortedMap create(Entry[] entries) { SafeTreeMap map = new SafeTreeMap<>(); putEntries(map, entries); - return Maps.unmodifiableNavigableMap(map); + return unmodifiableNavigableMap(map); } }) .named("unmodifiableNavigableMap[SafeTreeMap]") @@ -257,7 +263,7 @@ public SampleElements> samples() { @Override public NavigableMap create(Object... elements) { - NavigableSet set = Sets.newTreeSet(Ordering.natural()); + NavigableSet set = newTreeSet(Ordering.natural()); for (Object e : elements) { Entry entry = (Entry) e; checkNotNull(entry.getValue()); @@ -323,7 +329,7 @@ protected Map create(Entry[] entries) { Map map = new HashMap<>(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterKeys(map, FILTER_KEYS); + return filterKeys(map, FILTER_KEYS); } }) .named("Maps.filterKeys[Map, Predicate]") @@ -342,7 +348,7 @@ protected Map create(Entry[] entries) { Map map = new HashMap<>(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterValues(map, FILTER_VALUES); + return filterValues(map, FILTER_VALUES); } }) .named("Maps.filterValues[Map, Predicate]") @@ -361,7 +367,7 @@ protected Map create(Entry[] entries) { Map map = new HashMap<>(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterEntries(map, FILTER_ENTRIES); + return filterEntries(map, FILTER_ENTRIES); } }) .named("Maps.filterEntries[Map, Predicate]") @@ -380,8 +386,8 @@ protected Map create(Entry[] entries) { Map map = new HashMap<>(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - map = Maps.filterEntries(map, FILTER_ENTRIES_1); - return Maps.filterEntries(map, FILTER_ENTRIES_2); + map = filterEntries(map, FILTER_ENTRIES_1); + return filterEntries(map, FILTER_ENTRIES_2); } }) .named("Maps.filterEntries[Maps.filterEntries[Map, Predicate], Predicate]") @@ -405,7 +411,7 @@ protected BiMap create(Entry[] entries) { BiMap map = HashBiMap.create(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterKeys(map, FILTER_KEYS); + return filterKeys(map, FILTER_KEYS); } }) .named("Maps.filterKeys[BiMap, Predicate]") @@ -423,7 +429,7 @@ protected BiMap create(Entry[] entries) { BiMap map = HashBiMap.create(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterValues(map, FILTER_VALUES); + return filterValues(map, FILTER_VALUES); } }) .named("Maps.filterValues[BiMap, Predicate]") @@ -442,7 +448,7 @@ protected BiMap create(Entry[] entries) { BiMap map = HashBiMap.create(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterEntries(map, FILTER_ENTRIES); + return filterEntries(map, FILTER_ENTRIES); } }) .named("Maps.filterEntries[BiMap, Predicate]") @@ -466,7 +472,7 @@ protected SortedMap create(Entry[] entries) { SortedMap map = new NonNavigableSortedMap(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterKeys(map, FILTER_KEYS); + return filterKeys(map, FILTER_KEYS); } }) .named("Maps.filterKeys[SortedMap, Predicate]") @@ -481,7 +487,7 @@ protected SortedMap create(Entry[] entries) { SortedMap map = new NonNavigableSortedMap(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterValues(map, FILTER_VALUES); + return filterValues(map, FILTER_VALUES); } }) .named("Maps.filterValues[SortedMap, Predicate]") @@ -496,7 +502,7 @@ protected SortedMap create(Entry[] entries) { SortedMap map = new NonNavigableSortedMap(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterEntries(map, FILTER_ENTRIES); + return filterEntries(map, FILTER_ENTRIES); } }) .named("Maps.filterEntries[SortedMap, Predicate]") @@ -517,7 +523,7 @@ protected NavigableMap create(Entry[] entries) { putEntries(map, entries); map.put("banana", "toast"); map.put("eggplant", "spam"); - return Maps.filterKeys(map, FILTER_KEYS); + return filterKeys(map, FILTER_KEYS); } }) .named("Maps.filterKeys[NavigableMap, Predicate]") @@ -533,7 +539,7 @@ protected NavigableMap create(Entry[] entries) { putEntries(map, entries); map.put("banana", "toast"); map.put("eggplant", "spam"); - return Maps.filterValues(map, FILTER_VALUES); + return filterValues(map, FILTER_VALUES); } }) .named("Maps.filterValues[NavigableMap, Predicate]") @@ -549,7 +555,7 @@ protected NavigableMap create(Entry[] entries) { putEntries(map, entries); map.put("banana", "toast"); map.put("eggplant", "spam"); - return Maps.filterEntries(map, FILTER_ENTRIES); + return filterEntries(map, FILTER_ENTRIES); } }) .named("Maps.filterEntries[NavigableMap, Predicate]") @@ -619,7 +625,7 @@ public boolean apply(Entry entry) { private static class NonNavigableSortedSet extends ForwardingSortedSet { - private final SortedSet delegate = Sets.newTreeSet(Ordering.natural()); + private final SortedSet delegate = newTreeSet(Ordering.natural()); @Override protected SortedSet delegate() { @@ -697,7 +703,7 @@ protected Map create(Entry[] entries) { for (Entry entry : entries) { map.put(entry.getKey(), encode(entry.getValue())); } - return Maps.transformEntries(map, DECODE_ENTRY_TRANSFORMER); + return transformEntries(map, DECODE_ENTRY_TRANSFORMER); } }) .named("Maps.transformEntries[Map, EntryTransformer]") @@ -742,7 +748,7 @@ protected SortedMap create(Entry[] entries) { for (Entry entry : entries) { map.put(entry.getKey(), encode(entry.getValue())); } - return Maps.transformEntries(map, DECODE_ENTRY_TRANSFORMER); + return transformEntries(map, DECODE_ENTRY_TRANSFORMER); } }) .named("Maps.transformEntries[SortedMap, EntryTransformer]") @@ -785,7 +791,7 @@ protected NavigableMap create(Entry[] entries) { for (Entry entry : entries) { map.put(entry.getKey(), encode(entry.getValue())); } - return Maps.transformEntries(map, DECODE_ENTRY_TRANSFORMER); + return transformEntries(map, DECODE_ENTRY_TRANSFORMER); } }) .named("Maps.transformEntries[NavigableMap, EntryTransformer]") diff --git a/android/guava-tests/test/com/google/common/collect/MapsTest.java b/android/guava-tests/test/com/google/common/collect/MapsTest.java index 30b1b6502667..c8270f4b3073 100644 --- a/android/guava-tests/test/com/google/common/collect/MapsTest.java +++ b/android/guava-tests/test/com/google/common/collect/MapsTest.java @@ -17,9 +17,11 @@ package com.google.common.collect; import static com.google.common.collect.Maps.immutableEntry; +import static com.google.common.collect.Maps.toMap; import static com.google.common.collect.Maps.transformEntries; import static com.google.common.collect.Maps.transformValues; import static com.google.common.collect.Maps.unmodifiableNavigableMap; +import static com.google.common.collect.Sets.newTreeSet; import static com.google.common.collect.testing.Helpers.mapEntry; import static com.google.common.testing.SerializableTester.reserializeAndAssert; import static com.google.common.truth.Truth.assertThat; @@ -698,7 +700,7 @@ public void testAsMapEmpty() { } private static class NonNavigableSortedSet extends ForwardingSortedSet { - private final SortedSet delegate = Sets.newTreeSet(); + private final SortedSet delegate = newTreeSet(); @Override protected SortedSet delegate() { @@ -773,7 +775,7 @@ public void testAsMapSortedEmpty() { @GwtIncompatible // NavigableMap public void testAsMapNavigable() { - NavigableSet strings = Sets.newTreeSet(asList("one", "two", "three")); + NavigableSet strings = newTreeSet(asList("one", "two", "three")); NavigableMap map = Maps.asMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertEquals(Integer.valueOf(5), map.get("three")); @@ -820,7 +822,7 @@ public void testAsMapNavigable() { @GwtIncompatible // NavigableMap public void testAsMapNavigableReadsThrough() { - NavigableSet strings = Sets.newTreeSet(); + NavigableSet strings = newTreeSet(); Collections.addAll(strings, "one", "two", "three"); NavigableMap map = Maps.asMap(strings, LENGTH_FUNCTION); assertThat(map.comparator()).isNull(); @@ -854,7 +856,7 @@ public void testAsMapNavigableReadsThrough() { @GwtIncompatible // NavigableMap public void testAsMapNavigableWritesThrough() { - NavigableSet strings = Sets.newTreeSet(); + NavigableSet strings = newTreeSet(); Collections.addAll(strings, "one", "two", "three"); NavigableMap map = Maps.asMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); @@ -891,7 +893,7 @@ public void testAsMapNavigableEmpty() { public void testToMap() { Iterable strings = ImmutableList.of("one", "two", "three"); - ImmutableMap map = Maps.toMap(strings, LENGTH_FUNCTION); + ImmutableMap map = toMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertThat(map.entrySet()) .containsExactly(mapEntry("one", 3), mapEntry("two", 3), mapEntry("three", 5)) @@ -900,7 +902,7 @@ public void testToMap() { public void testToMapIterator() { Iterator strings = ImmutableList.of("one", "two", "three").iterator(); - ImmutableMap map = Maps.toMap(strings, LENGTH_FUNCTION); + ImmutableMap map = toMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertThat(map.entrySet()) .containsExactly(mapEntry("one", 3), mapEntry("two", 3), mapEntry("three", 5)) @@ -909,7 +911,7 @@ public void testToMapIterator() { public void testToMapWithDuplicateKeys() { Iterable strings = ImmutableList.of("one", "two", "three", "two", "one"); - ImmutableMap map = Maps.toMap(strings, LENGTH_FUNCTION); + ImmutableMap map = toMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertThat(map.entrySet()) .containsExactly(mapEntry("one", 3), mapEntry("two", 3), mapEntry("three", 5)) @@ -920,12 +922,12 @@ public void testToMapWithNullKeys() { Iterable<@Nullable String> strings = asList("one", null, "three"); assertThrows( NullPointerException.class, - () -> Maps.toMap((Iterable) strings, Functions.constant("foo"))); + () -> toMap((Iterable) strings, Functions.constant("foo"))); } public void testToMapWithNullValues() { Iterable strings = ImmutableList.of("one", "two", "three"); - assertThrows(NullPointerException.class, () -> Maps.toMap(strings, Functions.constant(null))); + assertThrows(NullPointerException.class, () -> toMap(strings, Functions.constant(null))); } private static final ImmutableBiMap INT_TO_STRING_MAP = diff --git a/android/guava-tests/test/com/google/common/collect/MinMaxPriorityQueueTest.java b/android/guava-tests/test/com/google/common/collect/MinMaxPriorityQueueTest.java index b3bbb1dae47c..beea6c915fa8 100644 --- a/android/guava-tests/test/com/google/common/collect/MinMaxPriorityQueueTest.java +++ b/android/guava-tests/test/com/google/common/collect/MinMaxPriorityQueueTest.java @@ -16,6 +16,7 @@ package com.google.common.collect; +import static com.google.common.collect.Lists.newArrayListWithCapacity; import static com.google.common.collect.Platform.reduceExponentIfGwt; import static com.google.common.collect.Platform.reduceIterationsIfGwt; import static com.google.common.collect.Sets.newHashSet; @@ -358,7 +359,7 @@ public void testIteratorRegressionChildlessUncle() { q.remove(10); // Now we're in the critical state: [1, 15, 13, 8, 14] // Removing 8 while iterating caused duplicates in iteration result. - List result = Lists.newArrayListWithCapacity(initial.size()); + List result = newArrayListWithCapacity(initial.size()); for (Iterator iter = q.iterator(); iter.hasNext(); ) { Integer value = iter.next(); result.add(value); @@ -696,7 +697,7 @@ public void testExhaustive_pollAndPush() { List expected = createOrderedList(size); for (Collection perm : Collections2.permutations(expected)) { MinMaxPriorityQueue q = MinMaxPriorityQueue.create(perm); - List elements = Lists.newArrayListWithCapacity(size); + List elements = newArrayListWithCapacity(size); while (!q.isEmpty()) { Integer next = q.pollFirst(); for (int i = 0; i <= size; i++) { @@ -717,7 +718,7 @@ public void testRegression_dataCorruption() { List expected = createOrderedList(size); MinMaxPriorityQueue q = MinMaxPriorityQueue.create(expected); List contents = new ArrayList<>(expected); - List elements = Lists.newArrayListWithCapacity(size); + List elements = newArrayListWithCapacity(size); while (!q.isEmpty()) { assertThat(q).containsExactlyElementsIn(contents); Integer next = q.pollFirst(); diff --git a/android/guava-tests/test/com/google/common/collect/MultimapsCollectionTest.java b/android/guava-tests/test/com/google/common/collect/MultimapsCollectionTest.java index 882abdd8e131..2c134366a1f6 100644 --- a/android/guava-tests/test/com/google/common/collect/MultimapsCollectionTest.java +++ b/android/guava-tests/test/com/google/common/collect/MultimapsCollectionTest.java @@ -22,6 +22,7 @@ import static com.google.common.collect.Multimaps.filterKeys; import static com.google.common.collect.Multimaps.filterValues; import static com.google.common.collect.Multimaps.synchronizedListMultimap; +import static com.google.common.collect.Sets.newLinkedHashSet; import static com.google.common.collect.testing.Helpers.mapEntry; import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES; import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; @@ -524,7 +525,7 @@ public SetMultimap create(Object... elements) { @Override public Collection createCollection(Iterable values) { - return Sets.newLinkedHashSet(values); + return newLinkedHashSet(values); } } diff --git a/android/guava-tests/test/com/google/common/collect/SetsFilterNavigableSetTest.java b/android/guava-tests/test/com/google/common/collect/SetsFilterNavigableSetTest.java index 2090e78098c6..c09efa6e4994 100644 --- a/android/guava-tests/test/com/google/common/collect/SetsFilterNavigableSetTest.java +++ b/android/guava-tests/test/com/google/common/collect/SetsFilterNavigableSetTest.java @@ -16,6 +16,8 @@ package com.google.common.collect; +import static com.google.common.collect.Sets.newTreeSet; + import com.google.common.base.Predicate; import com.google.common.collect.FilteredCollectionsTestUtil.AbstractFilteredNavigableSetTest; import java.util.NavigableSet; @@ -25,7 +27,7 @@ public final class SetsFilterNavigableSetTest extends AbstractFilteredNavigableSetTest { @Override NavigableSet createUnfiltered(Iterable contents) { - return Sets.newTreeSet(contents); + return newTreeSet(contents); } @Override diff --git a/android/guava-tests/test/com/google/common/collect/SetsFilterSortedSetTest.java b/android/guava-tests/test/com/google/common/collect/SetsFilterSortedSetTest.java index 6adf439ef663..7a20511e1c0f 100644 --- a/android/guava-tests/test/com/google/common/collect/SetsFilterSortedSetTest.java +++ b/android/guava-tests/test/com/google/common/collect/SetsFilterSortedSetTest.java @@ -16,6 +16,8 @@ package com.google.common.collect; +import static com.google.common.collect.Sets.newTreeSet; + import com.google.common.base.Predicate; import com.google.common.collect.FilteredCollectionsTestUtil.AbstractFilteredSortedSetTest; import java.util.SortedSet; @@ -27,7 +29,7 @@ public final class SetsFilterSortedSetTest extends AbstractFilteredSortedSetTest> { @Override SortedSet createUnfiltered(Iterable contents) { - TreeSet result = Sets.newTreeSet(contents); + TreeSet result = newTreeSet(contents); // we have to make the result not Navigable return new ForwardingSortedSet() { @Override diff --git a/android/guava-tests/test/com/google/common/collect/SetsTest.java b/android/guava-tests/test/com/google/common/collect/SetsTest.java index 37cd23ae44df..bd47dc8f67e5 100644 --- a/android/guava-tests/test/com/google/common/collect/SetsTest.java +++ b/android/guava-tests/test/com/google/common/collect/SetsTest.java @@ -18,8 +18,12 @@ import static com.google.common.collect.Iterables.unmodifiableIterable; import static com.google.common.collect.Sets.cartesianProduct; +import static com.google.common.collect.Sets.immutableEnumSet; import static com.google.common.collect.Sets.newEnumSet; import static com.google.common.collect.Sets.newHashSet; +import static com.google.common.collect.Sets.newIdentityHashSet; +import static com.google.common.collect.Sets.newLinkedHashSet; +import static com.google.common.collect.Sets.newTreeSet; import static com.google.common.collect.Sets.powerSet; import static com.google.common.collect.Sets.unmodifiableNavigableSet; import static com.google.common.collect.testing.IteratorFeature.UNMODIFIABLE; @@ -137,7 +141,7 @@ protected Set create(String[] elements) { protected Set create(AnEnum[] elements) { AnEnum[] otherElements = new AnEnum[elements.length - 1]; arraycopy(elements, 1, otherElements, 0, otherElements.length); - return Sets.immutableEnumSet(elements[0], otherElements); + return immutableEnumSet(elements[0], otherElements); } }) .named("Sets.immutableEnumSet") @@ -226,7 +230,7 @@ public Set create(String[] elements) { new TestStringSetGenerator() { @Override public NavigableSet create(String[] elements) { - NavigableSet unfiltered = Sets.newTreeSet(); + NavigableSet unfiltered = newTreeSet(); unfiltered.add("yyy"); unfiltered.addAll(ImmutableList.copyOf(elements)); unfiltered.add("zzz"); @@ -286,7 +290,7 @@ private enum SomeEnum { @SuppressWarnings("DoNotCall") public void testImmutableEnumSet() { - Set units = Sets.immutableEnumSet(SomeEnum.D, SomeEnum.B); + Set units = immutableEnumSet(SomeEnum.D, SomeEnum.B); assertThat(units).containsExactly(SomeEnum.B, SomeEnum.D).inOrder(); assertThrows(UnsupportedOperationException.class, () -> units.remove(SomeEnum.B)); @@ -296,7 +300,7 @@ public void testImmutableEnumSet() { @J2ktIncompatible @GwtIncompatible // SerializableTester public void testImmutableEnumSet_serialized() { - Set units = Sets.immutableEnumSet(SomeEnum.D, SomeEnum.B); + Set units = immutableEnumSet(SomeEnum.D, SomeEnum.B); assertThat(units).containsExactly(SomeEnum.B, SomeEnum.D).inOrder(); @@ -305,20 +309,20 @@ public void testImmutableEnumSet_serialized() { } public void testImmutableEnumSet_fromIterable() { - ImmutableSet none = Sets.immutableEnumSet(MinimalIterable.of()); + ImmutableSet none = immutableEnumSet(MinimalIterable.of()); assertThat(none).isEmpty(); - ImmutableSet one = Sets.immutableEnumSet(MinimalIterable.of(SomeEnum.B)); + ImmutableSet one = immutableEnumSet(MinimalIterable.of(SomeEnum.B)); assertThat(one).contains(SomeEnum.B); - ImmutableSet two = Sets.immutableEnumSet(MinimalIterable.of(SomeEnum.D, SomeEnum.B)); + ImmutableSet two = immutableEnumSet(MinimalIterable.of(SomeEnum.D, SomeEnum.B)); assertThat(two).containsExactly(SomeEnum.B, SomeEnum.D).inOrder(); } @GwtIncompatible @J2ktIncompatible public void testImmutableEnumSet_deserializationMakesDefensiveCopy() throws Exception { - ImmutableSet original = Sets.immutableEnumSet(SomeEnum.A, SomeEnum.B); + ImmutableSet original = immutableEnumSet(SomeEnum.A, SomeEnum.B); int handleOffset = 6; byte[] serializedForm = serializeWithBackReference(original, handleOffset); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(serializedForm)); @@ -428,19 +432,19 @@ public void testNewConcurrentHashSetFromCollection() { public void testNewLinkedHashSetEmpty() { @SuppressWarnings("UseCollectionConstructor") // test of factory method - LinkedHashSet set = Sets.newLinkedHashSet(); + LinkedHashSet set = newLinkedHashSet(); verifyLinkedHashSetContents(set, EMPTY_COLLECTION); } public void testNewLinkedHashSetFromCollection() { @SuppressWarnings("UseCollectionConstructor") // test of factory method - LinkedHashSet set = Sets.newLinkedHashSet(LONGER_LIST); + LinkedHashSet set = newLinkedHashSet(LONGER_LIST); verifyLinkedHashSetContents(set, LONGER_LIST); } public void testNewLinkedHashSetFromIterable() { LinkedHashSet set = - Sets.newLinkedHashSet( + newLinkedHashSet( new Iterable() { @Override public Iterator iterator() { @@ -461,12 +465,12 @@ public void testNewLinkedHashSetWithExpectedSizeLarge() { } public void testNewTreeSetEmpty() { - TreeSet set = Sets.newTreeSet(); + TreeSet set = newTreeSet(); verifySortedSetContents(set, EMPTY_COLLECTION, null); } public void testNewTreeSetEmptyDerived() { - TreeSet set = Sets.newTreeSet(); + TreeSet set = newTreeSet(); assertTrue(set.isEmpty()); set.add(new Derived("foo")); set.add(new Derived("bar")); @@ -474,7 +478,7 @@ public void testNewTreeSetEmptyDerived() { } public void testNewTreeSetEmptyNonGeneric() { - TreeSet set = Sets.newTreeSet(); + TreeSet set = newTreeSet(); assertTrue(set.isEmpty()); set.add(new LegacyComparable("foo")); set.add(new LegacyComparable("bar")); @@ -484,37 +488,37 @@ public void testNewTreeSetEmptyNonGeneric() { } public void testNewTreeSetFromCollection() { - TreeSet set = Sets.newTreeSet(SOME_COLLECTION); + TreeSet set = newTreeSet(SOME_COLLECTION); verifySortedSetContents(set, SOME_COLLECTION, null); } public void testNewTreeSetFromIterable() { - TreeSet set = Sets.newTreeSet(SOME_ITERABLE); + TreeSet set = newTreeSet(SOME_ITERABLE); verifySortedSetContents(set, SOME_ITERABLE, null); } public void testNewTreeSetFromIterableDerived() { Iterable iterable = asList(new Derived("foo"), new Derived("bar")); - TreeSet set = Sets.newTreeSet(iterable); + TreeSet set = newTreeSet(iterable); assertThat(set).containsExactly(new Derived("bar"), new Derived("foo")).inOrder(); } public void testNewTreeSetFromIterableNonGeneric() { Iterable iterable = asList(new LegacyComparable("foo"), new LegacyComparable("bar")); - TreeSet set = Sets.newTreeSet(iterable); + TreeSet set = newTreeSet(iterable); assertThat(set) .containsExactly(new LegacyComparable("bar"), new LegacyComparable("foo")) .inOrder(); } public void testNewTreeSetEmptyWithComparator() { - TreeSet set = Sets.newTreeSet(SOME_COMPARATOR); + TreeSet set = newTreeSet(SOME_COMPARATOR); verifySortedSetContents(set, EMPTY_COLLECTION, SOME_COMPARATOR); } public void testNewIdentityHashSet() { - Set set = Sets.newIdentityHashSet(); + Set set = newIdentityHashSet(); MyInteger value1 = new MyInteger(12357); MyInteger value2 = new MyInteger(12357); assertTrue(set.add(value1)); @@ -1058,7 +1062,7 @@ private static void verifySetContents(Set set, Iterable contents) { @GwtIncompatible // NavigableSet public void testUnmodifiableNavigableSet() { - TreeSet mod = Sets.newTreeSet(); + TreeSet mod = newTreeSet(); mod.add(1); mod.add(2); mod.add(3); diff --git a/android/guava-tests/test/com/google/common/collect/SortedIterablesTest.java b/android/guava-tests/test/com/google/common/collect/SortedIterablesTest.java index 9b1d04bba477..8f0f507f50c2 100644 --- a/android/guava-tests/test/com/google/common/collect/SortedIterablesTest.java +++ b/android/guava-tests/test/com/google/common/collect/SortedIterablesTest.java @@ -14,6 +14,8 @@ package com.google.common.collect; +import static com.google.common.collect.Sets.newTreeSet; + import com.google.common.annotations.GwtCompatible; import junit.framework.TestCase; import org.jspecify.annotations.NullMarked; @@ -27,14 +29,14 @@ @NullMarked public class SortedIterablesTest extends TestCase { public void testSameComparator() { - assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), Sets.newTreeSet())); + assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), newTreeSet())); assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), Maps.newTreeMap().keySet())); assertTrue( SortedIterables.hasSameComparator( - Ordering.natural().reverse(), Sets.newTreeSet(Ordering.natural().reverse()))); + Ordering.natural().reverse(), newTreeSet(Ordering.natural().reverse()))); } public void testComparator() { - assertEquals(Ordering.natural(), SortedIterables.comparator(Sets.newTreeSet())); + assertEquals(Ordering.natural(), SortedIterables.comparator(newTreeSet())); } } diff --git a/android/guava-tests/test/com/google/common/collect/TreeMultisetTest.java b/android/guava-tests/test/com/google/common/collect/TreeMultisetTest.java index 862c06f922ae..561d358cdc19 100644 --- a/android/guava-tests/test/com/google/common/collect/TreeMultisetTest.java +++ b/android/guava-tests/test/com/google/common/collect/TreeMultisetTest.java @@ -17,6 +17,7 @@ package com.google.common.collect; import static com.google.common.collect.BoundType.CLOSED; +import static com.google.common.collect.Sets.newTreeSet; import static com.google.common.truth.Truth.assertThat; import static java.util.Arrays.asList; import static java.util.Collections.sort; @@ -116,7 +117,7 @@ protected Set create(String[] elements) { @Override public List order(List insertionOrder) { - return new ArrayList<>(Sets.newTreeSet(insertionOrder)); + return new ArrayList<>(newTreeSet(insertionOrder)); } }) .named("TreeMultiset[Ordering.natural].elementSet") diff --git a/android/guava-tests/test/com/google/common/eventbus/DispatcherTest.java b/android/guava-tests/test/com/google/common/eventbus/DispatcherTest.java index 9d8eed2e8252..fb96b43d0c33 100644 --- a/android/guava-tests/test/com/google/common/eventbus/DispatcherTest.java +++ b/android/guava-tests/test/com/google/common/eventbus/DispatcherTest.java @@ -17,9 +17,9 @@ package com.google.common.eventbus; import static com.google.common.truth.Truth.assertThat; +import static com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly; import com.google.common.collect.ImmutableList; -import com.google.common.util.concurrent.Uninterruptibles; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.CountDownLatch; @@ -114,7 +114,7 @@ public void testLegacyAsyncDispatcher() { }) .start(); - Uninterruptibles.awaitUninterruptibly(latch); + awaitUninterruptibly(latch); // See Dispatcher.LegacyAsyncDispatcher for an explanation of why there aren't really any // useful testable guarantees about the behavior of that dispatcher in a multithreaded diff --git a/android/guava-tests/test/com/google/common/graph/GraphsTest.java b/android/guava-tests/test/com/google/common/graph/GraphsTest.java index 46f9531999b1..633051df6bf6 100644 --- a/android/guava-tests/test/com/google/common/graph/GraphsTest.java +++ b/android/guava-tests/test/com/google/common/graph/GraphsTest.java @@ -16,6 +16,7 @@ package com.google.common.graph; +import static com.google.common.graph.AbstractNetworkTest.validateNetwork; import static com.google.common.graph.Graphs.TransitiveClosureSelfLoopStrategy.ADD_SELF_LOOPS_ALWAYS; import static com.google.common.graph.Graphs.TransitiveClosureSelfLoopStrategy.ADD_SELF_LOOPS_FOR_CYCLES; import static com.google.common.graph.Graphs.copyOf; @@ -456,7 +457,7 @@ public void transpose_directedNetwork() { Network transpose = transpose(directedGraph); assertThat(transpose).isEqualTo(expectedTranspose); assertThat(transpose(transpose)).isSameInstanceAs(directedGraph); - AbstractNetworkTest.validateNetwork(transpose); + validateNetwork(transpose); assertThat(transpose.edgesConnecting(N1, N2)).isEmpty(); assertThat(transpose.edgeConnectingOrNull(N1, N2)).isNull(); @@ -470,8 +471,7 @@ public void transpose_directedNetwork() { // View should be updated. assertThat(transpose.edgesConnecting(N1, N2)).containsExactly(E21); assertThat(transpose.edgeConnectingOrNull(N1, N2)).isEqualTo(E21); - - AbstractNetworkTest.validateNetwork(transpose); + validateNetwork(transpose); } @Test diff --git a/android/guava-tests/test/com/google/common/graph/NetworkMutationTest.java b/android/guava-tests/test/com/google/common/graph/NetworkMutationTest.java index 1ba3eaf053f9..6478aef17297 100644 --- a/android/guava-tests/test/com/google/common/graph/NetworkMutationTest.java +++ b/android/guava-tests/test/com/google/common/graph/NetworkMutationTest.java @@ -16,6 +16,7 @@ package com.google.common.graph; +import static com.google.common.graph.AbstractNetworkTest.validateNetwork; import static com.google.common.truth.Truth.assertThat; import static java.util.Collections.shuffle; @@ -57,7 +58,7 @@ private static void testNetworkMutation(NetworkBuilder assertThat(network.nodes()).isEmpty(); assertThat(network.edges()).isEmpty(); - AbstractNetworkTest.validateNetwork(network); + validateNetwork(network); while (network.nodes().size() < NUM_NODES) { network.addNode(gen.nextInt(NODE_POOL_SIZE)); @@ -74,7 +75,7 @@ private static void testNetworkMutation(NetworkBuilder assertThat(network.nodes()).hasSize(NUM_NODES); assertThat(network.edges()).hasSize(NUM_EDGES); - AbstractNetworkTest.validateNetwork(network); + validateNetwork(network); shuffle(edgeList, gen); int numEdgesToRemove = gen.nextInt(NUM_EDGES); @@ -85,7 +86,7 @@ private static void testNetworkMutation(NetworkBuilder assertThat(network.nodes()).hasSize(NUM_NODES); assertThat(network.edges()).hasSize(NUM_EDGES - numEdgesToRemove); - AbstractNetworkTest.validateNetwork(network); + validateNetwork(network); shuffle(nodeList, gen); int numNodesToRemove = gen.nextInt(NUM_NODES); @@ -95,7 +96,7 @@ private static void testNetworkMutation(NetworkBuilder assertThat(network.nodes()).hasSize(NUM_NODES - numNodesToRemove); // Number of edges remaining is unknown (node's incident edges have been removed). - AbstractNetworkTest.validateNetwork(network); + validateNetwork(network); for (int i = numNodesToRemove; i < NUM_NODES; ++i) { assertThat(network.removeNode(nodeList.get(i))).isTrue(); @@ -103,7 +104,7 @@ private static void testNetworkMutation(NetworkBuilder assertThat(network.nodes()).isEmpty(); assertThat(network.edges()).isEmpty(); // no edges can remain if there's no nodes - AbstractNetworkTest.validateNetwork(network); + validateNetwork(network); shuffle(nodeList, gen); for (Integer node : nodeList) { @@ -119,7 +120,7 @@ private static void testNetworkMutation(NetworkBuilder assertThat(network.nodes()).hasSize(NUM_NODES); assertThat(network.edges()).hasSize(NUM_EDGES); - AbstractNetworkTest.validateNetwork(network); + validateNetwork(network); } } diff --git a/android/guava-tests/test/com/google/common/graph/ValueGraphTest.java b/android/guava-tests/test/com/google/common/graph/ValueGraphTest.java index c057bcbfd460..9e009e10f7ae 100644 --- a/android/guava-tests/test/com/google/common/graph/ValueGraphTest.java +++ b/android/guava-tests/test/com/google/common/graph/ValueGraphTest.java @@ -16,6 +16,7 @@ package com.google.common.graph; +import static com.google.common.graph.AbstractNetworkTest.validateNetwork; import static com.google.common.graph.GraphConstants.ENDPOINTS_MISMATCH; import static com.google.common.graph.TestUtil.assertStronglyEquivalent; import static com.google.common.truth.Truth.assertThat; @@ -57,7 +58,7 @@ public void validateGraphState() { assertThat(graph.allowsSelfLoops()).isEqualTo(asGraph.allowsSelfLoops()); Network> asNetwork = graph.asNetwork(); - AbstractNetworkTest.validateNetwork(asNetwork); + validateNetwork(asNetwork); assertThat(graph.nodes()).isEqualTo(asNetwork.nodes()); assertThat(graph.edges()).hasSize(asNetwork.edges().size()); assertThat(graph.nodeOrder()).isEqualTo(asNetwork.nodeOrder()); diff --git a/android/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java b/android/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java index 1d6a1bd7c3ca..2c9fa8febf7c 100644 --- a/android/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java +++ b/android/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java @@ -16,13 +16,13 @@ package com.google.common.hash; +import static com.google.common.collect.Iterables.concat; import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.UTF_16LE; import static java.util.Collections.singleton; import static org.junit.Assert.assertThrows; import com.google.common.annotations.J2ktIncompatible; -import com.google.common.collect.Iterables; import com.google.common.hash.HashTestUtils.RandomHasherAction; import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; @@ -150,7 +150,7 @@ public void testExhaustive() throws Exception { Control control = new Control(); Hasher controlSink = control.newHasher(1024); - Iterable sinksAndControl = Iterables.concat(sinks, singleton(controlSink)); + Iterable sinksAndControl = concat(sinks, singleton(controlSink)); for (int insertion = 0; insertion < totalInsertions; insertion++) { RandomHasherAction.pickAtRandom(random).performAction(random, sinksAndControl); } diff --git a/android/guava-tests/test/com/google/common/hash/BloomFilterTest.java b/android/guava-tests/test/com/google/common/hash/BloomFilterTest.java index 73e57e4b7e51..8cb1b82b8472 100644 --- a/android/guava-tests/test/com/google/common/hash/BloomFilterTest.java +++ b/android/guava-tests/test/com/google/common/hash/BloomFilterTest.java @@ -25,6 +25,7 @@ import static com.google.common.testing.SerializableTester.reserializeAndAssert; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; +import static com.google.common.util.concurrent.Uninterruptibles.joinUninterruptibly; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertThrows; @@ -37,7 +38,6 @@ import com.google.common.primitives.Ints; import com.google.common.testing.EqualsTester; import com.google.common.testing.NullPointerTester; -import com.google.common.util.concurrent.Uninterruptibles; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.math.RoundingMode; @@ -602,7 +602,7 @@ private static List runThreadsAndReturnExceptions(int numThreads, Run t.start(); } for (Thread t : threads) { - Uninterruptibles.joinUninterruptibly(t); + joinUninterruptibly(t); } return exceptions; } diff --git a/android/guava-tests/test/com/google/common/hash/FarmHashFingerprint64Test.java b/android/guava-tests/test/com/google/common/hash/FarmHashFingerprint64Test.java index 33684349671d..06555c9764ef 100644 --- a/android/guava-tests/test/com/google/common/hash/FarmHashFingerprint64Test.java +++ b/android/guava-tests/test/com/google/common/hash/FarmHashFingerprint64Test.java @@ -16,13 +16,13 @@ package com.google.common.hash; +import static com.google.common.base.Strings.repeat; import static com.google.common.hash.Hashing.farmHashFingerprint64; import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.ISO_8859_1; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.asList; -import com.google.common.base.Strings; import junit.framework.TestCase; import org.jspecify.annotations.NullUnmarked; @@ -42,9 +42,9 @@ public class FarmHashFingerprint64Test extends TestCase { public void testReallySimpleFingerprints() { assertEquals(8581389452482819506L, fingerprint("test".getBytes(UTF_8))); // 32 characters long - assertEquals(-4196240717365766262L, fingerprint(Strings.repeat("test", 8).getBytes(UTF_8))); + assertEquals(-4196240717365766262L, fingerprint(repeat("test", 8).getBytes(UTF_8))); // 256 characters long - assertEquals(3500507768004279527L, fingerprint(Strings.repeat("test", 64).getBytes(UTF_8))); + assertEquals(3500507768004279527L, fingerprint(repeat("test", 64).getBytes(UTF_8))); } public void testStringsConsistency() { diff --git a/android/guava-tests/test/com/google/common/hash/Fingerprint2011Test.java b/android/guava-tests/test/com/google/common/hash/Fingerprint2011Test.java index a6057e13f539..83b9b165641f 100644 --- a/android/guava-tests/test/com/google/common/hash/Fingerprint2011Test.java +++ b/android/guava-tests/test/com/google/common/hash/Fingerprint2011Test.java @@ -2,6 +2,7 @@ package com.google.common.hash; +import static com.google.common.base.Strings.repeat; import static com.google.common.hash.Hashing.fingerprint2011; import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.ISO_8859_1; @@ -9,7 +10,6 @@ import static java.util.Arrays.asList; import com.google.common.annotations.J2ktIncompatible; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Ordering; import com.google.common.primitives.UnsignedLong; @@ -67,9 +67,9 @@ public class Fingerprint2011Test extends TestCase { public void testReallySimpleFingerprints() { assertEquals(8473225671271759044L, fingerprint("test".getBytes(UTF_8))); // 32 characters long - assertEquals(7345148637025587076L, fingerprint(Strings.repeat("test", 8).getBytes(UTF_8))); + assertEquals(7345148637025587076L, fingerprint(repeat("test", 8).getBytes(UTF_8))); // 256 characters long - assertEquals(4904844928629814570L, fingerprint(Strings.repeat("test", 64).getBytes(UTF_8))); + assertEquals(4904844928629814570L, fingerprint(repeat("test", 64).getBytes(UTF_8))); } public void testStringsConsistency() { diff --git a/android/guava-tests/test/com/google/common/io/ByteStreamsTest.java b/android/guava-tests/test/com/google/common/io/ByteStreamsTest.java index 6db73b08d81e..36f1cc157c40 100644 --- a/android/guava-tests/test/com/google/common/io/ByteStreamsTest.java +++ b/android/guava-tests/test/com/google/common/io/ByteStreamsTest.java @@ -16,6 +16,8 @@ package com.google.common.io; +import static com.google.common.io.ByteStreams.newDataInput; +import static com.google.common.io.ByteStreams.newDataOutput; import static com.google.common.truth.Truth.assertThat; import static java.lang.System.arraycopy; import static java.nio.charset.StandardCharsets.US_ASCII; @@ -135,26 +137,26 @@ private static void skipHelper(long n, int expect, InputStream in) throws IOExce public void testNewDataInput_empty() { byte[] b = new byte[0]; - ByteArrayDataInput in = ByteStreams.newDataInput(b); + ByteArrayDataInput in = newDataInput(b); assertThrows(IllegalStateException.class, in::readInt); } public void testNewDataInput_normal() { - ByteArrayDataInput in = ByteStreams.newDataInput(bytes); + ByteArrayDataInput in = newDataInput(bytes); assertEquals(0x12345678, in.readInt()); assertEquals(0x76543210, in.readInt()); assertThrows(IllegalStateException.class, in::readInt); } public void testNewDataInput_readFully() { - ByteArrayDataInput in = ByteStreams.newDataInput(bytes); + ByteArrayDataInput in = newDataInput(bytes); byte[] actual = new byte[bytes.length]; in.readFully(actual); assertThat(actual).isEqualTo(bytes); } public void testNewDataInput_readFullyAndThenSome() { - ByteArrayDataInput in = ByteStreams.newDataInput(bytes); + ByteArrayDataInput in = newDataInput(bytes); byte[] actual = new byte[bytes.length * 2]; IllegalStateException ex = assertThrows(IllegalStateException.class, () -> in.readFully(actual)); @@ -162,7 +164,7 @@ public void testNewDataInput_readFullyAndThenSome() { } public void testNewDataInput_readFullyWithOffset() { - ByteArrayDataInput in = ByteStreams.newDataInput(bytes); + ByteArrayDataInput in = newDataInput(bytes); byte[] actual = new byte[4]; in.readFully(actual, 2, 2); assertEquals(0, actual[0]); @@ -173,8 +175,7 @@ public void testNewDataInput_readFullyWithOffset() { public void testNewDataInput_readLine() { ByteArrayDataInput in = - ByteStreams.newDataInput( - "This is a line\r\nThis too\rand this\nand also this".getBytes(UTF_8)); + newDataInput("This is a line\r\nThis too\rand this\nand also this".getBytes(UTF_8)); assertThat(in.readLine()).isEqualTo("This is a line"); assertThat(in.readLine()).isEqualTo("This too"); assertThat(in.readLine()).isEqualTo("and this"); @@ -183,14 +184,14 @@ public void testNewDataInput_readLine() { public void testNewDataInput_readFloat() { byte[] data = {0x12, 0x34, 0x56, 0x78, 0x76, 0x54, 0x32, 0x10}; - ByteArrayDataInput in = ByteStreams.newDataInput(data); + ByteArrayDataInput in = newDataInput(data); assertThat(in.readFloat()).isEqualTo(Float.intBitsToFloat(0x12345678)); assertThat(in.readFloat()).isEqualTo(Float.intBitsToFloat(0x76543210)); } public void testNewDataInput_readDouble() { byte[] data = {0x12, 0x34, 0x56, 0x78, 0x76, 0x54, 0x32, 0x10}; - ByteArrayDataInput in = ByteStreams.newDataInput(data); + ByteArrayDataInput in = newDataInput(data); assertThat(in.readDouble()).isEqualTo(Double.longBitsToDouble(0x1234567876543210L)); } @@ -198,13 +199,13 @@ public void testNewDataInput_readUTF() { byte[] data = new byte[17]; data[1] = 15; arraycopy("Kilroy was here".getBytes(UTF_8), 0, data, 2, 15); - ByteArrayDataInput in = ByteStreams.newDataInput(data); + ByteArrayDataInput in = newDataInput(data); assertThat(in.readUTF()).isEqualTo("Kilroy was here"); } public void testNewDataInput_readChar() { byte[] data = "qed".getBytes(UTF_16BE); - ByteArrayDataInput in = ByteStreams.newDataInput(data); + ByteArrayDataInput in = newDataInput(data); assertEquals('q', in.readChar()); assertEquals('e', in.readChar()); assertEquals('d', in.readChar()); @@ -212,7 +213,7 @@ public void testNewDataInput_readChar() { public void testNewDataInput_readUnsignedShort() { byte[] data = {0, 0, 0, 1, (byte) 0xFF, (byte) 0xFF, 0x12, 0x34}; - ByteArrayDataInput in = ByteStreams.newDataInput(data); + ByteArrayDataInput in = newDataInput(data); assertEquals(0, in.readUnsignedShort()); assertEquals(1, in.readUnsignedShort()); assertEquals(65535, in.readUnsignedShort()); @@ -221,17 +222,17 @@ public void testNewDataInput_readUnsignedShort() { public void testNewDataInput_readLong() { byte[] data = {0x12, 0x34, 0x56, 0x78, 0x76, 0x54, 0x32, 0x10}; - ByteArrayDataInput in = ByteStreams.newDataInput(data); + ByteArrayDataInput in = newDataInput(data); assertEquals(0x1234567876543210L, in.readLong()); } public void testNewDataInput_readBoolean() { - ByteArrayDataInput in = ByteStreams.newDataInput(bytes); + ByteArrayDataInput in = newDataInput(bytes); assertTrue(in.readBoolean()); } public void testNewDataInput_readByte() { - ByteArrayDataInput in = ByteStreams.newDataInput(bytes); + ByteArrayDataInput in = newDataInput(bytes); for (byte aByte : bytes) { assertEquals(aByte, in.readByte()); } @@ -240,7 +241,7 @@ public void testNewDataInput_readByte() { } public void testNewDataInput_readUnsignedByte() { - ByteArrayDataInput in = ByteStreams.newDataInput(bytes); + ByteArrayDataInput in = newDataInput(bytes); for (byte aByte : bytes) { assertEquals(aByte, in.readUnsignedByte()); } @@ -250,70 +251,70 @@ public void testNewDataInput_readUnsignedByte() { } public void testNewDataInput_offset() { - ByteArrayDataInput in = ByteStreams.newDataInput(bytes, 2); + ByteArrayDataInput in = newDataInput(bytes, 2); assertEquals(0x56787654, in.readInt()); assertThrows(IllegalStateException.class, in::readInt); } public void testNewDataInput_skip() { - ByteArrayDataInput in = ByteStreams.newDataInput(new byte[2]); + ByteArrayDataInput in = newDataInput(new byte[2]); assertEquals(2, in.skipBytes(2)); assertEquals(0, in.skipBytes(1)); } public void testNewDataInput_bais() { ByteArrayInputStream bais = new ByteArrayInputStream(new byte[] {0x12, 0x34, 0x56, 0x78}); - ByteArrayDataInput in = ByteStreams.newDataInput(bais); + ByteArrayDataInput in = newDataInput(bais); assertEquals(0x12345678, in.readInt()); } public void testNewDataOutput_empty() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); assertThat(out.toByteArray()).isEmpty(); } public void testNewDataOutput_writeInt() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeInt(0x12345678); out.writeInt(0x76543210); assertThat(out.toByteArray()).isEqualTo(bytes); } public void testNewDataOutput_sized() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(4); + ByteArrayDataOutput out = newDataOutput(4); out.writeInt(0x12345678); out.writeInt(0x76543210); assertThat(out.toByteArray()).isEqualTo(bytes); } public void testNewDataOutput_writeLong() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeLong(0x1234567876543210L); assertThat(out.toByteArray()).isEqualTo(bytes); } public void testNewDataOutput_writeByteArray() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.write(bytes); assertThat(out.toByteArray()).isEqualTo(bytes); } public void testNewDataOutput_writeByte() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.write(0x12); out.writeByte(0x34); assertThat(out.toByteArray()).isEqualTo(new byte[] {0x12, 0x34}); } public void testNewDataOutput_writeByteOffset() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.write(bytes, 4, 2); byte[] expected = {bytes[4], bytes[5]}; assertThat(out.toByteArray()).isEqualTo(expected); } public void testNewDataOutput_writeBoolean() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeBoolean(true); out.writeBoolean(false); byte[] expected = {(byte) 1, (byte) 0}; @@ -321,7 +322,7 @@ public void testNewDataOutput_writeBoolean() { } public void testNewDataOutput_writeChar() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeChar('a'); assertThat(out.toByteArray()).isEqualTo(new byte[] {0, 97}); } @@ -331,7 +332,7 @@ public void testNewDataOutput_writeChar() { new byte[] {-2, -1, 0, 114, 0, -55, 0, 115, 0, 117, 0, 109, 0, -55}; public void testNewDataOutput_writeChars() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeChars("r\u00C9sum\u00C9"); // need to remove byte order mark before comparing byte[] expected = Arrays.copyOfRange(utf16ExpectedWithBom, 2, 14); @@ -346,7 +347,7 @@ public void testUtf16Expected() { } public void testNewDataOutput_writeUTF() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeUTF("r\u00C9sum\u00C9"); byte[] expected = "r\u00C9sum\u00C9".getBytes(UTF_8); byte[] actual = out.toByteArray(); @@ -357,19 +358,19 @@ public void testNewDataOutput_writeUTF() { } public void testNewDataOutput_writeShort() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeShort(0x1234); assertThat(out.toByteArray()).isEqualTo(new byte[] {0x12, 0x34}); } public void testNewDataOutput_writeDouble() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeDouble(Double.longBitsToDouble(0x1234567876543210L)); assertThat(out.toByteArray()).isEqualTo(bytes); } public void testNewDataOutput_writeFloat() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeFloat(Float.intBitsToFloat(0x12345678)); out.writeFloat(Float.intBitsToFloat(0x76543210)); assertThat(out.toByteArray()).isEqualTo(bytes); @@ -377,7 +378,7 @@ public void testNewDataOutput_writeFloat() { public void testNewDataOutput_baos() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ByteArrayDataOutput out = ByteStreams.newDataOutput(baos); + ByteArrayDataOutput out = newDataOutput(baos); out.writeInt(0x12345678); assertEquals(4, baos.size()); assertThat(baos.toByteArray()).isEqualTo(new byte[] {0x12, 0x34, 0x56, 0x78}); diff --git a/android/guava-tests/test/com/google/common/io/CharStreamsTest.java b/android/guava-tests/test/com/google/common/io/CharStreamsTest.java index 9e130a16e3e6..eb0f1b8792d7 100644 --- a/android/guava-tests/test/com/google/common/io/CharStreamsTest.java +++ b/android/guava-tests/test/com/google/common/io/CharStreamsTest.java @@ -16,10 +16,10 @@ package com.google.common.io; +import static com.google.common.base.Strings.repeat; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import java.io.EOFException; import java.io.FilterReader; @@ -230,7 +230,7 @@ public void testCopy_toWriter_fromReadable() throws IOException { @SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8 public void testCopyWithReaderThatDoesNotFillBuffer() throws IOException { // need a long enough string for the buffer to hit 0 remaining before the copy completes - String string = Strings.repeat("0123456789", 100); + String string = repeat("0123456789", 100); StringBuilder b = new StringBuilder(); // the main assertion of this test is here... the copy will fail if the buffer size goes down // each time it is not filled completely diff --git a/android/guava-tests/test/com/google/common/io/FilesTest.java b/android/guava-tests/test/com/google/common/io/FilesTest.java index ddbbccc1ffc8..52b5c02ba9e9 100644 --- a/android/guava-tests/test/com/google/common/io/FilesTest.java +++ b/android/guava-tests/test/com/google/common/io/FilesTest.java @@ -17,6 +17,7 @@ package com.google.common.io; import static com.google.common.hash.Hashing.sha512; +import static com.google.common.primitives.Bytes.asList; import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.US_ASCII; import static java.nio.charset.StandardCharsets.UTF_16LE; @@ -24,7 +25,6 @@ import static org.junit.Assert.assertThrows; import com.google.common.collect.ImmutableList; -import com.google.common.primitives.Bytes; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; @@ -631,7 +631,7 @@ public byte[] getResult() { File asciiFile = getTestFile("ascii.txt"); byte[] result = Files.readBytes(asciiFile, processor); - assertEquals(Bytes.asList(Files.toByteArray(asciiFile)), Bytes.asList(result)); + assertEquals(asList(Files.toByteArray(asciiFile)), asList(result)); } public void testReadBytes_returnFalse() throws IOException { diff --git a/android/guava-tests/test/com/google/common/io/LittleEndianDataInputStreamTest.java b/android/guava-tests/test/com/google/common/io/LittleEndianDataInputStreamTest.java index 5f50d17c6aa6..d94d728bd273 100644 --- a/android/guava-tests/test/com/google/common/io/LittleEndianDataInputStreamTest.java +++ b/android/guava-tests/test/com/google/common/io/LittleEndianDataInputStreamTest.java @@ -16,10 +16,10 @@ package com.google.common.io; +import static com.google.common.primitives.Bytes.asList; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; -import com.google.common.primitives.Bytes; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInput; @@ -73,7 +73,7 @@ public void testReadFully() throws IOException { DataInput in = new LittleEndianDataInputStream(new ByteArrayInputStream(data)); byte[] b = new byte[data.length]; in.readFully(b); - assertEquals(Bytes.asList(data), Bytes.asList(b)); + assertEquals(asList(data), asList(b)); } public void testReadUnsignedByte_eof() throws IOException { diff --git a/android/guava-tests/test/com/google/common/io/LittleEndianDataOutputStreamTest.java b/android/guava-tests/test/com/google/common/io/LittleEndianDataOutputStreamTest.java index e7c2fd32e64f..634d50b63a2d 100644 --- a/android/guava-tests/test/com/google/common/io/LittleEndianDataOutputStreamTest.java +++ b/android/guava-tests/test/com/google/common/io/LittleEndianDataOutputStreamTest.java @@ -16,10 +16,10 @@ package com.google.common.io; +import static com.google.common.primitives.Bytes.asList; import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.ISO_8859_1; -import com.google.common.primitives.Bytes; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInput; @@ -145,6 +145,6 @@ public void testWriteChars() throws IOException { } private static void assertEquals(byte[] expected, byte[] actual) { - assertEquals(Bytes.asList(expected), Bytes.asList(actual)); + assertEquals(asList(expected), asList(actual)); } } diff --git a/android/guava-tests/test/com/google/common/math/BigIntegerMathTest.java b/android/guava-tests/test/com/google/common/math/BigIntegerMathTest.java index 75daea933205..204a541e6f1a 100644 --- a/android/guava-tests/test/com/google/common/math/BigIntegerMathTest.java +++ b/android/guava-tests/test/com/google/common/math/BigIntegerMathTest.java @@ -16,6 +16,7 @@ package com.google.common.math; +import static com.google.common.math.BigIntegerMath.sqrt; import static com.google.common.math.MathTesting.ALL_BIGINTEGER_CANDIDATES; import static com.google.common.math.MathTesting.ALL_ROUNDING_MODES; import static com.google.common.math.MathTesting.ALL_SAFE_ROUNDING_MODES; @@ -106,8 +107,7 @@ public void testFloorPowerOfTwoZero() { @GwtIncompatible // TODO public void testConstantSqrt2PrecomputedBits() { assertEquals( - BigIntegerMath.sqrt( - BigInteger.ZERO.setBit(2 * BigIntegerMath.SQRT2_PRECOMPUTE_THRESHOLD + 1), FLOOR), + sqrt(BigInteger.ZERO.setBit(2 * BigIntegerMath.SQRT2_PRECOMPUTE_THRESHOLD + 1), FLOOR), BigIntegerMath.SQRT2_PRECOMPUTED_BITS); } @@ -298,15 +298,14 @@ public void testLog10TrivialOnPowerOf10() { @GwtIncompatible // TODO public void testSqrtZeroAlwaysZero() { for (RoundingMode mode : ALL_ROUNDING_MODES) { - assertEquals(ZERO, BigIntegerMath.sqrt(ZERO, mode)); + assertEquals(ZERO, sqrt(ZERO, mode)); } } @GwtIncompatible // TODO public void testSqrtNegativeAlwaysThrows() { for (RoundingMode mode : ALL_ROUNDING_MODES) { - assertThrows( - IllegalArgumentException.class, () -> BigIntegerMath.sqrt(BigInteger.valueOf(-1), mode)); + assertThrows(IllegalArgumentException.class, () -> sqrt(BigInteger.valueOf(-1), mode)); } } @@ -314,7 +313,7 @@ public void testSqrtNegativeAlwaysThrows() { public void testSqrtFloor() { for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) { for (RoundingMode mode : asList(FLOOR, DOWN)) { - BigInteger result = BigIntegerMath.sqrt(x, mode); + BigInteger result = sqrt(x, mode); assertThat(result).isGreaterThan(ZERO); assertThat(result.pow(2)).isAtMost(x); assertThat(result.add(ONE).pow(2)).isGreaterThan(x); @@ -326,7 +325,7 @@ public void testSqrtFloor() { public void testSqrtCeiling() { for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) { for (RoundingMode mode : asList(CEILING, UP)) { - BigInteger result = BigIntegerMath.sqrt(x, mode); + BigInteger result = sqrt(x, mode); assertThat(result).isGreaterThan(ZERO); assertThat(result.pow(2)).isAtLeast(x); assertTrue(result.signum() == 0 || result.subtract(ONE).pow(2).compareTo(x) < 0); @@ -338,11 +337,11 @@ public void testSqrtCeiling() { @GwtIncompatible // TODO public void testSqrtExact() { for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) { - BigInteger floor = BigIntegerMath.sqrt(x, FLOOR); + BigInteger floor = sqrt(x, FLOOR); // We only expect an exception if x was not a perfect square. boolean isPerfectSquare = floor.pow(2).equals(x); try { - assertEquals(floor, BigIntegerMath.sqrt(x, UNNECESSARY)); + assertEquals(floor, sqrt(x, UNNECESSARY)); assertTrue(isPerfectSquare); } catch (ArithmeticException e) { assertFalse(isPerfectSquare); @@ -353,7 +352,7 @@ public void testSqrtExact() { @GwtIncompatible // TODO public void testSqrtHalfUp() { for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) { - BigInteger result = BigIntegerMath.sqrt(x, HALF_UP); + BigInteger result = sqrt(x, HALF_UP); BigInteger plusHalfSquared = result.pow(2).add(result).shiftLeft(2).add(ONE); BigInteger x4 = x.shiftLeft(2); // sqrt(x) < result + 0.5, so 4 * x < (result + 0.5)^2 * 4 @@ -369,7 +368,7 @@ public void testSqrtHalfUp() { @GwtIncompatible // TODO public void testSqrtHalfDown() { for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) { - BigInteger result = BigIntegerMath.sqrt(x, HALF_DOWN); + BigInteger result = sqrt(x, HALF_DOWN); BigInteger plusHalfSquared = result.pow(2).add(result).shiftLeft(2).add(ONE); BigInteger x4 = x.shiftLeft(2); // sqrt(x) <= result + 0.5, so 4 * x <= (result + 0.5)^2 * 4 @@ -386,11 +385,11 @@ public void testSqrtHalfDown() { @GwtIncompatible // TODO public void testSqrtHalfEven() { for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) { - BigInteger halfEven = BigIntegerMath.sqrt(x, HALF_EVEN); + BigInteger halfEven = sqrt(x, HALF_EVEN); // Now figure out what rounding mode we should behave like (it depends if FLOOR was // odd/even). - boolean floorWasOdd = BigIntegerMath.sqrt(x, FLOOR).testBit(0); - assertEquals(BigIntegerMath.sqrt(x, floorWasOdd ? HALF_UP : HALF_DOWN), halfEven); + boolean floorWasOdd = sqrt(x, FLOOR).testBit(0); + assertEquals(sqrt(x, floorWasOdd ? HALF_UP : HALF_DOWN), halfEven); } } diff --git a/android/guava-tests/test/com/google/common/math/DoubleMathTest.java b/android/guava-tests/test/com/google/common/math/DoubleMathTest.java index 91716044745e..c599dbe24525 100644 --- a/android/guava-tests/test/com/google/common/math/DoubleMathTest.java +++ b/android/guava-tests/test/com/google/common/math/DoubleMathTest.java @@ -16,8 +16,10 @@ package com.google.common.math; +import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.Iterables.get; import static com.google.common.collect.Iterables.size; +import static com.google.common.math.DoubleMath.isMathematicalInteger; import static com.google.common.math.MathTesting.ALL_DOUBLE_CANDIDATES; import static com.google.common.math.MathTesting.ALL_ROUNDING_MODES; import static com.google.common.math.MathTesting.ALL_SAFE_ROUNDING_MODES; @@ -44,7 +46,6 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; import com.google.common.primitives.Doubles; import com.google.common.testing.NullPointerTester; import java.math.BigDecimal; @@ -468,21 +469,21 @@ private strictfp double trueLog2(double d) { @GwtIncompatible // DoubleMath.isMathematicalInteger public void testIsMathematicalIntegerIntegral() { for (double d : INTEGRAL_DOUBLE_CANDIDATES) { - assertTrue(DoubleMath.isMathematicalInteger(d)); + assertTrue(isMathematicalInteger(d)); } } @GwtIncompatible // DoubleMath.isMathematicalInteger public void testIsMathematicalIntegerFractional() { for (double d : FRACTIONAL_DOUBLE_CANDIDATES) { - assertFalse(DoubleMath.isMathematicalInteger(d)); + assertFalse(isMathematicalInteger(d)); } } @GwtIncompatible // DoubleMath.isMathematicalInteger public void testIsMathematicalIntegerNotFinite() { for (double d : asList(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN)) { - assertFalse(DoubleMath.isMathematicalInteger(d)); + assertFalse(isMathematicalInteger(d)); } } @@ -511,8 +512,7 @@ public void testFactorialNegative() { private static final Iterable TOLERANCE_CANDIDATES = ImmutableList.copyOf( - Iterables.concat( - FINITE_TOLERANCE_CANDIDATES, ImmutableList.of(Double.POSITIVE_INFINITY))); + concat(FINITE_TOLERANCE_CANDIDATES, ImmutableList.of(Double.POSITIVE_INFINITY))); private static final ImmutableList BAD_TOLERANCE_CANDIDATES = ImmutableList.copyOf( diff --git a/android/guava-tests/test/com/google/common/math/IntMathTest.java b/android/guava-tests/test/com/google/common/math/IntMathTest.java index 734ebeb73a50..976b63e7cac0 100644 --- a/android/guava-tests/test/com/google/common/math/IntMathTest.java +++ b/android/guava-tests/test/com/google/common/math/IntMathTest.java @@ -16,6 +16,7 @@ package com.google.common.math; +import static com.google.common.math.BigIntegerMath.sqrt; import static com.google.common.math.IntMath.checkedAdd; import static com.google.common.math.IntMath.checkedMultiply; import static com.google.common.math.IntMath.checkedSubtract; @@ -114,8 +115,7 @@ public void testFloorPowerOfTwoZero() { @GwtIncompatible // BigIntegerMath // TODO(cpovirk): GWT-enable BigIntegerMath public void testConstantMaxPowerOfSqrt2Unsigned() { assertThat(IntMath.MAX_POWER_OF_SQRT2_UNSIGNED) - .isEqualTo( - BigIntegerMath.sqrt(BigInteger.ZERO.setBit(2 * Integer.SIZE - 1), FLOOR).intValue()); + .isEqualTo(sqrt(BigInteger.ZERO.setBit(2 * Integer.SIZE - 1), FLOOR).intValue()); } @GwtIncompatible // pow() @@ -136,10 +136,7 @@ public void testMaxLog10ForLeadingZeros() { @GwtIncompatible // BigIntegerMath // TODO(cpovirk): GWT-enable BigIntegerMath public void testConstantsHalfPowersOf10() { for (int i = 0; i < IntMath.halfPowersOf10.length; i++) { - assertThat( - min( - Integer.MAX_VALUE, - BigIntegerMath.sqrt(BigInteger.TEN.pow(2 * i + 1), FLOOR).longValue())) + assertThat(min(Integer.MAX_VALUE, sqrt(BigInteger.TEN.pow(2 * i + 1), FLOOR).longValue())) .isEqualTo(IntMath.halfPowersOf10[i]); } } @@ -304,7 +301,7 @@ public void testSqrtMatchesBigInteger() { // The BigInteger implementation is tested separately, use it as the reference. // Promote the int value (rather than using intValue() on the expected value) to avoid // any risk of truncation which could lead to a false positive. - assertThat(bigInt(sqrt(x, mode))).isEqualTo(BigIntegerMath.sqrt(bigInt(x), mode)); + assertThat(bigInt(sqrt(x, mode))).isEqualTo(sqrt(bigInt(x), mode)); } } } diff --git a/android/guava-tests/test/com/google/common/math/LongMathTest.java b/android/guava-tests/test/com/google/common/math/LongMathTest.java index 25b0ecfd9c7d..71f3bb634360 100644 --- a/android/guava-tests/test/com/google/common/math/LongMathTest.java +++ b/android/guava-tests/test/com/google/common/math/LongMathTest.java @@ -16,6 +16,7 @@ package com.google.common.math; +import static com.google.common.math.BigIntegerMath.sqrt; import static com.google.common.math.LongMath.checkedAdd; import static com.google.common.math.LongMath.checkedMultiply; import static com.google.common.math.LongMath.checkedSubtract; @@ -115,8 +116,7 @@ public void testFloorPowerOfTwoZero() { @GwtIncompatible // TODO public void testConstantMaxPowerOfSqrt2Unsigned() { assertThat(LongMath.MAX_POWER_OF_SQRT2_UNSIGNED) - .isEqualTo( - BigIntegerMath.sqrt(BigInteger.ZERO.setBit(2 * Long.SIZE - 1), FLOOR).longValue()); + .isEqualTo(sqrt(BigInteger.ZERO.setBit(2 * Long.SIZE - 1), FLOOR).longValue()); } @GwtIncompatible // BigIntegerMath // TODO(cpovirk): GWT-enable BigIntegerMath @@ -140,10 +140,9 @@ public void testConstantsPowersOf10() { public void testConstantsHalfPowersOf10() { for (int i = 0; i < LongMath.halfPowersOf10.length; i++) { assertThat(bigInt(LongMath.halfPowersOf10[i])) - .isEqualTo(BigIntegerMath.sqrt(BigInteger.TEN.pow(2 * i + 1), FLOOR)); + .isEqualTo(sqrt(BigInteger.TEN.pow(2 * i + 1), FLOOR)); } - BigInteger nextBigger = - BigIntegerMath.sqrt(BigInteger.TEN.pow(2 * LongMath.halfPowersOf10.length + 1), FLOOR); + BigInteger nextBigger = sqrt(BigInteger.TEN.pow(2 * LongMath.halfPowersOf10.length + 1), FLOOR); assertThat(nextBigger).isGreaterThan(bigInt(Long.MAX_VALUE)); } @@ -340,7 +339,7 @@ public void testSqrtMatchesBigInteger() { for (RoundingMode mode : ALL_SAFE_ROUNDING_MODES) { // Promote the long value (rather than using longValue() on the expected value) to avoid // any risk of truncation which could lead to a false positive. - assertThat(bigInt(sqrt(x, mode))).isEqualTo(BigIntegerMath.sqrt(bigInt(x), mode)); + assertThat(bigInt(sqrt(x, mode))).isEqualTo(sqrt(bigInt(x), mode)); } } } diff --git a/android/guava-tests/test/com/google/common/math/MathTesting.java b/android/guava-tests/test/com/google/common/math/MathTesting.java index 2517df978823..4bcfb74da7ca 100644 --- a/android/guava-tests/test/com/google/common/math/MathTesting.java +++ b/android/guava-tests/test/com/google/common/math/MathTesting.java @@ -16,8 +16,10 @@ package com.google.common.math; +import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.transform; +import static java.lang.Math.round; import static java.math.BigInteger.ONE; import static java.math.BigInteger.ZERO; import static java.math.RoundingMode.CEILING; @@ -32,7 +34,6 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; import com.google.common.primitives.Doubles; import java.math.BigInteger; import java.math.RoundingMode; @@ -86,13 +87,12 @@ public final class MathTesting { POSITIVE_INTEGER_CANDIDATES = intValues.build(); NEGATIVE_INTEGER_CANDIDATES = ImmutableList.copyOf( - Iterables.concat( + concat( transform(POSITIVE_INTEGER_CANDIDATES, x -> -x), ImmutableList.of(Integer.MIN_VALUE))); NONZERO_INTEGER_CANDIDATES = - ImmutableList.copyOf( - Iterables.concat(POSITIVE_INTEGER_CANDIDATES, NEGATIVE_INTEGER_CANDIDATES)); - ALL_INTEGER_CANDIDATES = Iterables.concat(NONZERO_INTEGER_CANDIDATES, ImmutableList.of(0)); + ImmutableList.copyOf(concat(POSITIVE_INTEGER_CANDIDATES, NEGATIVE_INTEGER_CANDIDATES)); + ALL_INTEGER_CANDIDATES = concat(NONZERO_INTEGER_CANDIDATES, ImmutableList.of(0)); } /* @@ -123,10 +123,9 @@ public final class MathTesting { longValues.add(194368031998L).add(194368031999L); // sqrt(2^75) rounded up and down POSITIVE_LONG_CANDIDATES = longValues.build(); NEGATIVE_LONG_CANDIDATES = - Iterables.concat( - transform(POSITIVE_LONG_CANDIDATES, x -> -x), ImmutableList.of(Long.MIN_VALUE)); - NONZERO_LONG_CANDIDATES = Iterables.concat(POSITIVE_LONG_CANDIDATES, NEGATIVE_LONG_CANDIDATES); - ALL_LONG_CANDIDATES = Iterables.concat(NONZERO_LONG_CANDIDATES, ImmutableList.of(0L)); + concat(transform(POSITIVE_LONG_CANDIDATES, x -> -x), ImmutableList.of(Long.MIN_VALUE)); + NONZERO_LONG_CANDIDATES = concat(POSITIVE_LONG_CANDIDATES, NEGATIVE_LONG_CANDIDATES); + ALL_LONG_CANDIDATES = concat(NONZERO_LONG_CANDIDATES, ImmutableList.of(0L)); } /* @@ -177,9 +176,8 @@ public final class MathTesting { POSITIVE_BIGINTEGER_CANDIDATES = bigValues.build(); NEGATIVE_BIGINTEGER_CANDIDATES = transform(POSITIVE_BIGINTEGER_CANDIDATES, BigInteger::negate); NONZERO_BIGINTEGER_CANDIDATES = - Iterables.concat(POSITIVE_BIGINTEGER_CANDIDATES, NEGATIVE_BIGINTEGER_CANDIDATES); - ALL_BIGINTEGER_CANDIDATES = - Iterables.concat(NONZERO_BIGINTEGER_CANDIDATES, ImmutableList.of(ZERO)); + concat(POSITIVE_BIGINTEGER_CANDIDATES, NEGATIVE_BIGINTEGER_CANDIDATES); + ALL_BIGINTEGER_CANDIDATES = concat(NONZERO_BIGINTEGER_CANDIDATES, ImmutableList.of(ZERO)); } static final ImmutableSet INTEGRAL_DOUBLE_CANDIDATES; @@ -228,7 +226,7 @@ public final class MathTesting { } for (double delta : Doubles.asList(0.01, 0.1, 0.25, 0.499, 0.5, 0.501, 0.7, 0.8)) { double x = d + delta; - if (x != Math.round(x)) { + if (x != round(x)) { fractionalBuilder.add(x); } } @@ -243,11 +241,10 @@ public final class MathTesting { } } FRACTIONAL_DOUBLE_CANDIDATES = fractionalBuilder.build(); - FINITE_DOUBLE_CANDIDATES = - Iterables.concat(FRACTIONAL_DOUBLE_CANDIDATES, INTEGRAL_DOUBLE_CANDIDATES); + FINITE_DOUBLE_CANDIDATES = concat(FRACTIONAL_DOUBLE_CANDIDATES, INTEGRAL_DOUBLE_CANDIDATES); POSITIVE_FINITE_DOUBLE_CANDIDATES = filter(FINITE_DOUBLE_CANDIDATES, input -> input > 0.0); - DOUBLE_CANDIDATES_EXCEPT_NAN = Iterables.concat(FINITE_DOUBLE_CANDIDATES, INFINITIES); - ALL_DOUBLE_CANDIDATES = Iterables.concat(DOUBLE_CANDIDATES_EXCEPT_NAN, asList(Double.NaN)); + DOUBLE_CANDIDATES_EXCEPT_NAN = concat(FINITE_DOUBLE_CANDIDATES, INFINITIES); + ALL_DOUBLE_CANDIDATES = concat(DOUBLE_CANDIDATES_EXCEPT_NAN, asList(Double.NaN)); } private MathTesting() {} diff --git a/android/guava-tests/test/com/google/common/net/InternetDomainNameTest.java b/android/guava-tests/test/com/google/common/net/InternetDomainNameTest.java index a0b2b0661d4a..60cf95c44dc4 100644 --- a/android/guava-tests/test/com/google/common/net/InternetDomainNameTest.java +++ b/android/guava-tests/test/com/google/common/net/InternetDomainNameTest.java @@ -16,6 +16,8 @@ package com.google.common.net; +import static com.google.common.base.Strings.repeat; +import static com.google.common.collect.Iterables.concat; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; @@ -23,9 +25,7 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Ascii; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; import com.google.common.testing.EqualsTester; import com.google.common.testing.NullPointerTester; import junit.framework.TestCase; @@ -49,13 +49,13 @@ public final class InternetDomainNameTest extends TestCase { /** A domain part which is valid under lenient validation, but invalid under strict validation. */ @SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8 - static final String LOTS_OF_DELTAS = Strings.repeat(DELTA, 62); + static final String LOTS_OF_DELTAS = repeat(DELTA, 62); @SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8 - private static final String ALMOST_TOO_MANY_LEVELS = Strings.repeat("a.", 127); + private static final String ALMOST_TOO_MANY_LEVELS = repeat("a.", 127); @SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8 - private static final String ALMOST_TOO_LONG = Strings.repeat("aaaaa.", 40) + "1234567890.c"; + private static final String ALMOST_TOO_LONG = repeat("aaaaa.", 40) + "1234567890.c"; private static final ImmutableSet VALID_NAME = ImmutableSet.of( @@ -422,9 +422,8 @@ public void testInvalidTopPrivateDomain() { } public void testIsValid() { - Iterable validCases = Iterables.concat(VALID_NAME, PS, NO_PS, NON_PS); - Iterable invalidCases = - Iterables.concat(INVALID_NAME, VALID_IP_ADDRS, INVALID_IP_ADDRS); + Iterable validCases = concat(VALID_NAME, PS, NO_PS, NON_PS); + Iterable invalidCases = concat(INVALID_NAME, VALID_IP_ADDRS, INVALID_IP_ADDRS); for (String valid : validCases) { assertTrue(valid, InternetDomainName.isValid(valid)); diff --git a/android/guava-tests/test/com/google/common/reflect/InvokableTest.java b/android/guava-tests/test/com/google/common/reflect/InvokableTest.java index 02ebe6d21dc8..8daf71275f8e 100644 --- a/android/guava-tests/test/com/google/common/reflect/InvokableTest.java +++ b/android/guava-tests/test/com/google/common/reflect/InvokableTest.java @@ -16,13 +16,13 @@ package com.google.common.reflect; +import static com.google.common.collect.Iterables.concat; import static com.google.common.truth.Truth.assertThat; import static java.util.Collections.nCopies; import static org.junit.Assert.assertThrows; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; import com.google.common.testing.EqualsTester; import com.google.common.testing.NullPointerTester; import com.google.errorprone.annotations.Keep; @@ -750,14 +750,14 @@ private Prepender() { @SuppressWarnings("UnusedTypeParameter") // examined with reflection static Iterable prepend(@NotBlank String first, Iterable tail) { - return Iterables.concat(ImmutableList.of(first), tail); + return concat(ImmutableList.of(first), tail); } // We are testing reflective access to an unnecessary `throws` clause. @SuppressWarnings("ThrowsUncheckedException") Iterable prepend(Iterable tail) throws IllegalArgumentException, NullPointerException { - return Iterables.concat(nCopies(times, prefix), tail); + return concat(nCopies(times, prefix), tail); } static Invokable constructor(Class... parameterTypes) throws Exception { diff --git a/android/guava-tests/test/com/google/common/reflect/TypeResolverTest.java b/android/guava-tests/test/com/google/common/reflect/TypeResolverTest.java index 464eebdd466c..8b3ecdcc9275 100644 --- a/android/guava-tests/test/com/google/common/reflect/TypeResolverTest.java +++ b/android/guava-tests/test/com/google/common/reflect/TypeResolverTest.java @@ -16,6 +16,8 @@ package com.google.common.reflect; +import static com.google.common.reflect.Types.subtypeOf; +import static com.google.common.reflect.Types.supertypeOf; import static org.junit.Assert.assertThrows; import java.lang.reflect.ParameterizedType; @@ -119,14 +121,14 @@ public void testWhere_parameterizedTypeMapping() { new TypeCapture>() {}.capture()) .resolveType(t)); assertEquals( - Types.subtypeOf(String.class), + subtypeOf(String.class), new TypeResolver() .where( new TypeCapture>() {}.capture(), new TypeCapture>() {}.capture()) .resolveType(t)); assertEquals( - Types.supertypeOf(String.class), + supertypeOf(String.class), new TypeResolver() .where( new TypeCapture>() {}.capture(), diff --git a/android/guava-tests/test/com/google/common/reflect/TypeTokenResolutionTest.java b/android/guava-tests/test/com/google/common/reflect/TypeTokenResolutionTest.java index 4cbab64246e1..e7a143234ce3 100644 --- a/android/guava-tests/test/com/google/common/reflect/TypeTokenResolutionTest.java +++ b/android/guava-tests/test/com/google/common/reflect/TypeTokenResolutionTest.java @@ -16,6 +16,8 @@ package com.google.common.reflect; +import static com.google.common.reflect.Types.newArrayType; +import static com.google.common.reflect.Types.newParameterizedType; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; @@ -281,7 +283,7 @@ private static final class GenericArray { public void testGenericArrayType() { GenericArray genericArray = new GenericArray<>(); assertEquals(GenericArray.class.getTypeParameters()[0], genericArray.t); - assertEquals(Types.newArrayType(genericArray.t), genericArray.array); + assertEquals(newArrayType(genericArray.t), genericArray.array); } public void testClassWrapper() { @@ -413,7 +415,7 @@ public void testResolveToGenericArrayType() { (GenericArrayType) new Holder[]>() {}.getContentType(); ParameterizedType listType = (ParameterizedType) arrayType.getGenericComponentType(); assertEquals(List.class, listType.getRawType()); - assertEquals(Types.newArrayType(int[].class), listType.getActualTypeArguments()[0]); + assertEquals(newArrayType(int[].class), listType.getActualTypeArguments()[0]); } private abstract class WithGenericBound { @@ -454,7 +456,7 @@ public void testWithGenericBoundInTypeVariable() throws Exception { public void testWithRecursiveBoundInTypeVariable() throws Exception { TypeVariable typeVariable = (TypeVariable) new WithGenericBound() {}.getTargetType("withRecursiveBound"); - assertEquals(Types.newParameterizedType(Enum.class, typeVariable), typeVariable.getBounds()[0]); + assertEquals(newParameterizedType(Enum.class, typeVariable), typeVariable.getBounds()[0]); } public void testWithMutualRecursiveBoundInTypeVariable() throws Exception { @@ -463,8 +465,8 @@ public void testWithMutualRecursiveBoundInTypeVariable() throws Exception { new WithGenericBound() {}.getTargetType("withMutualRecursiveBound"); TypeVariable k = (TypeVariable) paramType.getActualTypeArguments()[0]; TypeVariable v = (TypeVariable) paramType.getActualTypeArguments()[1]; - assertEquals(Types.newParameterizedType(List.class, v), k.getBounds()[0]); - assertEquals(Types.newParameterizedType(List.class, k), v.getBounds()[0]); + assertEquals(newParameterizedType(List.class, v), k.getBounds()[0]); + assertEquals(newParameterizedType(List.class, k), v.getBounds()[0]); } public void testWithGenericLowerBoundInWildcard() throws Exception { diff --git a/android/guava-tests/test/com/google/common/reflect/TypeTokenTest.java b/android/guava-tests/test/com/google/common/reflect/TypeTokenTest.java index 54da7471297d..4832f20269f1 100644 --- a/android/guava-tests/test/com/google/common/reflect/TypeTokenTest.java +++ b/android/guava-tests/test/com/google/common/reflect/TypeTokenTest.java @@ -16,6 +16,10 @@ package com.google.common.reflect; +import static com.google.common.reflect.Types.newArrayType; +import static com.google.common.reflect.Types.newParameterizedType; +import static com.google.common.reflect.Types.subtypeOf; +import static com.google.common.reflect.Types.supertypeOf; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; @@ -107,7 +111,7 @@ public void testGetType() { public void testNonStaticLocalClass() { class Local {} TypeToken> type = new TypeToken>() {}; - assertEquals(Types.newParameterizedType(Local.class, String.class), type.getType()); + assertEquals(newParameterizedType(Local.class, String.class), type.getType()); assertEquals(new Local() {}.getClass().getGenericSuperclass(), type.getType()); } @@ -118,7 +122,7 @@ public void testStaticLocalClass() { private static void doTestStaticLocalClass() { class Local {} TypeToken> type = new TypeToken>() {}; - assertEquals(Types.newParameterizedType(Local.class, String.class), type.getType()); + assertEquals(newParameterizedType(Local.class, String.class), type.getType()); assertEquals(new Local() {}.getClass().getGenericSuperclass(), type.getType()); } @@ -451,30 +455,28 @@ void testGetGenericSuperclass_typeVariable_boundIsTypeVariableAndInterface() { public void testGetGenericSuperclass_wildcard_lowerBounded() { assertEquals( - TypeToken.of(Object.class), - TypeToken.of(Types.supertypeOf(String.class)).getGenericSuperclass()); + TypeToken.of(Object.class), TypeToken.of(supertypeOf(String.class)).getGenericSuperclass()); assertEquals( new TypeToken() {}, - TypeToken.of(Types.supertypeOf(String[].class)).getGenericSuperclass()); + TypeToken.of(supertypeOf(String[].class)).getGenericSuperclass()); assertEquals( new TypeToken() {}, - TypeToken.of(Types.supertypeOf(CharSequence.class)).getGenericSuperclass()); + TypeToken.of(supertypeOf(CharSequence.class)).getGenericSuperclass()); } public void testGetGenericSuperclass_wildcard_boundIsClass() { assertEquals( - TypeToken.of(Object.class), - TypeToken.of(Types.subtypeOf(Object.class)).getGenericSuperclass()); + TypeToken.of(Object.class), TypeToken.of(subtypeOf(Object.class)).getGenericSuperclass()); assertEquals( new TypeToken() {}, - TypeToken.of(Types.subtypeOf(Object[].class)).getGenericSuperclass()); + TypeToken.of(subtypeOf(Object[].class)).getGenericSuperclass()); } public void testGetGenericSuperclass_wildcard_boundIsInterface() { - assertThat(TypeToken.of(Types.subtypeOf(CharSequence.class)).getGenericSuperclass()).isNull(); + assertThat(TypeToken.of(subtypeOf(CharSequence.class)).getGenericSuperclass()).isNull(); assertEquals( new TypeToken() {}, - TypeToken.of(Types.subtypeOf(CharSequence[].class)).getGenericSuperclass()); + TypeToken.of(subtypeOf(CharSequence[].class)).getGenericSuperclass()); } public void testGetGenericInterfaces_typeVariable_unbounded() { @@ -529,18 +531,18 @@ void testGetGenericInterfaces_typeVariable_boundIsTypeVariableAndInterface() { } public void testGetGenericInterfaces_wildcard_lowerBounded() { - assertThat(TypeToken.of(Types.supertypeOf(String.class)).getGenericInterfaces()).isEmpty(); - assertThat(TypeToken.of(Types.supertypeOf(String[].class)).getGenericInterfaces()).isEmpty(); + assertThat(TypeToken.of(supertypeOf(String.class)).getGenericInterfaces()).isEmpty(); + assertThat(TypeToken.of(supertypeOf(String[].class)).getGenericInterfaces()).isEmpty(); } public void testGetGenericInterfaces_wildcard_boundIsClass() { - assertThat(TypeToken.of(Types.subtypeOf(Object.class)).getGenericInterfaces()).isEmpty(); - assertThat(TypeToken.of(Types.subtypeOf(Object[].class)).getGenericInterfaces()).isEmpty(); + assertThat(TypeToken.of(subtypeOf(Object.class)).getGenericInterfaces()).isEmpty(); + assertThat(TypeToken.of(subtypeOf(Object[].class)).getGenericInterfaces()).isEmpty(); } public void testGetGenericInterfaces_wildcard_boundIsInterface() { TypeToken> interfaceType = new TypeToken>() {}; - makeUnmodifiable(TypeToken.of(Types.subtypeOf(interfaceType.getType())).getGenericInterfaces()) + makeUnmodifiable(TypeToken.of(subtypeOf(interfaceType.getType())).getGenericInterfaces()) .containsExactly(interfaceType); assertHasArrayInterfaces(new TypeToken[]>() {}); } @@ -624,7 +626,7 @@ public void testAssignableGenericArrayToClass() { } public void testAssignableWildcardBoundedByArrayToArrayClass() { - Type wildcardType = Types.subtypeOf(Object[].class); + Type wildcardType = subtypeOf(Object[].class); assertTrue(TypeToken.of(Object[].class).isSupertypeOf(wildcardType)); assertTrue(TypeToken.of(Object.class).isSupertypeOf(wildcardType)); assertFalse(TypeToken.of(wildcardType).isSupertypeOf(wildcardType)); @@ -640,8 +642,8 @@ public void testAssignableWildcardTypeParameterToClassTypeParameter() { } public void testAssignableArrayClassToBoundedWildcard() { - TypeToken subtypeOfArray = TypeToken.of(Types.subtypeOf(Object[].class)); - TypeToken supertypeOfArray = TypeToken.of(Types.supertypeOf(Object[].class)); + TypeToken subtypeOfArray = TypeToken.of(subtypeOf(Object[].class)); + TypeToken supertypeOfArray = TypeToken.of(supertypeOf(Object[].class)); assertFalse(subtypeOfArray.isSupertypeOf(Object[].class)); assertFalse(subtypeOfArray.isSupertypeOf(Object[][].class)); assertFalse(subtypeOfArray.isSupertypeOf(String[].class)); @@ -664,16 +666,16 @@ public void testAssignableClassTypeParameterToWildcardTypeParameter() { } public void testAssignableNonParameterizedClassToWildcard() { - TypeToken supertypeOfString = TypeToken.of(Types.supertypeOf(String.class)); + TypeToken supertypeOfString = TypeToken.of(supertypeOf(String.class)); assertFalse(supertypeOfString.isSupertypeOf(supertypeOfString)); assertFalse(supertypeOfString.isSupertypeOf(Object.class)); assertFalse(supertypeOfString.isSupertypeOf(CharSequence.class)); assertTrue(supertypeOfString.isSupertypeOf(String.class)); - assertTrue(supertypeOfString.isSupertypeOf(Types.subtypeOf(String.class))); + assertTrue(supertypeOfString.isSupertypeOf(subtypeOf(String.class))); } public void testAssignableWildcardBoundedByIntArrayToArrayClass() { - Type wildcardType = Types.subtypeOf(int[].class); + Type wildcardType = subtypeOf(int[].class); assertTrue(TypeToken.of(int[].class).isSupertypeOf(wildcardType)); assertTrue(TypeToken.of(Object.class).isSupertypeOf(wildcardType)); assertFalse(TypeToken.of(wildcardType).isSupertypeOf(wildcardType)); @@ -689,8 +691,8 @@ public void testAssignableWildcardTypeParameterBoundedByIntArrayToArrayClassType } public void testAssignableWildcardToWildcard() { - TypeToken subtypeOfArray = TypeToken.of(Types.subtypeOf(Object[].class)); - TypeToken supertypeOfArray = TypeToken.of(Types.supertypeOf(Object[].class)); + TypeToken subtypeOfArray = TypeToken.of(subtypeOf(Object[].class)); + TypeToken supertypeOfArray = TypeToken.of(supertypeOf(Object[].class)); assertTrue(supertypeOfArray.isSupertypeOf(subtypeOfArray)); assertFalse(supertypeOfArray.isSupertypeOf(supertypeOfArray)); assertFalse(subtypeOfArray.isSupertypeOf(subtypeOfArray)); @@ -976,10 +978,10 @@ public void testIsArray_genericArrayClasses() { } public void testIsArray_wildcardType() { - assertTrue(TypeToken.of(Types.subtypeOf(Object[].class)).isArray()); - assertTrue(TypeToken.of(Types.subtypeOf(int[].class)).isArray()); - assertFalse(TypeToken.of(Types.subtypeOf(Object.class)).isArray()); - assertFalse(TypeToken.of(Types.supertypeOf(Object[].class)).isArray()); + assertTrue(TypeToken.of(subtypeOf(Object[].class)).isArray()); + assertTrue(TypeToken.of(subtypeOf(int[].class)).isArray()); + assertFalse(TypeToken.of(subtypeOf(Object.class)).isArray()); + assertFalse(TypeToken.of(supertypeOf(Object[].class)).isArray()); } public void testPrimitiveWrappingAndUnwrapping() { @@ -991,7 +993,7 @@ public void testPrimitiveWrappingAndUnwrapping() { } assertNotPrimitiveNorWrapper(TypeToken.of(String.class)); assertNotPrimitiveNorWrapper(TypeToken.of(Object[].class)); - assertNotPrimitiveNorWrapper(TypeToken.of(Types.subtypeOf(Object.class))); + assertNotPrimitiveNorWrapper(TypeToken.of(subtypeOf(Object.class))); assertNotPrimitiveNorWrapper(new TypeToken>() {}); assertNotPrimitiveNorWrapper(TypeToken.of(new TypeCapture() {}.capture())); } @@ -1021,16 +1023,14 @@ public void testGetComponentType_genericArrayClasses() { public void testGetComponentType_wildcardType() { assertEquals( - Types.subtypeOf(Object.class), - TypeToken.of(Types.subtypeOf(Object[].class)).getComponentType().getType()); - assertEquals( - Types.subtypeOf(Object[].class), - Types.newArrayType( - TypeToken.of(Types.subtypeOf(Object[].class)).getComponentType().getType())); + subtypeOf(Object.class), + TypeToken.of(subtypeOf(Object[].class)).getComponentType().getType()); assertEquals( - int.class, TypeToken.of(Types.subtypeOf(int[].class)).getComponentType().getType()); - assertThat(TypeToken.of(Types.subtypeOf(Object.class)).getComponentType()).isNull(); - assertThat(TypeToken.of(Types.supertypeOf(Object[].class)).getComponentType()).isNull(); + subtypeOf(Object[].class), + newArrayType(TypeToken.of(subtypeOf(Object[].class)).getComponentType().getType())); + assertEquals(int.class, TypeToken.of(subtypeOf(int[].class)).getComponentType().getType()); + assertThat(TypeToken.of(subtypeOf(Object.class)).getComponentType()).isNull(); + assertThat(TypeToken.of(supertypeOf(Object[].class)).getComponentType()).isNull(); } private interface NumberList {} @@ -1054,7 +1054,7 @@ public void testToGenericType() { TypeToken genericType = TypeToken.toGenericType(Iterable.class); assertThat(genericType.getRawType()).isEqualTo(Iterable.class); assertEquals( - Types.newParameterizedType(Iterable.class, Iterable.class.getTypeParameters()[0]), + newParameterizedType(Iterable.class, Iterable.class.getTypeParameters()[0]), genericType.getType()); } @@ -1085,9 +1085,9 @@ private interface StringListArrayIterable extends ListIterable {} public void testGetSupertype_withTypeVariable() { ParameterizedType expectedType = - Types.newParameterizedType( + newParameterizedType( Iterable.class, - Types.newParameterizedType(List.class, ListIterable.class.getTypeParameters()[0])); + newParameterizedType(List.class, ListIterable.class.getTypeParameters()[0])); assertEquals( expectedType, TypeToken.of(ListIterable.class).getSupertype(Iterable.class).getType()); } @@ -1103,8 +1103,7 @@ void testGetSupertype_typeVariableWithMultipleBounds() { public void testGetSupertype_withoutTypeVariable() { ParameterizedType expectedType = - Types.newParameterizedType( - Iterable.class, Types.newParameterizedType(List.class, String.class)); + newParameterizedType(Iterable.class, newParameterizedType(List.class, String.class)); assertEquals( expectedType, TypeToken.of(StringListIterable.class).getSupertype(Iterable.class).getType()); @@ -1116,8 +1115,7 @@ public void testGetSupertype_chained() { (TypeToken>) TypeToken.of(StringListIterable.class).getSupertype(ListIterable.class); ParameterizedType expectedType = - Types.newParameterizedType( - Iterable.class, Types.newParameterizedType(List.class, String.class)); + newParameterizedType(Iterable.class, newParameterizedType(List.class, String.class)); assertEquals(expectedType, listIterableType.getSupertype(Iterable.class).getType()); } @@ -1137,7 +1135,7 @@ public void testGetSupertype_fromWildcard() { @SuppressWarnings("unchecked") // can't do new TypeToken() {} TypeToken> type = (TypeToken>) - TypeToken.of(Types.subtypeOf(new TypeToken>() {}.getType())); + TypeToken.of(subtypeOf(new TypeToken>() {}.getType())); assertEquals(new TypeToken>() {}, type.getSupertype(Iterable.class)); } @@ -1151,7 +1149,7 @@ public > void testGetSupertype_fromTypeVariable() { @SuppressWarnings("rawtypes") // purpose is to test raw type public void testGetSupertype_fromRawClass() { assertEquals( - Types.newParameterizedType(Iterable.class, List.class.getTypeParameters()[0]), + newParameterizedType(Iterable.class, List.class.getTypeParameters()[0]), new TypeToken() {}.getSupertype(Iterable.class).getType()); } @@ -1172,10 +1170,10 @@ private interface ListMap extends Map> {} public void testGetSupertype_fullyGenericType() { ParameterizedType expectedType = - Types.newParameterizedType( + newParameterizedType( Map.class, ListMap.class.getTypeParameters()[0], - Types.newParameterizedType(List.class, ListMap.class.getTypeParameters()[1])); + newParameterizedType(List.class, ListMap.class.getTypeParameters()[1])); assertEquals(expectedType, TypeToken.of(ListMap.class).getSupertype(Map.class).getType()); } @@ -1234,7 +1232,7 @@ public void testGetSubtype_fromWildcard() { @SuppressWarnings("unchecked") // can't do new TypeToken() {} TypeToken> type = (TypeToken>) - TypeToken.of(Types.supertypeOf(new TypeToken>() {}.getType())); + TypeToken.of(supertypeOf(new TypeToken>() {}.getType())); assertEquals(new TypeToken>() {}, type.getSubtype(List.class)); } @@ -1242,7 +1240,7 @@ public void testGetSubtype_fromWildcard_lowerBoundNotSupertype() { @SuppressWarnings("unchecked") // can't do new TypeToken() {} TypeToken> type = (TypeToken>) - TypeToken.of(Types.supertypeOf(new TypeToken>() {}.getType())); + TypeToken.of(supertypeOf(new TypeToken>() {}.getType())); assertThrows(IllegalArgumentException.class, () -> type.getSubtype(List.class)); } @@ -1250,7 +1248,7 @@ public void testGetSubtype_fromWildcard_upperBounded() { @SuppressWarnings("unchecked") // can't do new TypeToken() {} TypeToken> type = (TypeToken>) - TypeToken.of(Types.subtypeOf(new TypeToken>() {}.getType())); + TypeToken.of(subtypeOf(new TypeToken>() {}.getType())); assertThrows(IllegalArgumentException.class, () -> type.getSubtype(Iterable.class)); } @@ -1808,11 +1806,10 @@ static void verifyConsistentRawType() { public void testRawTypes() { RawTypeConsistencyTester.verifyConsistentRawType(); - assertThat(TypeToken.of(Types.subtypeOf(Object.class)).getRawType()).isEqualTo(Object.class); - assertThat(TypeToken.of(Types.subtypeOf(CharSequence.class)).getRawType()) + assertThat(TypeToken.of(subtypeOf(Object.class)).getRawType()).isEqualTo(Object.class); + assertThat(TypeToken.of(subtypeOf(CharSequence.class)).getRawType()) .isEqualTo(CharSequence.class); - assertThat(TypeToken.of(Types.supertypeOf(CharSequence.class)).getRawType()) - .isEqualTo(Object.class); + assertThat(TypeToken.of(supertypeOf(CharSequence.class)).getRawType()).isEqualTo(Object.class); } private abstract static class IKnowMyType { diff --git a/android/guava-tests/test/com/google/common/reflect/TypeVisitorTest.java b/android/guava-tests/test/com/google/common/reflect/TypeVisitorTest.java index d466067c8970..6712b3cf8d29 100644 --- a/android/guava-tests/test/com/google/common/reflect/TypeVisitorTest.java +++ b/android/guava-tests/test/com/google/common/reflect/TypeVisitorTest.java @@ -16,6 +16,8 @@ package com.google.common.reflect; +import static com.google.common.reflect.Types.subtypeOf; + import java.lang.reflect.GenericArrayType; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -57,7 +59,7 @@ void visitTypeVariable(TypeVariable t) {} } public void testVisitWildcardType() { - WildcardType type = Types.subtypeOf(String.class); + WildcardType type = subtypeOf(String.class); assertVisited(type); new BaseTypeVisitor() { @Override diff --git a/android/guava-tests/test/com/google/common/reflect/TypesTest.java b/android/guava-tests/test/com/google/common/reflect/TypesTest.java index c5508287b1fb..b8d282d38505 100644 --- a/android/guava-tests/test/com/google/common/reflect/TypesTest.java +++ b/android/guava-tests/test/com/google/common/reflect/TypesTest.java @@ -16,6 +16,11 @@ package com.google.common.reflect; +import static com.google.common.reflect.Types.newArrayType; +import static com.google.common.reflect.Types.newArtificialTypeVariable; +import static com.google.common.reflect.Types.newParameterizedType; +import static com.google.common.reflect.Types.subtypeOf; +import static com.google.common.reflect.Types.supertypeOf; import static com.google.common.testing.SerializableTester.reserialize; import static com.google.common.testing.SerializableTester.reserializeAndAssert; import static com.google.common.truth.Truth.assertThat; @@ -51,8 +56,7 @@ public class TypesTest extends TestCase { public void testNewParameterizedType_ownerTypeImplied() throws Exception { ParameterizedType jvmType = (ParameterizedType) new TypeCapture>() {}.capture(); - ParameterizedType ourType = - Types.newParameterizedType(Entry.class, String.class, Integer.class); + ParameterizedType ourType = newParameterizedType(Entry.class, String.class, Integer.class); assertEquals(jvmType, ourType); assertEquals(Map.class, ourType.getOwnerType()); } @@ -60,8 +64,7 @@ public void testNewParameterizedType_ownerTypeImplied() throws Exception { public void testNewParameterizedType() { ParameterizedType jvmType = (ParameterizedType) new TypeCapture>() {}.capture(); - ParameterizedType ourType = - Types.newParameterizedType(HashMap.class, String.class, int[][].class); + ParameterizedType ourType = newParameterizedType(HashMap.class, String.class, int[][].class); new EqualsTester().addEqualityGroup(jvmType, ourType).testEquals(); assertThat(ourType.toString()).isEqualTo(jvmType.toString()); @@ -72,7 +75,7 @@ public void testNewParameterizedType() { .containsExactlyElementsIn(asList(jvmType.getActualTypeArguments())) .inOrder(); assertEquals( - asList(String.class, Types.newArrayType(Types.newArrayType(int.class))), + asList(String.class, newArrayType(newArrayType(int.class))), asList(ourType.getActualTypeArguments())); assertThat(ourType.getOwnerType()).isNull(); } @@ -80,7 +83,7 @@ public void testNewParameterizedType() { public void testNewParameterizedType_nonStaticLocalClass() { class LocalClass {} Type jvmType = new LocalClass() {}.getClass().getGenericSuperclass(); - Type ourType = Types.newParameterizedType(LocalClass.class, String.class); + Type ourType = newParameterizedType(LocalClass.class, String.class); assertEquals(jvmType, ourType); } @@ -91,7 +94,7 @@ public void testNewParameterizedType_staticLocalClass() { private static void doTestNewParameterizedTypeStaticLocalClass() { class LocalClass {} Type jvmType = new LocalClass() {}.getClass().getGenericSuperclass(); - Type ourType = Types.newParameterizedType(LocalClass.class, String.class); + Type ourType = newParameterizedType(LocalClass.class, String.class); assertEquals(jvmType, ourType); } @@ -116,7 +119,7 @@ public void testNewParameterizedTypeWithOwner() { } public void testNewParameterizedType_serializable() { - reserializeAndAssert(Types.newParameterizedType(Entry.class, String.class, Integer.class)); + reserializeAndAssert(newParameterizedType(Entry.class, String.class, Integer.class)); } public void testNewParameterizedType_ownerMismatch() { @@ -127,7 +130,7 @@ public void testNewParameterizedType_ownerMismatch() { public void testNewParameterizedType_ownerMissing() { assertEquals( - Types.newParameterizedType(Entry.class, String.class, Integer.class), + newParameterizedType(Entry.class, String.class, Integer.class), Types.newParameterizedTypeWithOwner(null, Entry.class, String.class, Integer.class)); } @@ -146,10 +149,10 @@ public void testNewParameterizedType_primitiveTypeParameters() { public void testNewArrayType() { Type jvmType1 = new TypeCapture[]>() {}.capture(); GenericArrayType ourType1 = - (GenericArrayType) Types.newArrayType(Types.newParameterizedType(List.class, String.class)); + (GenericArrayType) newArrayType(newParameterizedType(List.class, String.class)); @SuppressWarnings("rawtypes") // test of raw types Type jvmType2 = new TypeCapture() {}.capture(); - Type ourType2 = Types.newArrayType(List.class); + Type ourType2 = newArrayType(List.class); new EqualsTester() .addEqualityGroup(jvmType1, ourType1) .addEqualityGroup(jvmType2, ourType2) @@ -161,30 +164,30 @@ public void testNewArrayType() { public void testNewArrayTypeOfArray() { Type jvmType = new TypeCapture() {}.capture(); - Type ourType = Types.newArrayType(int[].class); + Type ourType = newArrayType(int[].class); assertThat(ourType.toString()).isEqualTo(jvmType.toString()); new EqualsTester().addEqualityGroup(jvmType, ourType).testEquals(); } public void testNewArrayType_primitive() { Type jvmType = new TypeCapture() {}.capture(); - Type ourType = Types.newArrayType(int.class); + Type ourType = newArrayType(int.class); assertThat(ourType.toString()).isEqualTo(jvmType.toString()); new EqualsTester().addEqualityGroup(jvmType, ourType).testEquals(); } public void testNewArrayType_upperBoundedWildcard() { - Type wildcard = Types.subtypeOf(Number.class); - assertEquals(Types.subtypeOf(Number[].class), Types.newArrayType(wildcard)); + Type wildcard = subtypeOf(Number.class); + assertEquals(subtypeOf(Number[].class), newArrayType(wildcard)); } public void testNewArrayType_lowerBoundedWildcard() { - Type wildcard = Types.supertypeOf(Number.class); - assertEquals(Types.supertypeOf(Number[].class), Types.newArrayType(wildcard)); + Type wildcard = supertypeOf(Number.class); + assertEquals(supertypeOf(Number[].class), newArrayType(wildcard)); } public void testNewArrayType_serializable() { - reserializeAndAssert(Types.newArrayType(int[].class)); + reserializeAndAssert(newArrayType(int[].class)); } private static class WithWildcardType { @@ -215,9 +218,9 @@ public void testNewWildcardType() throws Exception { WildcardType objectBoundJvmType = WithWildcardType.getWildcardType("withObjectBound"); WildcardType upperBoundJvmType = WithWildcardType.getWildcardType("withUpperBound"); WildcardType lowerBoundJvmType = WithWildcardType.getWildcardType("withLowerBound"); - WildcardType objectBound = Types.subtypeOf(Object.class); - WildcardType upperBound = Types.subtypeOf(int[][].class); - WildcardType lowerBound = Types.supertypeOf(String[][].class); + WildcardType objectBound = subtypeOf(Object.class); + WildcardType upperBound = subtypeOf(int[][].class); + WildcardType lowerBound = supertypeOf(String[][].class); assertEqualWildcardType(noBoundJvmType, objectBound); assertEqualWildcardType(objectBoundJvmType, objectBound); @@ -232,13 +235,13 @@ public void testNewWildcardType() throws Exception { } public void testNewWildcardType_primitiveTypeBound() { - assertThrows(IllegalArgumentException.class, () -> Types.subtypeOf(int.class)); + assertThrows(IllegalArgumentException.class, () -> subtypeOf(int.class)); } public void testNewWildcardType_serializable() { - reserializeAndAssert(Types.supertypeOf(String.class)); - reserializeAndAssert(Types.subtypeOf(String.class)); - reserializeAndAssert(Types.subtypeOf(Object.class)); + reserializeAndAssert(supertypeOf(String.class)); + reserializeAndAssert(subtypeOf(String.class)); + reserializeAndAssert(subtypeOf(Object.class)); } private static void assertEqualWildcardType(WildcardType expected, WildcardType actual) { @@ -306,18 +309,17 @@ public void testNewTypeVariable() throws Exception { public void testNewTypeVariable_primitiveTypeBound() { assertThrows( IllegalArgumentException.class, - () -> Types.newArtificialTypeVariable(List.class, "E", int.class)); + () -> newArtificialTypeVariable(List.class, "E", int.class)); } public void testNewTypeVariable_serializable() throws Exception { assertThrows( - RuntimeException.class, - () -> reserialize(Types.newArtificialTypeVariable(List.class, "E"))); + RuntimeException.class, () -> reserialize(newArtificialTypeVariable(List.class, "E"))); } private static TypeVariable withBounds( TypeVariable typeVariable, Type... bounds) { - return Types.newArtificialTypeVariable( + return newArtificialTypeVariable( typeVariable.getGenericDeclaration(), typeVariable.getName(), bounds); } @@ -359,7 +361,7 @@ private static void assertEqualTypeVariable(TypeVariable expected, TypeVariab */ public void testNewParameterizedTypeImmutability() { Type[] typesIn = {String.class, Integer.class}; - ParameterizedType parameterizedType = Types.newParameterizedType(Map.class, typesIn); + ParameterizedType parameterizedType = newParameterizedType(Map.class, typesIn); typesIn[0] = null; typesIn[1] = null; @@ -374,7 +376,7 @@ public void testNewParameterizedTypeImmutability() { public void testNewParameterizedTypeWithWrongNumberOfTypeArguments() { assertThrows( IllegalArgumentException.class, - () -> Types.newParameterizedType(Map.class, String.class, Integer.class, Long.class)); + () -> newParameterizedType(Map.class, String.class, Integer.class, Long.class)); } public void testToString() { diff --git a/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java b/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java index 9ac68f3ddd11..c4f11c6b3710 100644 --- a/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java +++ b/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java @@ -19,6 +19,7 @@ import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION; import static com.google.common.base.StandardSystemProperty.OS_NAME; import static com.google.common.collect.Iterables.getOnlyElement; +import static com.google.common.collect.Sets.newIdentityHashSet; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; import static com.google.common.util.concurrent.Futures.immediateCancelledFuture; @@ -26,6 +27,8 @@ import static com.google.common.util.concurrent.Futures.immediateFuture; import static com.google.common.util.concurrent.MoreExecutors.directExecutor; import static com.google.common.util.concurrent.SneakyThrows.sneakyThrow; +import static com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly; +import static com.google.common.util.concurrent.Uninterruptibles.getUninterruptibly; import static java.util.Arrays.asList; import static java.util.Collections.shuffle; import static java.util.Collections.singletonList; @@ -40,7 +43,6 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.Range; -import com.google.common.collect.Sets; import com.google.common.primitives.Ints; import com.google.common.util.concurrent.internal.InternalFutureFailureAccess; import java.util.ArrayList; @@ -504,11 +506,11 @@ public void testFutureBash() { return null; } }; - Set finalResults = synchronizedSet(Sets.newIdentityHashSet()); + Set finalResults = synchronizedSet(newIdentityHashSet()); Runnable collectResultsRunnable = () -> { try { - String result = Uninterruptibles.getUninterruptibly(currentFuture.get()); + String result = getUninterruptibly(currentFuture.get()); finalResults.add(result); } catch (ExecutionException e) { finalResults.add(e.getCause()); @@ -523,7 +525,7 @@ public void testFutureBash() { Future future = currentFuture.get(); while (true) { try { - String result = Uninterruptibles.getUninterruptibly(future, 0, SECONDS); + String result = getUninterruptibly(future, 0, SECONDS); finalResults.add(result); break; } catch (ExecutionException e) { @@ -619,11 +621,11 @@ public void testSetFutureCancelBash() { setFutureCompletionSuccess.set(future.set("hello-async-world")); awaitUnchecked(barrier); }; - Set finalResults = synchronizedSet(Sets.newIdentityHashSet()); + Set finalResults = synchronizedSet(newIdentityHashSet()); Runnable collectResultsRunnable = () -> { try { - String result = Uninterruptibles.getUninterruptibly(currentFuture.get()); + String result = getUninterruptibly(currentFuture.get()); finalResults.add(result); } catch (ExecutionException e) { finalResults.add(e.getCause()); @@ -638,7 +640,7 @@ public void testSetFutureCancelBash() { Future future = currentFuture.get(); while (true) { try { - String result = Uninterruptibles.getUninterruptibly(future, 0, SECONDS); + String result = getUninterruptibly(future, 0, SECONDS); finalResults.add(result); break; } catch (ExecutionException e) { @@ -736,11 +738,11 @@ public void testSetFutureCancelBash_withDoneFuture() { return null; } }; - Set finalResults = synchronizedSet(Sets.newIdentityHashSet()); + Set finalResults = synchronizedSet(newIdentityHashSet()); Runnable collectResultsRunnable = () -> { try { - String result = Uninterruptibles.getUninterruptibly(currentFuture.get()); + String result = getUninterruptibly(currentFuture.get()); finalResults.add(result); } catch (ExecutionException e) { finalResults.add(e.getCause()); @@ -1255,7 +1257,7 @@ public void run() { } void awaitInLoop() { - Uninterruptibles.awaitUninterruptibly(completedIteration); + awaitUninterruptibly(completedIteration); } } diff --git a/android/guava-tests/test/com/google/common/util/concurrent/InterruptibleTaskTest.java b/android/guava-tests/test/com/google/common/util/concurrent/InterruptibleTaskTest.java index e33daded5621..680bc14f4c26 100644 --- a/android/guava-tests/test/com/google/common/util/concurrent/InterruptibleTaskTest.java +++ b/android/guava-tests/test/com/google/common/util/concurrent/InterruptibleTaskTest.java @@ -16,6 +16,7 @@ package com.google.common.util.concurrent; import static com.google.common.truth.Truth.assertThat; +import static com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly; import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertThrows; @@ -198,7 +199,7 @@ static final class SlowChannel extends AbstractInterruptibleChannel { @Override protected void implCloseChannel() { - Uninterruptibles.awaitUninterruptibly(exitClose); + awaitUninterruptibly(exitClose); } void doBegin() { diff --git a/android/guava-tests/test/com/google/common/util/concurrent/MoreExecutorsTest.java b/android/guava-tests/test/com/google/common/util/concurrent/MoreExecutorsTest.java index 5a2d685ce1cb..114b81924770 100644 --- a/android/guava-tests/test/com/google/common/util/concurrent/MoreExecutorsTest.java +++ b/android/guava-tests/test/com/google/common/util/concurrent/MoreExecutorsTest.java @@ -36,6 +36,7 @@ import static com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService; import static com.google.common.util.concurrent.MoreExecutors.renamingDecorator; import static com.google.common.util.concurrent.MoreExecutors.shutdownAndAwaitTermination; +import static com.google.common.util.concurrent.Uninterruptibles.joinUninterruptibly; import static java.util.Collections.nCopies; import static java.util.concurrent.TimeUnit.DAYS; import static java.util.concurrent.TimeUnit.MILLISECONDS; @@ -223,7 +224,7 @@ public void run() { waiter.start(); awaitTimedWaiting(waiter); service.shutdown(); - Uninterruptibles.joinUninterruptibly(waiter, 10, SECONDS); + joinUninterruptibly(waiter, 10, SECONDS); if (waiter.isAlive()) { waiter.interrupt(); fail("awaitTermination failed to trigger after shutdown()"); diff --git a/android/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java b/android/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java index c11d88b2ace4..e585dee85b28 100644 --- a/android/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java +++ b/android/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java @@ -22,6 +22,8 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; import static com.google.common.util.concurrent.MoreExecutors.directExecutor; +import static com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly; +import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly; import static java.util.Arrays.asList; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.SECONDS; @@ -92,7 +94,7 @@ protected void doStart() { new Thread() { @Override public void run() { - Uninterruptibles.sleepUninterruptibly(delay, MILLISECONDS); + sleepUninterruptibly(delay, MILLISECONDS); notifyStarted(); } }.start(); @@ -103,7 +105,7 @@ protected void doStop() { new Thread() { @Override public void run() { - Uninterruptibles.sleepUninterruptibly(delay, MILLISECONDS); + sleepUninterruptibly(delay, MILLISECONDS); notifyStopped(); } }.start(); @@ -173,7 +175,7 @@ public void testServiceStartupTimes_selfStartingServices() { protected void doStart() { super.doStart(); // This will delay service listener execution at least 150 milliseconds - Uninterruptibles.sleepUninterruptibly(150, MILLISECONDS); + sleepUninterruptibly(150, MILLISECONDS); } }; Service a = @@ -490,7 +492,7 @@ public void run() { // We need to wait for the main thread to leave the ServiceManager.startAsync call // to // ensure that the thread running the failure callbacks is not the main thread. - Uninterruptibles.awaitUninterruptibly(afterStarted); + awaitUninterruptibly(afterStarted); notifyFailed(new Exception("boom")); } }.start(); @@ -508,7 +510,7 @@ protected void doStop() { public void failure(Service service) { failEnter.countDown(); // block until after the service manager is shutdown - Uninterruptibles.awaitUninterruptibly(failLeave); + awaitUninterruptibly(failLeave); } }, directExecutor()); diff --git a/android/guava-tests/test/com/google/common/util/concurrent/StripedTest.java b/android/guava-tests/test/com/google/common/util/concurrent/StripedTest.java index 70e4cbb1f0ad..9bf1750797e8 100644 --- a/android/guava-tests/test/com/google/common/util/concurrent/StripedTest.java +++ b/android/guava-tests/test/com/google/common/util/concurrent/StripedTest.java @@ -17,6 +17,7 @@ package com.google.common.util.concurrent; import static com.google.common.collect.Iterables.concat; +import static com.google.common.collect.Sets.newIdentityHashSet; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; @@ -184,7 +185,7 @@ public void testBasicInvariants() { } private static void assertBasicInvariants(Striped striped) { - Set observed = Sets.newIdentityHashSet(); // for the sake of weakly referenced locks. + Set observed = newIdentityHashSet(); // for the sake of weakly referenced locks. // this gets the stripes with #getAt(index) for (int i = 0; i < striped.size(); i++) { Object object = striped.getAt(i); diff --git a/android/guava-tests/test/com/google/common/util/concurrent/WrappingExecutorServiceTest.java b/android/guava-tests/test/com/google/common/util/concurrent/WrappingExecutorServiceTest.java index d84fe6a2ac92..db55c556da7d 100644 --- a/android/guava-tests/test/com/google/common/util/concurrent/WrappingExecutorServiceTest.java +++ b/android/guava-tests/test/com/google/common/util/concurrent/WrappingExecutorServiceTest.java @@ -16,6 +16,7 @@ package com.google.common.util.concurrent; +import static com.google.common.base.Predicates.instanceOf; import static com.google.common.collect.Iterables.all; import static com.google.common.truth.Truth.assertThat; import static com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService; @@ -26,7 +27,6 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import java.util.ArrayList; @@ -307,7 +307,7 @@ public void execute(Runnable command) { } private static void assertTaskWrapped(Collection> tasks) { - Predicate p = Predicates.instanceOf(WrappedCallable.class); + Predicate p = instanceOf(WrappedCallable.class); assertTrue(all(tasks, p)); } } diff --git a/android/guava/src/com/google/common/cache/LocalCache.java b/android/guava/src/com/google/common/cache/LocalCache.java index 0625e9ef3e34..7c79c901b9c3 100644 --- a/android/guava/src/com/google/common/cache/LocalCache.java +++ b/android/guava/src/com/google/common/cache/LocalCache.java @@ -49,7 +49,6 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; import com.google.common.util.concurrent.UncheckedExecutionException; -import com.google.common.util.concurrent.Uninterruptibles; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.concurrent.GuardedBy; import com.google.errorprone.annotations.concurrent.LazyInit; @@ -2297,7 +2296,7 @@ V scheduleRefresh( ListenableFuture result = loadAsync(key, hash, loadingValueReference, loader); if (result.isDone()) { try { - return Uninterruptibles.getUninterruptibly(result); + return getUninterruptibly(result); } catch (Throwable t) { // don't let refresh exceptions propagate; error was already logged } diff --git a/android/guava/src/com/google/common/collect/Collections2.java b/android/guava/src/com/google/common/collect/Collections2.java index 1bb45b9ec8d0..e020304204ef 100644 --- a/android/guava/src/com/google/common/collect/Collections2.java +++ b/android/guava/src/com/google/common/collect/Collections2.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.and; import static com.google.common.collect.CollectPreconditions.checkNonnegative; import static com.google.common.collect.Iterables.any; import static java.lang.Math.min; @@ -26,7 +27,6 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.base.Function; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.common.math.IntMath; import com.google.common.primitives.Ints; import java.util.AbstractCollection; @@ -128,7 +128,7 @@ static class FilteredCollection extends AbstractColl } FilteredCollection createCombined(Predicate newPredicate) { - return new FilteredCollection<>(unfiltered, Predicates.and(predicate, newPredicate)); + return new FilteredCollection<>(unfiltered, and(predicate, newPredicate)); } @Override diff --git a/android/guava/src/com/google/common/collect/FilteredKeyMultimap.java b/android/guava/src/com/google/common/collect/FilteredKeyMultimap.java index 280735c5b477..5ed5220d4e0f 100644 --- a/android/guava/src/com/google/common/collect/FilteredKeyMultimap.java +++ b/android/guava/src/com/google/common/collect/FilteredKeyMultimap.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkPositionIndex; +import static com.google.common.collect.Maps.filterKeys; import static java.util.Collections.emptyList; import static java.util.Collections.emptySet; @@ -217,7 +218,7 @@ Collection createValues() { @Override Map> createAsMap() { - return Maps.filterKeys(unfiltered.asMap(), keyPredicate); + return filterKeys(unfiltered.asMap(), keyPredicate); } @Override diff --git a/android/guava/src/com/google/common/collect/ImmutableRangeSet.java b/android/guava/src/com/google/common/collect/ImmutableRangeSet.java index fb2df807f301..bcee68581579 100644 --- a/android/guava/src/com/google/common/collect/ImmutableRangeSet.java +++ b/android/guava/src/com/google/common/collect/ImmutableRangeSet.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkElementIndex; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.Iterables.getOnlyElement; import static com.google.common.collect.Iterators.emptyIterator; import static com.google.common.collect.Iterators.peekingIterator; @@ -422,7 +423,7 @@ private ImmutableRangeSet lazyComplement() { * @since 21.0 */ public ImmutableRangeSet union(RangeSet other) { - return unionOf(Iterables.concat(asRanges(), other.asRanges())); + return unionOf(concat(asRanges(), other.asRanges())); } /** diff --git a/android/guava/src/com/google/common/collect/ImmutableSortedMultiset.java b/android/guava/src/com/google/common/collect/ImmutableSortedMultiset.java index 2f2399849fef..d42491959902 100644 --- a/android/guava/src/com/google/common/collect/ImmutableSortedMultiset.java +++ b/android/guava/src/com/google/common/collect/ImmutableSortedMultiset.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Lists.newArrayListWithCapacity; import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; @@ -191,7 +192,7 @@ public static > ImmutableSortedMultiset of( public static > ImmutableSortedMultiset of( E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) { int size = remaining.length + 6; - List all = Lists.newArrayListWithCapacity(size); + List all = newArrayListWithCapacity(size); Collections.addAll(all, e1, e2, e3, e4, e5, e6); Collections.addAll(all, remaining); return copyOf(Ordering.natural(), all); diff --git a/android/guava/src/com/google/common/collect/Iterables.java b/android/guava/src/com/google/common/collect/Iterables.java index d99e4124f766..ed252f1846bb 100644 --- a/android/guava/src/com/google/common/collect/Iterables.java +++ b/android/guava/src/com/google/common/collect/Iterables.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.instanceOf; import static com.google.common.collect.CollectPreconditions.checkRemove; import com.google.common.annotations.GwtCompatible; @@ -25,7 +26,6 @@ import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.InlineMe; import java.util.Collection; @@ -638,7 +638,7 @@ public Iterator iterator() { public static Iterable filter(Iterable unfiltered, Class desiredType) { checkNotNull(unfiltered); checkNotNull(desiredType); - return (Iterable) filter(unfiltered, Predicates.instanceOf(desiredType)); + return (Iterable) filter(unfiltered, instanceOf(desiredType)); } /** diff --git a/android/guava/src/com/google/common/collect/Maps.java b/android/guava/src/com/google/common/collect/Maps.java index fbbd2b70a702..2b2257a00f36 100644 --- a/android/guava/src/com/google/common/collect/Maps.java +++ b/android/guava/src/com/google/common/collect/Maps.java @@ -18,11 +18,14 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.and; import static com.google.common.base.Predicates.compose; import static com.google.common.collect.CollectPreconditions.checkEntryNotNull; import static com.google.common.collect.CollectPreconditions.checkNonnegative; import static com.google.common.collect.Iterables.any; +import static com.google.common.collect.Iterables.removeFirstMatching; import static com.google.common.collect.Iterators.filter; +import static com.google.common.collect.Iterators.transform; import static com.google.common.collect.NullnessCasts.uncheckedCastNullableTToT; import static com.google.common.collect.Sets.unmodifiableNavigableSet; import static java.lang.Math.ceil; @@ -38,7 +41,6 @@ import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.common.collect.MapDifference.ValueDifference; import com.google.common.primitives.Ints; import com.google.errorprone.annotations.CanIgnoreReturnValue; @@ -2070,8 +2072,7 @@ public Set keySet() { @Override Iterator> entryIterator() { - return Iterators.transform( - fromMap.entrySet().iterator(), asEntryToEntryFunction(transformer)); + return transform(fromMap.entrySet().iterator(), asEntryToEntryFunction(transformer)); } @Override @@ -2664,7 +2665,7 @@ NavigableMap filterEntries( */ private static Map filterFiltered( AbstractFilteredMap map, Predicate> entryPredicate) { - return new FilteredEntryMap<>(map.unfiltered, Predicates.and(map.predicate, entryPredicate)); + return new FilteredEntryMap<>(map.unfiltered, and(map.predicate, entryPredicate)); } /** @@ -2674,7 +2675,7 @@ NavigableMap filterEntries( private static SortedMap filterFiltered( FilteredEntrySortedMap map, Predicate> entryPredicate) { - Predicate> predicate = Predicates.and(map.predicate, entryPredicate); + Predicate> predicate = and(map.predicate, entryPredicate); return new FilteredEntrySortedMap<>(map.sortedMap(), predicate); } @@ -2686,7 +2687,7 @@ SortedMap filterFiltered( private static NavigableMap filterFiltered( FilteredEntryNavigableMap map, Predicate> entryPredicate) { - Predicate> predicate = Predicates.and(map.entryPredicate, entryPredicate); + Predicate> predicate = and(map.entryPredicate, entryPredicate); return new FilteredEntryNavigableMap<>(map.unfiltered, predicate); } @@ -2697,7 +2698,7 @@ NavigableMap filterFiltered( private static BiMap filterFiltered( FilteredEntryBiMap map, Predicate> entryPredicate) { - Predicate> predicate = Predicates.and(map.predicate, entryPredicate); + Predicate> predicate = and(map.predicate, entryPredicate); return new FilteredEntryBiMap<>(map.unfiltered(), predicate); } @@ -3184,12 +3185,12 @@ public Set> entrySet() { @Override public @Nullable Entry pollFirstEntry() { - return Iterables.removeFirstMatching(unfiltered.entrySet(), entryPredicate); + return removeFirstMatching(unfiltered.entrySet(), entryPredicate); } @Override public @Nullable Entry pollLastEntry() { - return Iterables.removeFirstMatching(unfiltered.descendingMap().entrySet(), entryPredicate); + return removeFirstMatching(unfiltered.descendingMap().entrySet(), entryPredicate); } @Override diff --git a/android/guava/src/com/google/common/collect/Multimaps.java b/android/guava/src/com/google/common/collect/Multimaps.java index dc5cb201780f..77d94466a05a 100644 --- a/android/guava/src/com/google/common/collect/Multimaps.java +++ b/android/guava/src/com/google/common/collect/Multimaps.java @@ -17,13 +17,16 @@ package com.google.common.collect; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.and; import static com.google.common.collect.CollectPreconditions.checkNonnegative; import static com.google.common.collect.CollectPreconditions.checkRemove; import static com.google.common.collect.Maps.immutableEntry; import static com.google.common.collect.Maps.safeGet; +import static com.google.common.collect.Maps.unmodifiableEntrySet; import static com.google.common.collect.Multisets.unmodifiableMultiset; import static com.google.common.collect.NullnessCasts.uncheckedCastNullableTToT; import static com.google.common.collect.Sets.unmodifiableNavigableSet; +import static java.util.Collections.unmodifiableCollection; import static java.util.Collections.unmodifiableList; import static java.util.Collections.unmodifiableMap; import static java.util.Collections.unmodifiableSet; @@ -35,7 +38,6 @@ import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Function; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.common.base.Supplier; import com.google.common.collect.Maps.EntryTransformer; import com.google.errorprone.annotations.CanIgnoreReturnValue; @@ -49,7 +51,6 @@ import java.io.Serializable; import java.util.AbstractCollection; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; @@ -256,7 +257,7 @@ protected Collection createCollection() { } else if (collection instanceof List) { return unmodifiableList((List) collection); } else { - return Collections.unmodifiableCollection(collection); + return unmodifiableCollection(collection); } } @@ -782,7 +783,7 @@ public Collection replaceValues(@ParametricNullness K key, Iterable values() { Collection result = values; if (result == null) { - values = result = Collections.unmodifiableCollection(delegate.values()); + values = result = unmodifiableCollection(delegate.values()); } return result; } @@ -843,7 +844,7 @@ public Set get(@ParametricNullness K key) { @Override public Set> entries() { - return Maps.unmodifiableEntrySet(delegate().entries()); + return unmodifiableEntrySet(delegate().entries()); } @Override @@ -1045,7 +1046,7 @@ public static ListMultimap unmodifiableListMultimap( } else if (collection instanceof List) { return unmodifiableList((List) collection); } - return Collections.unmodifiableCollection(collection); + return unmodifiableCollection(collection); } /** @@ -1059,9 +1060,9 @@ public static ListMultimap unmodifiableListMultimap( private static Collection> unmodifiableEntries(Collection> entries) { if (entries instanceof Set) { - return Maps.unmodifiableEntrySet((Set>) entries); + return unmodifiableEntrySet((Set>) entries); } - return new Maps.UnmodifiableEntries<>(Collections.unmodifiableCollection(entries)); + return new Maps.UnmodifiableEntries<>(unmodifiableCollection(entries)); } /** @@ -1951,8 +1952,7 @@ public void clear() { return filterKeys((ListMultimap) unfiltered, keyPredicate); } else if (unfiltered instanceof FilteredKeyMultimap) { FilteredKeyMultimap prev = (FilteredKeyMultimap) unfiltered; - return new FilteredKeyMultimap<>( - prev.unfiltered, Predicates.and(prev.keyPredicate, keyPredicate)); + return new FilteredKeyMultimap<>(prev.unfiltered, and(prev.keyPredicate, keyPredicate)); } else if (unfiltered instanceof FilteredMultimap) { FilteredMultimap prev = (FilteredMultimap) unfiltered; return filterFiltered(prev, Maps.keyPredicateOnEntries(keyPredicate)); @@ -1993,8 +1993,7 @@ SetMultimap filterKeys( SetMultimap unfiltered, Predicate keyPredicate) { if (unfiltered instanceof FilteredKeySetMultimap) { FilteredKeySetMultimap prev = (FilteredKeySetMultimap) unfiltered; - return new FilteredKeySetMultimap<>( - prev.unfiltered(), Predicates.and(prev.keyPredicate, keyPredicate)); + return new FilteredKeySetMultimap<>(prev.unfiltered(), and(prev.keyPredicate, keyPredicate)); } else if (unfiltered instanceof FilteredSetMultimap) { FilteredSetMultimap prev = (FilteredSetMultimap) unfiltered; return filterFiltered(prev, Maps.keyPredicateOnEntries(keyPredicate)); @@ -2035,8 +2034,7 @@ ListMultimap filterKeys( ListMultimap unfiltered, Predicate keyPredicate) { if (unfiltered instanceof FilteredKeyListMultimap) { FilteredKeyListMultimap prev = (FilteredKeyListMultimap) unfiltered; - return new FilteredKeyListMultimap<>( - prev.unfiltered(), Predicates.and(prev.keyPredicate, keyPredicate)); + return new FilteredKeyListMultimap<>(prev.unfiltered(), and(prev.keyPredicate, keyPredicate)); } else { return new FilteredKeyListMultimap<>(unfiltered, keyPredicate); } @@ -2187,7 +2185,7 @@ SetMultimap filterEntries( private static Multimap filterFiltered( FilteredMultimap multimap, Predicate> entryPredicate) { - Predicate> predicate = Predicates.and(multimap.entryPredicate(), entryPredicate); + Predicate> predicate = and(multimap.entryPredicate(), entryPredicate); return new FilteredEntryMultimap<>(multimap.unfiltered(), predicate); } @@ -2200,7 +2198,7 @@ Multimap filterFiltered( private static SetMultimap filterFiltered( FilteredSetMultimap multimap, Predicate> entryPredicate) { - Predicate> predicate = Predicates.and(multimap.entryPredicate(), entryPredicate); + Predicate> predicate = and(multimap.entryPredicate(), entryPredicate); return new FilteredEntrySetMultimap<>(multimap.unfiltered(), predicate); } diff --git a/android/guava/src/com/google/common/collect/Multisets.java b/android/guava/src/com/google/common/collect/Multisets.java index 5811e2dc6b96..887c233f58ff 100644 --- a/android/guava/src/com/google/common/collect/Multisets.java +++ b/android/guava/src/com/google/common/collect/Multisets.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.and; import static com.google.common.collect.CollectPreconditions.checkNonnegative; import static com.google.common.collect.CollectPreconditions.checkRemove; import static java.lang.Math.max; @@ -31,7 +32,6 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.common.collect.Multiset.Entry; import com.google.common.math.IntMath; import com.google.common.primitives.Ints; @@ -315,7 +315,7 @@ public final int getCount() { // Support clear(), removeAll(), and retainAll() when filtering a filtered // collection. FilteredMultiset filtered = (FilteredMultiset) unfiltered; - Predicate combinedPredicate = Predicates.and(filtered.predicate, predicate); + Predicate combinedPredicate = and(filtered.predicate, predicate); return new FilteredMultiset<>(filtered.unfiltered, combinedPredicate); } return new FilteredMultiset<>(unfiltered, predicate); diff --git a/android/guava/src/com/google/common/collect/Sets.java b/android/guava/src/com/google/common/collect/Sets.java index ba697fab8852..fab2fc56c278 100644 --- a/android/guava/src/com/google/common/collect/Sets.java +++ b/android/guava/src/com/google/common/collect/Sets.java @@ -18,8 +18,10 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.and; import static com.google.common.collect.CollectPreconditions.checkNonnegative; import static com.google.common.collect.Iterables.find; +import static com.google.common.collect.Iterables.removeFirstMatching; import static com.google.common.collect.Iterators.find; import static com.google.common.math.IntMath.saturatedAdd; import static java.lang.Math.max; @@ -31,7 +33,6 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.common.collect.Collections2.FilteredCollection; import com.google.common.math.IntMath; import com.google.errorprone.annotations.CanIgnoreReturnValue; @@ -1151,7 +1152,7 @@ int maxSize() { // Support clear(), removeAll(), and retainAll() when filtering a filtered // collection. FilteredSet filtered = (FilteredSet) unfiltered; - Predicate combinedPredicate = Predicates.and(filtered.predicate, predicate); + Predicate combinedPredicate = and(filtered.predicate, predicate); return new FilteredSet<>((Set) filtered.unfiltered, combinedPredicate); } @@ -1188,7 +1189,7 @@ int maxSize() { // Support clear(), removeAll(), and retainAll() when filtering a filtered // collection. FilteredSet filtered = (FilteredSet) unfiltered; - Predicate combinedPredicate = Predicates.and(filtered.predicate, predicate); + Predicate combinedPredicate = and(filtered.predicate, predicate); return new FilteredSortedSet<>((SortedSet) filtered.unfiltered, combinedPredicate); } @@ -1226,7 +1227,7 @@ int maxSize() { // Support clear(), removeAll(), and retainAll() when filtering a filtered // collection. FilteredSet filtered = (FilteredSet) unfiltered; - Predicate combinedPredicate = Predicates.and(filtered.predicate, predicate); + Predicate combinedPredicate = and(filtered.predicate, predicate); return new FilteredNavigableSet<>((NavigableSet) filtered.unfiltered, combinedPredicate); } @@ -1331,12 +1332,12 @@ NavigableSet unfiltered() { @Override public @Nullable E pollFirst() { - return Iterables.removeFirstMatching(unfiltered(), predicate); + return removeFirstMatching(unfiltered(), predicate); } @Override public @Nullable E pollLast() { - return Iterables.removeFirstMatching(unfiltered().descendingSet(), predicate); + return removeFirstMatching(unfiltered().descendingSet(), predicate); } @Override diff --git a/android/guava/src/com/google/common/collect/Tables.java b/android/guava/src/com/google/common/collect/Tables.java index b80702382fb3..44f262560142 100644 --- a/android/guava/src/com/google/common/collect/Tables.java +++ b/android/guava/src/com/google/common/collect/Tables.java @@ -18,7 +18,9 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterators.transform; import static com.google.common.collect.NullnessCasts.uncheckedCastNullableTToT; +import static java.util.Collections.unmodifiableCollection; import static java.util.Collections.unmodifiableMap; import static java.util.Collections.unmodifiableSet; import static java.util.Collections.unmodifiableSortedMap; @@ -319,7 +321,7 @@ public Collection values() { @Override Iterator> cellIterator() { - return Iterators.transform(original.cellSet().iterator(), Tables::transposeCell); + return transform(original.cellSet().iterator(), Tables::transposeCell); } } @@ -482,7 +484,7 @@ Cell applyToValue(Cell cell) { @Override Iterator> cellIterator() { - return Iterators.transform(fromTable.cellSet().iterator(), this::applyToValue); + return transform(fromTable.cellSet().iterator(), this::applyToValue); } @Override @@ -604,7 +606,7 @@ public Map> rowMap() { @Override public Collection values() { - return Collections.unmodifiableCollection(super.values()); + return unmodifiableCollection(super.values()); } @GwtIncompatible @J2ktIncompatible private static final long serialVersionUID = 0; diff --git a/android/guava/src/com/google/common/eventbus/SubscriberRegistry.java b/android/guava/src/com/google/common/eventbus/SubscriberRegistry.java index 158635ccdc54..7484d250f04a 100644 --- a/android/guava/src/com/google/common/eventbus/SubscriberRegistry.java +++ b/android/guava/src/com/google/common/eventbus/SubscriberRegistry.java @@ -16,6 +16,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterators.concat; +import static com.google.common.collect.Lists.newArrayListWithCapacity; import static java.util.Arrays.asList; import com.google.common.annotations.VisibleForTesting; @@ -26,8 +28,6 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.primitives.Primitives; @@ -125,8 +125,7 @@ Set getSubscribersForTesting(Class eventType) { Iterator getSubscribers(Object event) { ImmutableSet> eventTypes = flattenHierarchy(event.getClass()); - List> subscriberIterators = - Lists.newArrayListWithCapacity(eventTypes.size()); + List> subscriberIterators = newArrayListWithCapacity(eventTypes.size()); for (Class eventType : eventTypes) { CopyOnWriteArraySet eventSubscribers = subscribers.get(eventType); @@ -136,7 +135,7 @@ Iterator getSubscribers(Object event) { } } - return Iterators.concat(subscriberIterators.iterator()); + return concat(subscriberIterators.iterator()); } /** diff --git a/android/guava/src/com/google/common/graph/AbstractBaseGraph.java b/android/guava/src/com/google/common/graph/AbstractBaseGraph.java index c1ec51da5c5a..98572d071db2 100644 --- a/android/guava/src/com/google/common/graph/AbstractBaseGraph.java +++ b/android/guava/src/com/google/common/graph/AbstractBaseGraph.java @@ -19,6 +19,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static com.google.common.collect.Iterators.concat; +import static com.google.common.collect.Iterators.transform; import static com.google.common.graph.GraphConstants.ENDPOINTS_MISMATCH; import static com.google.common.graph.GraphConstants.NODE_PAIR_REMOVED_FROM_GRAPH; import static com.google.common.graph.GraphConstants.NODE_REMOVED_FROM_GRAPH; @@ -113,18 +115,18 @@ public Set> incidentEdges(N node) { public UnmodifiableIterator> iterator() { if (graph.isDirected()) { return Iterators.unmodifiableIterator( - Iterators.concat( - Iterators.transform( + concat( + transform( graph.predecessors(node).iterator(), (N predecessor) -> EndpointPair.ordered(predecessor, node)), - Iterators.transform( + transform( // filter out 'node' from successors (already covered by predecessors, // above) Sets.difference(graph.successors(node), ImmutableSet.of(node)).iterator(), (N successor) -> EndpointPair.ordered(node, successor)))); } else { return Iterators.unmodifiableIterator( - Iterators.transform( + transform( graph.adjacentNodes(node).iterator(), (N adjacentNode) -> EndpointPair.unordered(node, adjacentNode))); } @@ -250,7 +252,7 @@ public Set> inEdges(N node) { @Override public UnmodifiableIterator> iterator() { return Iterators.unmodifiableIterator( - Iterators.transform( + transform( graph.predecessors(node).iterator(), (N predecessor) -> graph.isDirected() @@ -270,7 +272,7 @@ public Set> outEdges(N node) { @Override public UnmodifiableIterator> iterator() { return Iterators.unmodifiableIterator( - Iterators.transform( + transform( graph.successors(node).iterator(), (N successor) -> graph.isDirected() diff --git a/android/guava/src/com/google/common/graph/AbstractDirectedNetworkConnections.java b/android/guava/src/com/google/common/graph/AbstractDirectedNetworkConnections.java index 9993dd91029e..ca63b49c0e70 100644 --- a/android/guava/src/com/google/common/graph/AbstractDirectedNetworkConnections.java +++ b/android/guava/src/com/google/common/graph/AbstractDirectedNetworkConnections.java @@ -18,12 +18,12 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static com.google.common.collect.Iterables.concat; import static com.google.common.graph.Graphs.checkNonNegative; import static com.google.common.graph.Graphs.checkPositive; import static java.util.Collections.unmodifiableSet; import static java.util.Objects.requireNonNull; -import com.google.common.collect.Iterables; import com.google.common.collect.Iterators; import com.google.common.collect.Sets; import com.google.common.collect.UnmodifiableIterator; @@ -68,7 +68,7 @@ public Set incidentEdges() { public UnmodifiableIterator iterator() { Iterable incidentEdges = (selfLoopCount == 0) - ? Iterables.concat(inEdgeMap.keySet(), outEdgeMap.keySet()) + ? concat(inEdgeMap.keySet(), outEdgeMap.keySet()) : Sets.union(inEdgeMap.keySet(), outEdgeMap.keySet()); return Iterators.unmodifiableIterator(incidentEdges.iterator()); } diff --git a/android/guava/src/com/google/common/graph/AbstractNetwork.java b/android/guava/src/com/google/common/graph/AbstractNetwork.java index 291a21658ef4..b676df409bcb 100644 --- a/android/guava/src/com/google/common/graph/AbstractNetwork.java +++ b/android/guava/src/com/google/common/graph/AbstractNetwork.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterators.transform; import static com.google.common.graph.GraphConstants.EDGE_REMOVED_FROM_GRAPH; import static com.google.common.graph.GraphConstants.ENDPOINTS_MISMATCH; import static com.google.common.graph.GraphConstants.MULTIPLE_EDGES_CONNECTING; @@ -27,7 +28,6 @@ import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterators; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import com.google.common.math.IntMath; @@ -71,8 +71,7 @@ public Set> edges() { return new AbstractSet>() { @Override public Iterator> iterator() { - return Iterators.transform( - AbstractNetwork.this.edges().iterator(), edge -> incidentNodes(edge)); + return transform(AbstractNetwork.this.edges().iterator(), edge -> incidentNodes(edge)); } @Override diff --git a/android/guava/src/com/google/common/graph/DirectedGraphConnections.java b/android/guava/src/com/google/common/graph/DirectedGraphConnections.java index bf1c04e9b3dd..87ac0ea4f427 100644 --- a/android/guava/src/com/google/common/graph/DirectedGraphConnections.java +++ b/android/guava/src/com/google/common/graph/DirectedGraphConnections.java @@ -19,6 +19,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static com.google.common.collect.Iterators.concat; +import static com.google.common.collect.Iterators.transform; import static com.google.common.graph.GraphConstants.INNER_CAPACITY; import static com.google.common.graph.GraphConstants.INNER_LOAD_FACTOR; import static com.google.common.graph.Graphs.checkNonNegative; @@ -28,7 +30,6 @@ import com.google.common.base.Function; import com.google.common.collect.AbstractIterator; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterators; import com.google.common.collect.UnmodifiableIterator; import java.util.AbstractSet; import java.util.ArrayList; @@ -371,16 +372,16 @@ public Iterator> incidentEdgeIterator(N thisNode) { Iterator> resultWithDoubleSelfLoop; if (orderedNodeConnections == null) { resultWithDoubleSelfLoop = - Iterators.concat( - Iterators.transform( + concat( + transform( predecessors().iterator(), (N predecessor) -> EndpointPair.ordered(predecessor, thisNode)), - Iterators.transform( + transform( successors().iterator(), (N successor) -> EndpointPair.ordered(thisNode, successor))); } else { resultWithDoubleSelfLoop = - Iterators.transform( + transform( orderedNodeConnections.iterator(), (NodeConnection connection) -> { if (connection instanceof NodeConnection.Succ) { diff --git a/android/guava/src/com/google/common/graph/Graphs.java b/android/guava/src/com/google/common/graph/Graphs.java index cbde28511ddc..bc3616e8ca94 100644 --- a/android/guava/src/com/google/common/graph/Graphs.java +++ b/android/guava/src/com/google/common/graph/Graphs.java @@ -17,12 +17,12 @@ package com.google.common.graph; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.collect.Iterators.transform; import static com.google.common.graph.GraphConstants.NODE_NOT_IN_GRAPH; import static com.google.common.graph.Graphs.TransitiveClosureSelfLoopStrategy.ADD_SELF_LOOPS_ALWAYS; import static java.util.Objects.requireNonNull; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterators; import com.google.common.collect.Maps; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.ArrayDeque; @@ -367,7 +367,7 @@ public Set> incidentEdges(N node) { return new IncidentEdgeSet(this, node, IncidentEdgeSet.EdgeType.BOTH) { @Override public Iterator> iterator() { - return Iterators.transform( + return transform( delegate().incidentEdges(node).iterator(), edge -> EndpointPair.of(delegate(), edge.nodeV(), edge.nodeU())); } diff --git a/android/guava/src/com/google/common/graph/UndirectedGraphConnections.java b/android/guava/src/com/google/common/graph/UndirectedGraphConnections.java index 8d2276a8666e..aaf0d5a84be4 100644 --- a/android/guava/src/com/google/common/graph/UndirectedGraphConnections.java +++ b/android/guava/src/com/google/common/graph/UndirectedGraphConnections.java @@ -17,12 +17,12 @@ package com.google.common.graph; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterators.transform; import static com.google.common.graph.GraphConstants.INNER_CAPACITY; import static com.google.common.graph.GraphConstants.INNER_LOAD_FACTOR; import static java.util.Collections.unmodifiableSet; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterators; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; @@ -78,7 +78,7 @@ public Set successors() { @Override public Iterator> incidentEdgeIterator(N thisNode) { - return Iterators.transform( + return transform( adjacentNodeValues.keySet().iterator(), (N incidentNode) -> EndpointPair.unordered(thisNode, incidentNode)); } diff --git a/android/guava/src/com/google/common/hash/BloomFilter.java b/android/guava/src/com/google/common/hash/BloomFilter.java index 2263ececce65..2da114920eed 100644 --- a/android/guava/src/com/google/common/hash/BloomFilter.java +++ b/android/guava/src/com/google/common/hash/BloomFilter.java @@ -19,6 +19,7 @@ import static java.lang.Byte.toUnsignedInt; import static java.lang.Math.log; import static java.lang.Math.max; +import static java.lang.Math.round; import com.google.common.annotations.Beta; import com.google.common.annotations.J2ktIncompatible; @@ -544,7 +545,7 @@ public int hashCode() { @VisibleForTesting static int optimalNumOfHashFunctions(double p) { // -log(p) / log(2), ensuring the result is rounded to avoid truncation. - return max(1, (int) Math.round(-log(p) / LOG_TWO)); + return max(1, (int) round(-log(p) / LOG_TWO)); } /** diff --git a/android/guava/src/com/google/common/math/LongMath.java b/android/guava/src/com/google/common/math/LongMath.java index fa0a4635adc7..f3c7728b8ba9 100644 --- a/android/guava/src/com/google/common/math/LongMath.java +++ b/android/guava/src/com/google/common/math/LongMath.java @@ -22,6 +22,7 @@ import static com.google.common.math.MathPreconditions.checkRoundingUnnecessary; import static java.lang.Math.abs; import static java.lang.Math.ceil; +import static java.lang.Math.floor; import static java.lang.Math.min; import static java.lang.Math.nextDown; import static java.lang.Math.nextUp; @@ -1299,7 +1300,7 @@ public static double roundToDouble(long x, RoundingMode mode) { roundCeilingAsDouble = roundArbitrarily; roundCeiling = roundArbitrarilyAsLong; roundFloorAsDouble = nextDown(roundArbitrarily); - roundFloor = (long) Math.floor(roundFloorAsDouble); + roundFloor = (long) floor(roundFloorAsDouble); } long deltaToFloor = x - roundFloor; diff --git a/android/guava/src/com/google/common/net/InetAddresses.java b/android/guava/src/com/google/common/net/InetAddresses.java index 0bfe6b26a559..b940760b75d7 100644 --- a/android/guava/src/com/google/common/net/InetAddresses.java +++ b/android/guava/src/com/google/common/net/InetAddresses.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.hash.Hashing.murmur3_32_fixed; +import static com.google.common.io.ByteStreams.newDataInput; import static java.lang.Math.max; import static java.lang.System.arraycopy; import static java.util.Objects.requireNonNull; @@ -25,7 +26,6 @@ import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.CharMatcher; import com.google.common.base.MoreObjects; -import com.google.common.io.ByteStreams; import com.google.common.primitives.Ints; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.FormatMethod; @@ -832,10 +832,10 @@ public static TeredoInfo getTeredoInfo(Inet6Address ip) { byte[] bytes = ip.getAddress(); Inet4Address server = getInet4Address(Arrays.copyOfRange(bytes, 4, 8)); - int flags = ByteStreams.newDataInput(bytes, 8).readShort() & 0xffff; + int flags = newDataInput(bytes, 8).readShort() & 0xffff; // Teredo obfuscates the mapped client port, per section 4 of the RFC. - int port = ~ByteStreams.newDataInput(bytes, 10).readShort() & 0xffff; + int port = ~newDataInput(bytes, 10).readShort() & 0xffff; byte[] clientBytes = Arrays.copyOfRange(bytes, 12, 16); for (int i = 0; i < clientBytes.length; i++) { @@ -1063,7 +1063,7 @@ public static Inet4Address getCoercedIPv4Address(InetAddress ip) { * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { - return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); + return newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); } /** diff --git a/android/guava/src/com/google/common/primitives/SignedBytes.java b/android/guava/src/com/google/common/primitives/SignedBytes.java index f66b4bc84cb1..77506e8beac1 100644 --- a/android/guava/src/com/google/common/primitives/SignedBytes.java +++ b/android/guava/src/com/google/common/primitives/SignedBytes.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkPositionIndexes; +import static com.google.common.primitives.Bytes.reverse; import static java.util.Arrays.sort; import com.google.common.annotations.GwtCompatible; @@ -212,6 +213,6 @@ public static void sortDescending(byte[] array, int fromIndex, int toIndex) { checkNotNull(array); checkPositionIndexes(fromIndex, toIndex, array.length); sort(array, fromIndex, toIndex); - Bytes.reverse(array, fromIndex, toIndex); + reverse(array, fromIndex, toIndex); } } diff --git a/android/guava/src/com/google/common/reflect/Invokable.java b/android/guava/src/com/google/common/reflect/Invokable.java index 84180208c354..2f5e65adebde 100644 --- a/android/guava/src/com/google/common/reflect/Invokable.java +++ b/android/guava/src/com/google/common/reflect/Invokable.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.reflect.Types.newParameterizedType; import static java.lang.System.arraycopy; import com.google.common.collect.ImmutableList; @@ -428,7 +429,7 @@ Type getGenericReturnType() { Class declaringClass = getDeclaringClass(); TypeVariable[] typeParams = declaringClass.getTypeParameters(); if (typeParams.length > 0) { - return Types.newParameterizedType(declaringClass, typeParams); + return newParameterizedType(declaringClass, typeParams); } else { return declaringClass; } diff --git a/android/guava/src/com/google/common/reflect/MutableTypeToInstanceMap.java b/android/guava/src/com/google/common/reflect/MutableTypeToInstanceMap.java index 7d355cc6677c..35701bb5cf04 100644 --- a/android/guava/src/com/google/common/reflect/MutableTypeToInstanceMap.java +++ b/android/guava/src/com/google/common/reflect/MutableTypeToInstanceMap.java @@ -15,11 +15,11 @@ package com.google.common.reflect; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterators.transform; import com.google.common.collect.ForwardingMap; import com.google.common.collect.ForwardingMapEntry; import com.google.common.collect.ForwardingSet; -import com.google.common.collect.Iterators; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.DoNotCall; import java.util.HashMap; @@ -155,7 +155,7 @@ public Object[] toArray() { private static Iterator> transformEntries( Iterator> entries) { - return Iterators.transform(entries, UnmodifiableEntry::new); + return transform(entries, UnmodifiableEntry::new); } private UnmodifiableEntry(Entry delegate) { diff --git a/android/guava/src/com/google/common/reflect/TypeResolver.java b/android/guava/src/com/google/common/reflect/TypeResolver.java index 9e184a47855d..e3542a917cbb 100644 --- a/android/guava/src/com/google/common/reflect/TypeResolver.java +++ b/android/guava/src/com/google/common/reflect/TypeResolver.java @@ -17,6 +17,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static com.google.common.reflect.Types.newArrayType; +import static com.google.common.reflect.Types.newArtificialTypeVariable; import static java.util.Arrays.asList; import com.google.common.base.Joiner; @@ -251,7 +253,7 @@ private WildcardType resolveWildcardType(WildcardType type) { private Type resolveGenericArrayType(GenericArrayType type) { Type componentType = type.getGenericComponentType(); Type resolvedComponentType = resolveType(componentType); - return Types.newArrayType(resolvedComponentType); + return newArrayType(resolvedComponentType); } private ParameterizedType resolveParameterizedType(ParameterizedType type) { @@ -380,7 +382,7 @@ Type resolveInternal(TypeVariable var, TypeTable forDependants) { && Arrays.equals(bounds, resolvedBounds)) { return var; } - return Types.newArtificialTypeVariable( + return newArtificialTypeVariable( var.getGenericDeclaration(), var.getName(), resolvedBounds); } // in case the type is yet another type variable. @@ -487,8 +489,7 @@ final Type capture(Type type) { } if (type instanceof GenericArrayType) { GenericArrayType arrayType = (GenericArrayType) type; - return Types.newArrayType( - notForTypeVariable().capture(arrayType.getGenericComponentType())); + return newArrayType(notForTypeVariable().capture(arrayType.getGenericComponentType())); } if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; @@ -519,7 +520,7 @@ final Type capture(Type type) { TypeVariable captureAsTypeVariable(Type[] upperBounds) { String name = "capture#" + id.incrementAndGet() + "-of ? extends " + Joiner.on('&').join(upperBounds); - return Types.newArtificialTypeVariable(WildcardCapturer.class, name, upperBounds); + return newArtificialTypeVariable(WildcardCapturer.class, name, upperBounds); } private WildcardCapturer forTypeVariable(TypeVariable typeParam) { diff --git a/android/guava/src/com/google/common/reflect/TypeToken.java b/android/guava/src/com/google/common/reflect/TypeToken.java index 0bbdae02ca87..486e3adda9e6 100644 --- a/android/guava/src/com/google/common/reflect/TypeToken.java +++ b/android/guava/src/com/google/common/reflect/TypeToken.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static com.google.common.reflect.Types.newArrayType; import static java.lang.Math.max; import static java.util.Arrays.asList; import static java.util.Objects.requireNonNull; @@ -1027,7 +1028,7 @@ private static Type canonicalizeWildcardsInType(Type type) { return canonicalizeWildcardsInParameterizedType((ParameterizedType) type); } if (type instanceof GenericArrayType) { - return Types.newArrayType( + return newArrayType( canonicalizeWildcardsInType(((GenericArrayType) type).getGenericComponentType())); } return type; @@ -1167,7 +1168,7 @@ private boolean isOwnedBySubtypeOf(Type supertype) { static TypeToken toGenericType(Class cls) { if (cls.isArray()) { Type arrayOfGenericType = - Types.newArrayType( + newArrayType( // If we are passed with int[].class, don't turn it to GenericArrayType toGenericType(cls.getComponentType()).runtimeType); @SuppressWarnings("unchecked") // array is covariant diff --git a/android/guava/src/com/google/common/util/concurrent/CycleDetectingLockFactory.java b/android/guava/src/com/google/common/util/concurrent/CycleDetectingLockFactory.java index 5a71a4c1b1b7..b2bb64796b1e 100644 --- a/android/guava/src/com/google/common/util/concurrent/CycleDetectingLockFactory.java +++ b/android/guava/src/com/google/common/util/concurrent/CycleDetectingLockFactory.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Lists.newArrayListWithCapacity; +import static com.google.common.collect.Sets.newIdentityHashSet; import static java.util.Collections.unmodifiableMap; import static java.util.Objects.requireNonNull; @@ -25,10 +26,8 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; import com.google.common.collect.MapMaker; import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import com.google.j2objc.annotations.Weak; import java.util.ArrayList; import java.util.Arrays; @@ -304,7 +303,7 @@ static > Map createNodes(Class clazz) { EnumMap map = Maps.newEnumMap(clazz); E[] keys = clazz.getEnumConstants(); int numKeys = keys.length; - ArrayList nodes = Lists.newArrayListWithCapacity(numKeys); + ArrayList nodes = newArrayListWithCapacity(numKeys); // Create a LockGraphNode for each enum value. for (E key : keys) { LockGraphNode node = new LockGraphNode(getLockName(key)); @@ -652,7 +651,7 @@ void checkAcquiredLock(Policy policy, LockGraphNode acquiredLock) { } // Otherwise, it's the first time seeing this lock relationship. Look for // a path from the acquiredLock to this. - Set seen = Sets.newIdentityHashSet(); + Set seen = newIdentityHashSet(); ExampleStackTrace path = acquiredLock.findPathTo(this, seen); if (path == null) { diff --git a/android/guava/src/com/google/common/util/concurrent/MoreExecutors.java b/android/guava/src/com/google/common/util/concurrent/MoreExecutors.java index c5e841278a75..00a610636919 100644 --- a/android/guava/src/com/google/common/util/concurrent/MoreExecutors.java +++ b/android/guava/src/com/google/common/util/concurrent/MoreExecutors.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Lists.newArrayListWithCapacity; import static com.google.common.util.concurrent.Callables.threadRenaming; import static com.google.common.util.concurrent.Internal.toNanosSaturated; import static com.google.common.util.concurrent.SneakyThrows.sneakyThrow; @@ -31,7 +32,6 @@ import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Supplier; -import com.google.common.collect.Lists; import com.google.common.collect.Queues; import com.google.common.util.concurrent.ForwardingListenableFuture.SimpleForwardingListenableFuture; import com.google.errorprone.annotations.CanIgnoreReturnValue; @@ -723,7 +723,7 @@ protected String pendingToString() { checkNotNull(unit); int ntasks = tasks.size(); checkArgument(ntasks > 0); - List> futures = Lists.newArrayListWithCapacity(ntasks); + List> futures = newArrayListWithCapacity(ntasks); BlockingQueue> futureQueue = Queues.newLinkedBlockingQueue(); long timeoutNanos = unit.toNanos(timeout); diff --git a/android/guava/src/com/google/common/util/concurrent/RateLimiter.java b/android/guava/src/com/google/common/util/concurrent/RateLimiter.java index f6c5c354578e..b80419a4ca23 100644 --- a/android/guava/src/com/google/common/util/concurrent/RateLimiter.java +++ b/android/guava/src/com/google/common/util/concurrent/RateLimiter.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.util.concurrent.Internal.toNanosSaturated; +import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly; import static java.lang.Math.max; import static java.util.concurrent.TimeUnit.MICROSECONDS; import static java.util.concurrent.TimeUnit.NANOSECONDS; @@ -487,7 +488,7 @@ protected long readMicros() { @Override protected void sleepMicrosUninterruptibly(long micros) { if (micros > 0) { - Uninterruptibles.sleepUninterruptibly(micros, MICROSECONDS); + sleepUninterruptibly(micros, MICROSECONDS); } } }; diff --git a/android/guava/src/com/google/common/util/concurrent/ServiceManager.java b/android/guava/src/com/google/common/util/concurrent/ServiceManager.java index 1d762f3ef4c6..61f4ed45246c 100644 --- a/android/guava/src/com/google/common/util/concurrent/ServiceManager.java +++ b/android/guava/src/com/google/common/util/concurrent/ServiceManager.java @@ -21,6 +21,7 @@ import static com.google.common.base.Predicates.in; import static com.google.common.base.Predicates.instanceOf; import static com.google.common.base.Predicates.not; +import static com.google.common.collect.Lists.newArrayListWithCapacity; import static com.google.common.collect.Maps.immutableEntry; import static com.google.common.collect.Multimaps.filterKeys; import static com.google.common.util.concurrent.Internal.toNanosSaturated; @@ -45,7 +46,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSetMultimap; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.MultimapBuilder; import com.google.common.collect.Multiset; @@ -648,7 +648,7 @@ ImmutableMap startupTimes() { List> loadTimes; monitor.enter(); try { - loadTimes = Lists.newArrayListWithCapacity(startupTimers.size()); + loadTimes = newArrayListWithCapacity(startupTimers.size()); // N.B. There will only be an entry in the map if the service has started for (Entry entry : startupTimers.entrySet()) { Service service = entry.getKey(); diff --git a/guava-testlib/src/com/google/common/testing/ArbitraryInstances.java b/guava-testlib/src/com/google/common/testing/ArbitraryInstances.java index 760a8df59acf..0256115e7859 100644 --- a/guava-testlib/src/com/google/common/testing/ArbitraryInstances.java +++ b/guava-testlib/src/com/google/common/testing/ArbitraryInstances.java @@ -18,6 +18,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.Iterators.peekingIterator; +import static com.google.common.collect.Maps.unmodifiableNavigableMap; +import static com.google.common.collect.Sets.newTreeSet; import static com.google.common.collect.Sets.unmodifiableNavigableSet; import static com.google.common.collect.Tables.unmodifiableRowSortedTable; import static java.nio.charset.StandardCharsets.UTF_8; @@ -63,7 +65,6 @@ import com.google.common.collect.Range; import com.google.common.collect.RowSortedTable; import com.google.common.collect.SetMultimap; -import com.google.common.collect.Sets; import com.google.common.collect.SortedMapDifference; import com.google.common.collect.SortedMultiset; import com.google.common.collect.SortedSetMultimap; @@ -263,12 +264,12 @@ private static MatchResult createMatchResult() { .put(ImmutableSet.class, ImmutableSet.of()) .put(SortedSet.class, ImmutableSortedSet.of()) .put(ImmutableSortedSet.class, ImmutableSortedSet.of()) - .put(NavigableSet.class, unmodifiableNavigableSet(Sets.newTreeSet())) + .put(NavigableSet.class, unmodifiableNavigableSet(newTreeSet())) .put(Map.class, ImmutableMap.of()) .put(ImmutableMap.class, ImmutableMap.of()) .put(SortedMap.class, ImmutableSortedMap.of()) .put(ImmutableSortedMap.class, ImmutableSortedMap.of()) - .put(NavigableMap.class, Maps.unmodifiableNavigableMap(Maps.newTreeMap())) + .put(NavigableMap.class, unmodifiableNavigableMap(Maps.newTreeMap())) .put(Multimap.class, ImmutableMultimap.of()) .put(ImmutableMultimap.class, ImmutableMultimap.of()) .put(ListMultimap.class, ImmutableListMultimap.of()) diff --git a/guava-testlib/src/com/google/common/testing/ClassSanityTester.java b/guava-testlib/src/com/google/common/testing/ClassSanityTester.java index f6c5d23a4f02..5a3b0c8e7fc0 100644 --- a/guava-testlib/src/com/google/common/testing/ClassSanityTester.java +++ b/guava-testlib/src/com/google/common/testing/ClassSanityTester.java @@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Throwables.throwIfUnchecked; +import static com.google.common.collect.Lists.newArrayListWithCapacity; import static com.google.common.testing.NullPointerTester.isNullable; import static com.google.common.testing.SerializableTester.reserialize; import static com.google.common.testing.SerializableTester.reserializeAndAssert; @@ -578,8 +579,8 @@ private void testEqualsUsing(Invokable factory) InvocationTargetException, FactoryMethodReturnsNullException { List params = factory.getParameters(); - List argGenerators = Lists.newArrayListWithCapacity(params.size()); - List<@Nullable Object> args = Lists.newArrayListWithCapacity(params.size()); + List argGenerators = newArrayListWithCapacity(params.size()); + List<@Nullable Object> args = newArrayListWithCapacity(params.size()); for (Parameter param : params) { FreshValueGenerator generator = newFreshValueGenerator(); argGenerators.add(generator); diff --git a/guava-testlib/src/com/google/common/testing/EqualsTester.java b/guava-testlib/src/com/google/common/testing/EqualsTester.java index 531d7453f095..729a9a242000 100644 --- a/guava-testlib/src/com/google/common/testing/EqualsTester.java +++ b/guava-testlib/src/com/google/common/testing/EqualsTester.java @@ -17,12 +17,12 @@ package com.google.common.testing; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.concat; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import com.google.common.annotations.GwtCompatible; import com.google.common.base.Equivalence; -import com.google.common.collect.Iterables; import com.google.common.testing.RelationshipTester.Item; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.ArrayList; @@ -139,7 +139,7 @@ public EqualsTester testEquals() { } private void testItems() { - for (Object item : Iterables.concat(equalityGroups)) { + for (Object item : concat(equalityGroups)) { assertTrue(item + " must not be Object#equals to null", !item.equals(null)); assertTrue( item + " must not be Object#equals to an arbitrary object of another class", diff --git a/guava-testlib/src/com/google/common/testing/FreshValueGenerator.java b/guava-testlib/src/com/google/common/testing/FreshValueGenerator.java index 7361e73fdf53..7101207a5b0b 100644 --- a/guava-testlib/src/com/google/common/testing/FreshValueGenerator.java +++ b/guava-testlib/src/com/google/common/testing/FreshValueGenerator.java @@ -18,6 +18,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Throwables.throwIfUnchecked; +import static com.google.common.collect.Lists.newArrayListWithCapacity; +import static com.google.common.collect.Sets.newTreeSet; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.asList; import static java.util.Objects.requireNonNull; @@ -52,7 +54,6 @@ import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.LinkedHashMultiset; import com.google.common.collect.ListMultimap; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.collect.Multiset; @@ -60,7 +61,6 @@ import com.google.common.collect.Range; import com.google.common.collect.RowSortedTable; import com.google.common.collect.SetMultimap; -import com.google.common.collect.Sets; import com.google.common.collect.SortedMultiset; import com.google.common.collect.Table; import com.google.common.collect.TreeBasedTable; @@ -243,7 +243,7 @@ final T newFreshProxy(Class interfaceType) { Method generate = GENERATORS.get(rawType); if (generate != null) { ImmutableList params = Invokable.from(generate).getParameters(); - List args = Lists.newArrayListWithCapacity(params.size()); + List args = newArrayListWithCapacity(params.size()); TypeVariable[] typeVars = rawType.getTypeParameters(); for (int i = 0; i < params.size(); i++) { TypeToken paramType = type.resolveType(typeVars[i]); @@ -732,7 +732,7 @@ static > NavigableSet generateNavigableSet(E @Generates static > TreeSet generateTreeSet(E freshElement) { - TreeSet set = Sets.newTreeSet(); + TreeSet set = newTreeSet(); set.add(freshElement); return set; } diff --git a/guava-testlib/test/com/google/common/collect/testing/SafeTreeSetTest.java b/guava-testlib/test/com/google/common/collect/testing/SafeTreeSetTest.java index 3cedfc02780e..6b6b0525ba11 100644 --- a/guava-testlib/test/com/google/common/collect/testing/SafeTreeSetTest.java +++ b/guava-testlib/test/com/google/common/collect/testing/SafeTreeSetTest.java @@ -16,6 +16,7 @@ package com.google.common.collect.testing; +import static com.google.common.collect.Sets.newTreeSet; import static com.google.common.testing.SerializableTester.reserialize; import static com.google.common.testing.SerializableTester.reserializeAndAssert; import static java.util.Arrays.asList; @@ -23,7 +24,6 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Ordering; -import com.google.common.collect.Sets; import com.google.common.collect.testing.features.CollectionFeature; import com.google.common.collect.testing.features.CollectionSize; import java.util.ArrayList; @@ -52,7 +52,7 @@ protected Set create(String[] elements) { @Override public List order(List insertionOrder) { - return new ArrayList<>(Sets.newTreeSet(insertionOrder)); + return new ArrayList<>(newTreeSet(insertionOrder)); } }) .withFeatures( @@ -73,7 +73,7 @@ protected Set create(String[] elements) { @Override public List order(List insertionOrder) { - return new ArrayList<>(Sets.newTreeSet(insertionOrder)); + return new ArrayList<>(newTreeSet(insertionOrder)); } }) .withFeatures( diff --git a/guava-tests/test/com/google/common/base/CharMatcherTest.java b/guava-tests/test/com/google/common/base/CharMatcherTest.java index 5ad4f4495cae..d2ff3a847de6 100644 --- a/guava-tests/test/com/google/common/base/CharMatcherTest.java +++ b/guava-tests/test/com/google/common/base/CharMatcherTest.java @@ -25,6 +25,7 @@ import static com.google.common.base.CharMatcher.noneOf; import static com.google.common.base.CharMatcher.whitespace; import static com.google.common.base.Predicates.equalTo; +import static com.google.common.base.Strings.repeat; import static com.google.common.truth.Truth.assertThat; import static java.util.Arrays.sort; import static org.junit.Assert.assertThrows; @@ -293,8 +294,8 @@ private void reallyTestAllMatches(CharMatcher matcher, CharSequence s) { assertTrue(matcher.matchesAllOf(s)); assertFalse(matcher.matchesNoneOf(s)); assertThat(matcher.removeFrom(s)).isEqualTo(""); - assertThat(matcher.replaceFrom(s, 'z')).isEqualTo(Strings.repeat("z", s.length())); - assertThat(matcher.replaceFrom(s, "ZZ")).isEqualTo(Strings.repeat("ZZ", s.length())); + assertThat(matcher.replaceFrom(s, 'z')).isEqualTo(repeat("z", s.length())); + assertThat(matcher.replaceFrom(s, "ZZ")).isEqualTo(repeat("ZZ", s.length())); assertThat(matcher.trimFrom(s)).isEqualTo(""); assertEquals(s.length(), matcher.countIn(s)); } diff --git a/guava-tests/test/com/google/common/base/PredicatesTest.java b/guava-tests/test/com/google/common/base/PredicatesTest.java index 5818057aaaec..3a0daccda39e 100644 --- a/guava-tests/test/com/google/common/base/PredicatesTest.java +++ b/guava-tests/test/com/google/common/base/PredicatesTest.java @@ -17,8 +17,12 @@ package com.google.common.base; import static com.google.common.base.CharMatcher.whitespace; +import static com.google.common.base.Predicates.and; import static com.google.common.base.Predicates.equalTo; +import static com.google.common.base.Predicates.instanceOf; import static com.google.common.base.Predicates.not; +import static com.google.common.base.Predicates.notNull; +import static com.google.common.base.Predicates.or; import static com.google.common.testing.SerializableTester.reserializeAndAssert; import static com.google.common.truth.Truth.assertThat; import static java.util.Arrays.asList; @@ -170,14 +174,14 @@ public void testNot_equalityForNotOfKnownValues() { new EqualsTester() .addEqualityGroup(Predicates.isNull(), Predicates.isNull()) - .addEqualityGroup(Predicates.notNull()) + .addEqualityGroup(notNull()) .addEqualityGroup(not(Predicates.isNull())) .testEquals(); new EqualsTester() - .addEqualityGroup(Predicates.notNull(), Predicates.notNull()) + .addEqualityGroup(notNull(), notNull()) .addEqualityGroup(Predicates.isNull()) - .addEqualityGroup(not(Predicates.notNull())) + .addEqualityGroup(not(notNull())) .testEquals(); } @@ -192,118 +196,116 @@ public void testNot_serialization() { */ public void testAnd_applyNoArgs() { - assertEvalsToTrue(Predicates.and()); + assertEvalsToTrue(and()); } public void testAnd_equalityNoArgs() { new EqualsTester() - .addEqualityGroup(Predicates.and(), Predicates.and()) - .addEqualityGroup(Predicates.and(FALSE)) - .addEqualityGroup(Predicates.or()) + .addEqualityGroup(and(), and()) + .addEqualityGroup(and(FALSE)) + .addEqualityGroup(or()) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testAnd_serializationNoArgs() { - checkSerialization(Predicates.and()); + checkSerialization(and()); } public void testAnd_applyOneArg() { - assertEvalsLikeOdd(Predicates.and(isOdd())); + assertEvalsLikeOdd(and(isOdd())); } public void testAnd_equalityOneArg() { - Object[] notEqualObjects = {Predicates.and(NEVER_REACHED, FALSE)}; + Object[] notEqualObjects = {and(NEVER_REACHED, FALSE)}; new EqualsTester() - .addEqualityGroup(Predicates.and(NEVER_REACHED), Predicates.and(NEVER_REACHED)) + .addEqualityGroup(and(NEVER_REACHED), and(NEVER_REACHED)) .addEqualityGroup(notEqualObjects) - .addEqualityGroup(Predicates.and(isOdd())) - .addEqualityGroup(Predicates.and()) - .addEqualityGroup(Predicates.or(NEVER_REACHED)) + .addEqualityGroup(and(isOdd())) + .addEqualityGroup(and()) + .addEqualityGroup(or(NEVER_REACHED)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testAnd_serializationOneArg() { - checkSerialization(Predicates.and(isOdd())); + checkSerialization(and(isOdd())); } public void testAnd_applyBinary() { - assertEvalsLikeOdd(Predicates.and(isOdd(), TRUE)); - assertEvalsLikeOdd(Predicates.and(TRUE, isOdd())); - assertEvalsToFalse(Predicates.and(FALSE, NEVER_REACHED)); + assertEvalsLikeOdd(and(isOdd(), TRUE)); + assertEvalsLikeOdd(and(TRUE, isOdd())); + assertEvalsToFalse(and(FALSE, NEVER_REACHED)); } public void testAnd_equalityBinary() { new EqualsTester() - .addEqualityGroup(Predicates.and(TRUE, NEVER_REACHED), Predicates.and(TRUE, NEVER_REACHED)) - .addEqualityGroup(Predicates.and(NEVER_REACHED, TRUE)) - .addEqualityGroup(Predicates.and(TRUE)) - .addEqualityGroup(Predicates.or(TRUE, NEVER_REACHED)) + .addEqualityGroup(and(TRUE, NEVER_REACHED), and(TRUE, NEVER_REACHED)) + .addEqualityGroup(and(NEVER_REACHED, TRUE)) + .addEqualityGroup(and(TRUE)) + .addEqualityGroup(or(TRUE, NEVER_REACHED)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testAnd_serializationBinary() { - checkSerialization(Predicates.and(TRUE, isOdd())); + checkSerialization(and(TRUE, isOdd())); } public void testAnd_applyTernary() { - assertEvalsLikeOdd(Predicates.and(isOdd(), TRUE, TRUE)); - assertEvalsLikeOdd(Predicates.and(TRUE, isOdd(), TRUE)); - assertEvalsLikeOdd(Predicates.and(TRUE, TRUE, isOdd())); - assertEvalsToFalse(Predicates.and(TRUE, FALSE, NEVER_REACHED)); + assertEvalsLikeOdd(and(isOdd(), TRUE, TRUE)); + assertEvalsLikeOdd(and(TRUE, isOdd(), TRUE)); + assertEvalsLikeOdd(and(TRUE, TRUE, isOdd())); + assertEvalsToFalse(and(TRUE, FALSE, NEVER_REACHED)); } public void testAnd_equalityTernary() { new EqualsTester() - .addEqualityGroup( - Predicates.and(TRUE, isOdd(), NEVER_REACHED), - Predicates.and(TRUE, isOdd(), NEVER_REACHED)) - .addEqualityGroup(Predicates.and(isOdd(), NEVER_REACHED, TRUE)) - .addEqualityGroup(Predicates.and(TRUE)) - .addEqualityGroup(Predicates.or(TRUE, isOdd(), NEVER_REACHED)) + .addEqualityGroup(and(TRUE, isOdd(), NEVER_REACHED), and(TRUE, isOdd(), NEVER_REACHED)) + .addEqualityGroup(and(isOdd(), NEVER_REACHED, TRUE)) + .addEqualityGroup(and(TRUE)) + .addEqualityGroup(or(TRUE, isOdd(), NEVER_REACHED)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testAnd_serializationTernary() { - checkSerialization(Predicates.and(TRUE, isOdd(), FALSE)); + checkSerialization(and(TRUE, isOdd(), FALSE)); } public void testAnd_applyIterable() { Collection> empty = asList(); - assertEvalsToTrue(Predicates.and(empty)); - assertEvalsLikeOdd(Predicates.and(asList(isOdd()))); - assertEvalsLikeOdd(Predicates.and(asList(TRUE, isOdd()))); - assertEvalsToFalse(Predicates.and(asList(FALSE, NEVER_REACHED))); + assertEvalsToTrue(and(empty)); + assertEvalsLikeOdd(and(asList(isOdd()))); + assertEvalsLikeOdd(and(asList(TRUE, isOdd()))); + assertEvalsToFalse(and(asList(FALSE, NEVER_REACHED))); } public void testAnd_equalityIterable() { new EqualsTester() .addEqualityGroup( - Predicates.and(asList(TRUE, NEVER_REACHED)), - Predicates.and(asList(TRUE, NEVER_REACHED)), - Predicates.and(TRUE, NEVER_REACHED)) - .addEqualityGroup(Predicates.and(FALSE, NEVER_REACHED)) - .addEqualityGroup(Predicates.or(TRUE, NEVER_REACHED)) + and(asList(TRUE, NEVER_REACHED)), + and(asList(TRUE, NEVER_REACHED)), + and(TRUE, NEVER_REACHED)) + .addEqualityGroup(and(FALSE, NEVER_REACHED)) + .addEqualityGroup(or(TRUE, NEVER_REACHED)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testAnd_serializationIterable() { - checkSerialization(Predicates.and(asList(TRUE, FALSE))); + checkSerialization(and(asList(TRUE, FALSE))); } public void testAnd_arrayDefensivelyCopied() { @SuppressWarnings("unchecked") // generic arrays Predicate[] array = (Predicate[]) new Predicate[] {Predicates.alwaysFalse()}; - Predicate predicate = Predicates.and(array); + Predicate predicate = and(array); assertFalse(predicate.apply(1)); array[0] = Predicates.alwaysTrue(); assertFalse(predicate.apply(1)); @@ -311,7 +313,7 @@ public void testAnd_arrayDefensivelyCopied() { public void testAnd_listDefensivelyCopied() { List> list = new ArrayList<>(); - Predicate predicate = Predicates.and(list); + Predicate predicate = and(list); assertTrue(predicate.apply(1)); list.add(Predicates.alwaysFalse()); assertTrue(predicate.apply(1)); @@ -326,7 +328,7 @@ public Iterator> iterator() { return list.iterator(); } }; - Predicate predicate = Predicates.and(iterable); + Predicate predicate = and(iterable); assertTrue(predicate.apply(1)); list.add(Predicates.alwaysFalse()); assertTrue(predicate.apply(1)); @@ -337,48 +339,48 @@ public Iterator> iterator() { */ public void testOr_applyNoArgs() { - assertEvalsToFalse(Predicates.or()); + assertEvalsToFalse(or()); } public void testOr_equalityNoArgs() { new EqualsTester() - .addEqualityGroup(Predicates.or(), Predicates.or()) - .addEqualityGroup(Predicates.or(TRUE)) - .addEqualityGroup(Predicates.and()) + .addEqualityGroup(or(), or()) + .addEqualityGroup(or(TRUE)) + .addEqualityGroup(and()) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testOr_serializationNoArgs() { - checkSerialization(Predicates.or()); + checkSerialization(or()); } public void testOr_applyOneArg() { - assertEvalsToTrue(Predicates.or(TRUE)); - assertEvalsToFalse(Predicates.or(FALSE)); + assertEvalsToTrue(or(TRUE)); + assertEvalsToFalse(or(FALSE)); } public void testOr_equalityOneArg() { new EqualsTester() - .addEqualityGroup(Predicates.or(NEVER_REACHED), Predicates.or(NEVER_REACHED)) - .addEqualityGroup(Predicates.or(NEVER_REACHED, TRUE)) - .addEqualityGroup(Predicates.or(TRUE)) - .addEqualityGroup(Predicates.or()) - .addEqualityGroup(Predicates.and(NEVER_REACHED)) + .addEqualityGroup(or(NEVER_REACHED), or(NEVER_REACHED)) + .addEqualityGroup(or(NEVER_REACHED, TRUE)) + .addEqualityGroup(or(TRUE)) + .addEqualityGroup(or()) + .addEqualityGroup(and(NEVER_REACHED)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testOr_serializationOneArg() { - checkSerialization(Predicates.or(isOdd())); + checkSerialization(or(isOdd())); } public void testOr_applyBinary() { - Predicate<@Nullable Integer> falseOrFalse = Predicates.or(FALSE, FALSE); - Predicate<@Nullable Integer> falseOrTrue = Predicates.or(FALSE, TRUE); - Predicate<@Nullable Integer> trueOrAnything = Predicates.or(TRUE, NEVER_REACHED); + Predicate<@Nullable Integer> falseOrFalse = or(FALSE, FALSE); + Predicate<@Nullable Integer> falseOrTrue = or(FALSE, TRUE); + Predicate<@Nullable Integer> trueOrAnything = or(TRUE, NEVER_REACHED); assertEvalsToFalse(falseOrFalse); assertEvalsToTrue(falseOrTrue); @@ -387,46 +389,45 @@ public void testOr_applyBinary() { public void testOr_equalityBinary() { new EqualsTester() - .addEqualityGroup(Predicates.or(FALSE, NEVER_REACHED), Predicates.or(FALSE, NEVER_REACHED)) - .addEqualityGroup(Predicates.or(NEVER_REACHED, FALSE)) - .addEqualityGroup(Predicates.or(TRUE)) - .addEqualityGroup(Predicates.and(FALSE, NEVER_REACHED)) + .addEqualityGroup(or(FALSE, NEVER_REACHED), or(FALSE, NEVER_REACHED)) + .addEqualityGroup(or(NEVER_REACHED, FALSE)) + .addEqualityGroup(or(TRUE)) + .addEqualityGroup(and(FALSE, NEVER_REACHED)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testOr_serializationBinary() { - checkSerialization(Predicates.or(isOdd(), TRUE)); + checkSerialization(or(isOdd(), TRUE)); } public void testOr_applyTernary() { - assertEvalsLikeOdd(Predicates.or(isOdd(), FALSE, FALSE)); - assertEvalsLikeOdd(Predicates.or(FALSE, isOdd(), FALSE)); - assertEvalsLikeOdd(Predicates.or(FALSE, FALSE, isOdd())); - assertEvalsToTrue(Predicates.or(FALSE, TRUE, NEVER_REACHED)); + assertEvalsLikeOdd(or(isOdd(), FALSE, FALSE)); + assertEvalsLikeOdd(or(FALSE, isOdd(), FALSE)); + assertEvalsLikeOdd(or(FALSE, FALSE, isOdd())); + assertEvalsToTrue(or(FALSE, TRUE, NEVER_REACHED)); } public void testOr_equalityTernary() { new EqualsTester() - .addEqualityGroup( - Predicates.or(FALSE, NEVER_REACHED, TRUE), Predicates.or(FALSE, NEVER_REACHED, TRUE)) - .addEqualityGroup(Predicates.or(TRUE, NEVER_REACHED, FALSE)) - .addEqualityGroup(Predicates.or(TRUE)) - .addEqualityGroup(Predicates.and(FALSE, NEVER_REACHED, TRUE)) + .addEqualityGroup(or(FALSE, NEVER_REACHED, TRUE), or(FALSE, NEVER_REACHED, TRUE)) + .addEqualityGroup(or(TRUE, NEVER_REACHED, FALSE)) + .addEqualityGroup(or(TRUE)) + .addEqualityGroup(and(FALSE, NEVER_REACHED, TRUE)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testOr_serializationTernary() { - checkSerialization(Predicates.or(FALSE, isOdd(), TRUE)); + checkSerialization(or(FALSE, isOdd(), TRUE)); } public void testOr_applyIterable() { - Predicate<@Nullable Integer> vacuouslyFalse = Predicates.or(ImmutableList.of()); - Predicate<@Nullable Integer> troo = Predicates.or(ImmutableList.of(TRUE)); - Predicate<@Nullable Integer> trueAndFalse = Predicates.or(ImmutableList.of(TRUE, FALSE)); + Predicate<@Nullable Integer> vacuouslyFalse = or(ImmutableList.of()); + Predicate<@Nullable Integer> troo = or(ImmutableList.of(TRUE)); + Predicate<@Nullable Integer> trueAndFalse = or(ImmutableList.of(TRUE, FALSE)); assertEvalsToFalse(vacuouslyFalse); assertEvalsToTrue(troo); @@ -436,18 +437,18 @@ public void testOr_applyIterable() { public void testOr_equalityIterable() { new EqualsTester() .addEqualityGroup( - Predicates.or(asList(FALSE, NEVER_REACHED)), - Predicates.or(asList(FALSE, NEVER_REACHED)), - Predicates.or(FALSE, NEVER_REACHED)) - .addEqualityGroup(Predicates.or(TRUE, NEVER_REACHED)) - .addEqualityGroup(Predicates.and(FALSE, NEVER_REACHED)) + or(asList(FALSE, NEVER_REACHED)), + or(asList(FALSE, NEVER_REACHED)), + or(FALSE, NEVER_REACHED)) + .addEqualityGroup(or(TRUE, NEVER_REACHED)) + .addEqualityGroup(and(FALSE, NEVER_REACHED)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // SerializableTester public void testOr_serializationIterable() { - Predicate pre = Predicates.or(asList(TRUE, FALSE)); + Predicate pre = or(asList(TRUE, FALSE)); Predicate post = reserializeAndAssert(pre); assertEquals(pre.apply(0), post.apply(0)); } @@ -455,7 +456,7 @@ public void testOr_serializationIterable() { public void testOr_arrayDefensivelyCopied() { @SuppressWarnings("unchecked") // generic arrays Predicate[] array = (Predicate[]) new Predicate[] {Predicates.alwaysFalse()}; - Predicate predicate = Predicates.or(array); + Predicate predicate = or(array); assertFalse(predicate.apply(1)); array[0] = Predicates.alwaysTrue(); assertFalse(predicate.apply(1)); @@ -463,7 +464,7 @@ public void testOr_arrayDefensivelyCopied() { public void testOr_listDefensivelyCopied() { List> list = new ArrayList<>(); - Predicate predicate = Predicates.or(list); + Predicate predicate = or(list); assertFalse(predicate.apply(1)); list.add(Predicates.alwaysTrue()); assertFalse(predicate.apply(1)); @@ -478,7 +479,7 @@ public Iterator> iterator() { return list.iterator(); } }; - Predicate predicate = Predicates.or(iterable); + Predicate predicate = or(iterable); assertFalse(predicate.apply(1)); list.add(Predicates.alwaysTrue()); assertFalse(predicate.apply(1)); @@ -539,7 +540,7 @@ public void testIsEqualToNull_serialization() { */ @GwtIncompatible // Predicates.instanceOf public void testIsInstanceOf_apply() { - Predicate<@Nullable Object> isInteger = Predicates.instanceOf(Integer.class); + Predicate<@Nullable Object> isInteger = instanceOf(Integer.class); assertTrue(isInteger.apply(1)); assertFalse(isInteger.apply(2.0f)); @@ -549,7 +550,7 @@ public void testIsInstanceOf_apply() { @GwtIncompatible // Predicates.instanceOf public void testIsInstanceOf_subclass() { - Predicate<@Nullable Object> isNumber = Predicates.instanceOf(Number.class); + Predicate<@Nullable Object> isNumber = instanceOf(Number.class); assertTrue(isNumber.apply(1)); assertTrue(isNumber.apply(2.0f)); @@ -559,7 +560,7 @@ public void testIsInstanceOf_subclass() { @GwtIncompatible // Predicates.instanceOf public void testIsInstanceOf_interface() { - Predicate<@Nullable Object> isComparable = Predicates.instanceOf(Comparable.class); + Predicate<@Nullable Object> isComparable = instanceOf(Comparable.class); assertTrue(isComparable.apply(1)); assertTrue(isComparable.apply(2.0f)); @@ -570,17 +571,16 @@ public void testIsInstanceOf_interface() { @GwtIncompatible // Predicates.instanceOf public void testIsInstanceOf_equality() { new EqualsTester() - .addEqualityGroup( - Predicates.instanceOf(Integer.class), Predicates.instanceOf(Integer.class)) - .addEqualityGroup(Predicates.instanceOf(Number.class)) - .addEqualityGroup(Predicates.instanceOf(Float.class)) + .addEqualityGroup(instanceOf(Integer.class), instanceOf(Integer.class)) + .addEqualityGroup(instanceOf(Number.class)) + .addEqualityGroup(instanceOf(Float.class)) .testEquals(); } @J2ktIncompatible @GwtIncompatible // Predicates.instanceOf, SerializableTester public void testIsInstanceOf_serialization() { - checkSerialization(Predicates.instanceOf(Integer.class)); + checkSerialization(instanceOf(Integer.class)); } @J2ktIncompatible @@ -646,7 +646,7 @@ public void testIsNull_apply() { public void testIsNull_equality() { new EqualsTester() .addEqualityGroup(Predicates.isNull(), Predicates.isNull()) - .addEqualityGroup(Predicates.notNull()) + .addEqualityGroup(notNull()) .testEquals(); } @@ -660,14 +660,14 @@ public void testIsNull_serialization() { } public void testNotNull_apply() { - Predicate<@Nullable Integer> notNull = Predicates.notNull(); + Predicate<@Nullable Integer> notNull = notNull(); assertFalse(notNull.apply(null)); assertTrue(notNull.apply(1)); } public void testNotNull_equality() { new EqualsTester() - .addEqualityGroup(Predicates.notNull(), Predicates.notNull()) + .addEqualityGroup(notNull(), notNull()) .addEqualityGroup(Predicates.isNull()) .testEquals(); } @@ -675,7 +675,7 @@ public void testNotNull_equality() { @J2ktIncompatible @GwtIncompatible // SerializableTester public void testNotNull_serialization() { - checkSerialization(Predicates.notNull()); + checkSerialization(notNull()); } public void testIn_apply() { @@ -766,14 +766,14 @@ public void testCascadingSerialization() throws Exception { // Eclipse says Predicate; javac says Predicate. Predicate nasty = not( - Predicates.and( - Predicates.or( + and( + or( equalTo((Object) 1), equalTo(null), Predicates.alwaysFalse(), Predicates.alwaysTrue(), Predicates.isNull(), - Predicates.notNull(), + notNull(), Predicates.in(asList(1))))); assertEvalsToFalse(nasty); @@ -889,13 +889,13 @@ public void testHashCodeForBooleanOperations() { // Make sure that hash codes are not computed per-instance. assertEqualHashCode(not(p1), not(p1)); - assertEqualHashCode(Predicates.and(p1, p2), Predicates.and(p1, p2)); + assertEqualHashCode(and(p1, p2), and(p1, p2)); - assertEqualHashCode(Predicates.or(p1, p2), Predicates.or(p1, p2)); + assertEqualHashCode(or(p1, p2), or(p1, p2)); // While not a contractual requirement, we'd like the hash codes for ands // & ors of the same predicates to not collide. - assertTrue(Predicates.and(p1, p2).hashCode() != Predicates.or(p1, p2).hashCode()); + assertTrue(and(p1, p2).hashCode() != or(p1, p2).hashCode()); } @J2ktIncompatible diff --git a/guava-tests/test/com/google/common/base/StringsTest.java b/guava-tests/test/com/google/common/base/StringsTest.java index 1b4921db1811..4a099e3eecb5 100644 --- a/guava-tests/test/com/google/common/base/StringsTest.java +++ b/guava-tests/test/com/google/common/base/StringsTest.java @@ -16,6 +16,7 @@ package com.google.common.base; +import static com.google.common.base.Strings.repeat; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; @@ -105,20 +106,19 @@ public void testPadEnd_null() { @SuppressWarnings("InlineMeInliner") // test of method that doesn't just delegate public void testRepeat() { String input = "20"; - assertThat(Strings.repeat(input, 0)).isEqualTo(""); - assertThat(Strings.repeat(input, 1)).isEqualTo("20"); - assertThat(Strings.repeat(input, 2)).isEqualTo("2020"); - assertThat(Strings.repeat(input, 3)).isEqualTo("202020"); + assertThat(repeat(input, 0)).isEqualTo(""); + assertThat(repeat(input, 1)).isEqualTo("20"); + assertThat(repeat(input, 2)).isEqualTo("2020"); + assertThat(repeat(input, 3)).isEqualTo("202020"); - assertThat(Strings.repeat("", 4)).isEqualTo(""); + assertThat(repeat("", 4)).isEqualTo(""); for (int i = 0; i < 100; ++i) { - assertEquals(2 * i, Strings.repeat(input, i).length()); + assertEquals(2 * i, repeat(input, i).length()); } - assertThrows(IllegalArgumentException.class, () -> Strings.repeat("x", -1)); - assertThrows( - ArrayIndexOutOfBoundsException.class, () -> Strings.repeat("12345678", (1 << 30) + 3)); + assertThrows(IllegalArgumentException.class, () -> repeat("x", -1)); + assertThrows(ArrayIndexOutOfBoundsException.class, () -> repeat("12345678", (1 << 30) + 3)); } @SuppressWarnings({ @@ -126,7 +126,7 @@ public void testRepeat() { "nullness", // test of a bogus call }) public void testRepeat_null() { - assertThrows(NullPointerException.class, () -> Strings.repeat(null, 5)); + assertThrows(NullPointerException.class, () -> repeat(null, 5)); } @SuppressWarnings("UnnecessaryStringBuilder") // We want to test a non-String CharSequence diff --git a/guava-tests/test/com/google/common/cache/CacheBuilderFactory.java b/guava-tests/test/com/google/common/cache/CacheBuilderFactory.java index f7dc4c375f20..a66e5eab3a19 100644 --- a/guava-tests/test/com/google/common/cache/CacheBuilderFactory.java +++ b/guava-tests/test/com/google/common/cache/CacheBuilderFactory.java @@ -19,12 +19,12 @@ import static com.google.common.collect.Lists.transform; import static com.google.common.collect.Sets.cartesianProduct; import static com.google.common.collect.Sets.newHashSet; +import static com.google.common.collect.Sets.newLinkedHashSet; import com.google.common.base.MoreObjects; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.cache.LocalCache.Strength; -import com.google.common.collect.Sets; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.LinkedHashSet; import java.util.List; @@ -136,7 +136,7 @@ Iterable> buildAllPermutations() { private Iterable> buildCartesianProduct(Set... sets) { List>> optionalSets = newArrayListWithExpectedSize(sets.length); for (Set set : sets) { - Set> optionalSet = Sets.newLinkedHashSet(transform(set, Optional::fromNullable)); + Set> optionalSet = newLinkedHashSet(transform(set, Optional::fromNullable)); optionalSets.add(optionalSet); } Set>> cartesianProduct = cartesianProduct(optionalSets); diff --git a/guava-tests/test/com/google/common/cache/CacheTesting.java b/guava-tests/test/com/google/common/cache/CacheTesting.java index 6c33cde9d009..b6645bb9d931 100644 --- a/guava-tests/test/com/google/common/cache/CacheTesting.java +++ b/guava-tests/test/com/google/common/cache/CacheTesting.java @@ -15,6 +15,7 @@ package com.google.common.cache; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Sets.newIdentityHashSet; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; import static java.lang.Math.max; @@ -27,7 +28,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; import com.google.common.testing.EqualsTester; import com.google.common.testing.FakeTicker; import java.lang.ref.Reference; @@ -218,7 +218,7 @@ static void checkExpiration(Cache cache) { static void checkExpiration(LocalCache cchm) { for (Segment segment : cchm.segments) { if (cchm.usesWriteQueue()) { - Set> entries = Sets.newIdentityHashSet(); + Set> entries = newIdentityHashSet(); ReferenceEntry prev = null; for (ReferenceEntry current : segment.writeQueue) { @@ -240,7 +240,7 @@ static void checkExpiration(LocalCache cchm) { } if (cchm.usesAccessQueue()) { - Set> entries = Sets.newIdentityHashSet(); + Set> entries = newIdentityHashSet(); ReferenceEntry prev = null; for (ReferenceEntry current : segment.accessQueue) { diff --git a/guava-tests/test/com/google/common/collect/AbstractFilteredMapTest.java b/guava-tests/test/com/google/common/collect/AbstractFilteredMapTest.java index 179bb2b59021..33beee99a01e 100644 --- a/guava-tests/test/com/google/common/collect/AbstractFilteredMapTest.java +++ b/guava-tests/test/com/google/common/collect/AbstractFilteredMapTest.java @@ -16,6 +16,9 @@ package com.google.common.collect; +import static com.google.common.collect.Maps.filterEntries; +import static com.google.common.collect.Maps.filterKeys; +import static com.google.common.collect.Maps.filterValues; import static org.junit.Assert.assertThrows; import com.google.common.annotations.GwtCompatible; @@ -40,7 +43,7 @@ abstract class AbstractFilteredMapTest extends TestCase { public void testFilteredKeysIllegalPut() { Map unfiltered = createUnfiltered(); - Map filtered = Maps.filterKeys(unfiltered, NOT_LENGTH_3); + Map filtered = filterKeys(unfiltered, NOT_LENGTH_3); filtered.put("a", 1); filtered.put("b", 2); assertEquals(ImmutableMap.of("a", 1, "b", 2), filtered); @@ -50,7 +53,7 @@ public void testFilteredKeysIllegalPut() { public void testFilteredKeysIllegalPutAll() { Map unfiltered = createUnfiltered(); - Map filtered = Maps.filterKeys(unfiltered, NOT_LENGTH_3); + Map filtered = filterKeys(unfiltered, NOT_LENGTH_3); filtered.put("a", 1); filtered.put("b", 2); assertEquals(ImmutableMap.of("a", 1, "b", 2), filtered); @@ -64,7 +67,7 @@ public void testFilteredKeysIllegalPutAll() { public void testFilteredKeysFilteredReflectsBackingChanges() { Map unfiltered = createUnfiltered(); - Map filtered = Maps.filterKeys(unfiltered, NOT_LENGTH_3); + Map filtered = filterKeys(unfiltered, NOT_LENGTH_3); unfiltered.put("two", 2); unfiltered.put("three", 3); unfiltered.put("four", 4); @@ -82,7 +85,7 @@ public void testFilteredKeysFilteredReflectsBackingChanges() { public void testFilteredValuesIllegalPut() { Map unfiltered = createUnfiltered(); - Map filtered = Maps.filterValues(unfiltered, EVEN); + Map filtered = filterValues(unfiltered, EVEN); filtered.put("a", 2); unfiltered.put("b", 4); unfiltered.put("c", 5); @@ -94,7 +97,7 @@ public void testFilteredValuesIllegalPut() { public void testFilteredValuesIllegalPutAll() { Map unfiltered = createUnfiltered(); - Map filtered = Maps.filterValues(unfiltered, EVEN); + Map filtered = filterValues(unfiltered, EVEN); filtered.put("a", 2); unfiltered.put("b", 4); unfiltered.put("c", 5); @@ -108,7 +111,7 @@ public void testFilteredValuesIllegalPutAll() { public void testFilteredValuesIllegalSetValue() { Map unfiltered = createUnfiltered(); - Map filtered = Maps.filterValues(unfiltered, EVEN); + Map filtered = filterValues(unfiltered, EVEN); filtered.put("a", 2); filtered.put("b", 4); assertEquals(ImmutableMap.of("a", 2, "b", 4), filtered); @@ -125,7 +128,7 @@ public void testFilteredValuesClear() { unfiltered.put("two", 2); unfiltered.put("three", 3); unfiltered.put("four", 4); - Map filtered = Maps.filterValues(unfiltered, EVEN); + Map filtered = filterValues(unfiltered, EVEN); assertEquals(ImmutableMap.of("one", 1, "two", 2, "three", 3, "four", 4), unfiltered); assertEquals(ImmutableMap.of("two", 2, "four", 4), filtered); @@ -139,7 +142,7 @@ public void testFilteredEntriesIllegalPut() { unfiltered.put("cat", 3); unfiltered.put("dog", 2); unfiltered.put("horse", 5); - Map filtered = Maps.filterEntries(unfiltered, CORRECT_LENGTH); + Map filtered = filterEntries(unfiltered, CORRECT_LENGTH); assertEquals(ImmutableMap.of("cat", 3, "horse", 5), filtered); filtered.put("chicken", 7); @@ -154,7 +157,7 @@ public void testFilteredEntriesIllegalPutAll() { unfiltered.put("cat", 3); unfiltered.put("dog", 2); unfiltered.put("horse", 5); - Map filtered = Maps.filterEntries(unfiltered, CORRECT_LENGTH); + Map filtered = filterEntries(unfiltered, CORRECT_LENGTH); assertEquals(ImmutableMap.of("cat", 3, "horse", 5), filtered); filtered.put("chicken", 7); @@ -172,7 +175,7 @@ public void testFilteredEntriesObjectPredicate() { unfiltered.put("dog", 2); unfiltered.put("horse", 5); Predicate predicate = Predicates.alwaysFalse(); - Map filtered = Maps.filterEntries(unfiltered, predicate); + Map filtered = filterEntries(unfiltered, predicate); assertTrue(filtered.isEmpty()); } @@ -182,7 +185,7 @@ public void testFilteredEntriesWildCardEntryPredicate() { unfiltered.put("dog", 2); unfiltered.put("horse", 5); Predicate> predicate = e -> e.getKey().equals("cat") || e.getValue().equals(2); - Map filtered = Maps.filterEntries(unfiltered, predicate); + Map filtered = filterEntries(unfiltered, predicate); assertEquals(ImmutableMap.of("cat", 3, "dog", 2), filtered); } } diff --git a/guava-tests/test/com/google/common/collect/CollectionBenchmarkSampleData.java b/guava-tests/test/com/google/common/collect/CollectionBenchmarkSampleData.java index 47671aa92701..ce6d74292ce6 100644 --- a/guava-tests/test/com/google/common/collect/CollectionBenchmarkSampleData.java +++ b/guava-tests/test/com/google/common/collect/CollectionBenchmarkSampleData.java @@ -17,6 +17,7 @@ package com.google.common.collect; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Lists.newArrayListWithCapacity; import static java.util.Collections.shuffle; import java.util.ArrayList; @@ -64,7 +65,7 @@ Element[] getQueries() { } private Element[] createQueries(Set elementsInSet, int numQueries) { - List queryList = Lists.newArrayListWithCapacity(numQueries); + List queryList = newArrayListWithCapacity(numQueries); int numGoodQueries = (int) (numQueries * hitRate + 0.5); diff --git a/guava-tests/test/com/google/common/collect/EnumBiMapTest.java b/guava-tests/test/com/google/common/collect/EnumBiMapTest.java index d710e0384c03..994c42dc225c 100644 --- a/guava-tests/test/com/google/common/collect/EnumBiMapTest.java +++ b/guava-tests/test/com/google/common/collect/EnumBiMapTest.java @@ -16,6 +16,7 @@ package com.google.common.collect; +import static com.google.common.collect.Sets.newIdentityHashSet; import static com.google.common.collect.testing.Helpers.mapEntry; import static com.google.common.collect.testing.Helpers.orderEntriesByKey; import static com.google.common.testing.SerializableTester.reserializeAndAssert; @@ -286,7 +287,7 @@ public void testEntrySet() { Currency.PESO, Country.CHILE, Currency.FRANC, Country.SWITZERLAND); EnumBiMap bimap = EnumBiMap.create(map); - Set uniqueEntries = Sets.newIdentityHashSet(); + Set uniqueEntries = newIdentityHashSet(); uniqueEntries.addAll(bimap.entrySet()); assertEquals(3, uniqueEntries.size()); } diff --git a/guava-tests/test/com/google/common/collect/EnumHashBiMapTest.java b/guava-tests/test/com/google/common/collect/EnumHashBiMapTest.java index ff8fcd247d36..14ae1c93bfcb 100644 --- a/guava-tests/test/com/google/common/collect/EnumHashBiMapTest.java +++ b/guava-tests/test/com/google/common/collect/EnumHashBiMapTest.java @@ -17,6 +17,7 @@ package com.google.common.collect; import static com.google.common.collect.Maps.immutableEntry; +import static com.google.common.collect.Sets.newIdentityHashSet; import static com.google.common.testing.SerializableTester.reserializeAndAssert; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; @@ -221,7 +222,7 @@ public void testEntrySet() { Currency.FRANC, "franc"); EnumHashBiMap bimap = EnumHashBiMap.create(map); - Set uniqueEntries = Sets.newIdentityHashSet(); + Set uniqueEntries = newIdentityHashSet(); uniqueEntries.addAll(bimap.entrySet()); assertEquals(3, uniqueEntries.size()); } diff --git a/guava-tests/test/com/google/common/collect/EnumMultisetTest.java b/guava-tests/test/com/google/common/collect/EnumMultisetTest.java index 5cbcce256ef5..2df8fb6d5793 100644 --- a/guava-tests/test/com/google/common/collect/EnumMultisetTest.java +++ b/guava-tests/test/com/google/common/collect/EnumMultisetTest.java @@ -16,6 +16,7 @@ package com.google.common.collect; +import static com.google.common.collect.Sets.newIdentityHashSet; import static com.google.common.testing.SerializableTester.reserialize; import static com.google.common.truth.Truth.assertThat; import static java.util.Arrays.asList; @@ -148,7 +149,7 @@ public void testEntrySet() { ms.add(Color.YELLOW, 1); ms.add(Color.RED, 2); - Set uniqueEntries = Sets.newIdentityHashSet(); + Set uniqueEntries = newIdentityHashSet(); uniqueEntries.addAll(ms.entrySet()); assertEquals(3, uniqueEntries.size()); } diff --git a/guava-tests/test/com/google/common/collect/FilteredCollectionsTestUtil.java b/guava-tests/test/com/google/common/collect/FilteredCollectionsTestUtil.java index d9d976beb5e9..0c72a82cecf4 100644 --- a/guava-tests/test/com/google/common/collect/FilteredCollectionsTestUtil.java +++ b/guava-tests/test/com/google/common/collect/FilteredCollectionsTestUtil.java @@ -16,6 +16,7 @@ package com.google.common.collect; +import static com.google.common.base.Predicates.and; import static com.google.common.base.Predicates.not; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; @@ -202,8 +203,7 @@ public void testClearFilterFiltered() { C filtered1 = filter(unfiltered, EVEN); C filtered2 = filter(filtered1, PRIME_DIGIT); - C inverseFiltered = - filter(createUnfiltered(contents), not(Predicates.and(EVEN, PRIME_DIGIT))); + C inverseFiltered = filter(createUnfiltered(contents), not(and(EVEN, PRIME_DIGIT))); filtered2.clear(); assertThat(unfiltered).containsExactlyElementsIn(inverseFiltered); diff --git a/guava-tests/test/com/google/common/collect/FilteredSortedMapTest.java b/guava-tests/test/com/google/common/collect/FilteredSortedMapTest.java index 9102201a9b0b..05f0f26dd791 100644 --- a/guava-tests/test/com/google/common/collect/FilteredSortedMapTest.java +++ b/guava-tests/test/com/google/common/collect/FilteredSortedMapTest.java @@ -16,6 +16,7 @@ package com.google.common.collect; +import static com.google.common.collect.Maps.filterEntries; import static com.google.common.truth.Truth.assertThat; import com.google.common.annotations.GwtCompatible; @@ -37,7 +38,7 @@ public void testFirstAndLastKeyFilteredMap() { unfiltered.put("cat", 3); unfiltered.put("dog", 5); - SortedMap filtered = Maps.filterEntries(unfiltered, CORRECT_LENGTH); + SortedMap filtered = filterEntries(unfiltered, CORRECT_LENGTH); assertThat(filtered.firstKey()).isEqualTo("banana"); assertThat(filtered.lastKey()).isEqualTo("cat"); } @@ -48,7 +49,7 @@ public void testHeadSubTailMap_filteredMap() { unfiltered.put("banana", 6); unfiltered.put("cat", 4); unfiltered.put("dog", 3); - SortedMap filtered = Maps.filterEntries(unfiltered, CORRECT_LENGTH); + SortedMap filtered = filterEntries(unfiltered, CORRECT_LENGTH); assertEquals(ImmutableMap.of("banana", 6), filtered.headMap("dog")); assertEquals(ImmutableMap.of(), filtered.headMap("banana")); diff --git a/guava-tests/test/com/google/common/collect/ForwardingNavigableSetTest.java b/guava-tests/test/com/google/common/collect/ForwardingNavigableSetTest.java index 7a10c294792b..1605a35e8f4f 100644 --- a/guava-tests/test/com/google/common/collect/ForwardingNavigableSetTest.java +++ b/guava-tests/test/com/google/common/collect/ForwardingNavigableSetTest.java @@ -16,6 +16,7 @@ package com.google.common.collect; +import static com.google.common.collect.Sets.newTreeSet; import static java.util.Arrays.asList; import com.google.common.base.Function; @@ -180,7 +181,7 @@ protected Set create(String[] elements) { @Override public List order(List insertionOrder) { - return new ArrayList<>(Sets.newTreeSet(insertionOrder)); + return new ArrayList<>(newTreeSet(insertionOrder)); } }) .named("ForwardingNavigableSet[SafeTreeSet] with standard implementations") @@ -201,7 +202,7 @@ protected Set create(String[] elements) { @Override public List order(List insertionOrder) { - return new ArrayList<>(Sets.newTreeSet(insertionOrder)); + return new ArrayList<>(newTreeSet(insertionOrder)); } }) .named( diff --git a/guava-tests/test/com/google/common/collect/ForwardingSortedSetTest.java b/guava-tests/test/com/google/common/collect/ForwardingSortedSetTest.java index 0598544a13fa..6a661a278e71 100644 --- a/guava-tests/test/com/google/common/collect/ForwardingSortedSetTest.java +++ b/guava-tests/test/com/google/common/collect/ForwardingSortedSetTest.java @@ -16,6 +16,7 @@ package com.google.common.collect; +import static com.google.common.collect.Sets.newTreeSet; import static java.util.Arrays.asList; import com.google.common.base.Function; @@ -137,7 +138,7 @@ protected SortedSet create(String[] elements) { @Override public List order(List insertionOrder) { - return new ArrayList<>(Sets.newTreeSet(insertionOrder)); + return new ArrayList<>(newTreeSet(insertionOrder)); } }) .named("ForwardingSortedSet[SafeTreeSet] with standard implementations") diff --git a/guava-tests/test/com/google/common/collect/IterablesTest.java b/guava-tests/test/com/google/common/collect/IterablesTest.java index 82c938761237..5633072d92fb 100644 --- a/guava-tests/test/com/google/common/collect/IterablesTest.java +++ b/guava-tests/test/com/google/common/collect/IterablesTest.java @@ -19,6 +19,7 @@ import static com.google.common.base.Predicates.equalTo; import static com.google.common.collect.Iterables.all; import static com.google.common.collect.Iterables.any; +import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.Iterables.elementsEqual; import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.find; @@ -399,7 +400,7 @@ public void testConcatIterable() { List> input = newArrayList(list1, list2); - Iterable result = Iterables.concat(input); + Iterable result = concat(input); assertEquals(asList(1, 4), newArrayList(result)); // Now change the inputs and see result dynamically change as well @@ -418,7 +419,7 @@ public void testConcatVarargs() { List list3 = newArrayList(7, 8); List list4 = newArrayList(9); List list5 = newArrayList(10); - Iterable result = Iterables.concat(list1, list2, list3, list4, list5); + Iterable result = concat(list1, list2, list3, list4, list5); assertEquals(asList(1, 4, 7, 8, 9, 10), newArrayList(result)); assertThat(result.toString()).isEqualTo("[1, 4, 7, 8, 9, 10]"); } @@ -427,13 +428,13 @@ public void testConcatNullPointerException() { List list1 = newArrayList(1); List list2 = newArrayList(4); - assertThrows(NullPointerException.class, () -> Iterables.concat(list1, null, list2)); + assertThrows(NullPointerException.class, () -> concat(list1, null, list2)); } public void testConcatPeformingFiniteCycle() { Iterable iterable = asList(1, 2, 3); int n = 4; - Iterable repeated = Iterables.concat(nCopies(n, iterable)); + Iterable repeated = concat(nCopies(n, iterable)); assertThat(repeated).containsExactly(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3).inOrder(); } diff --git a/guava-tests/test/com/google/common/collect/IteratorsTest.java b/guava-tests/test/com/google/common/collect/IteratorsTest.java index 4c8a532c46a3..c98637ad816c 100644 --- a/guava-tests/test/com/google/common/collect/IteratorsTest.java +++ b/guava-tests/test/com/google/common/collect/IteratorsTest.java @@ -21,6 +21,7 @@ import static com.google.common.collect.Iterators.advance; import static com.google.common.collect.Iterators.all; import static com.google.common.collect.Iterators.any; +import static com.google.common.collect.Iterators.concat; import static com.google.common.collect.Iterators.elementsEqual; import static com.google.common.collect.Iterators.emptyIterator; import static com.google.common.collect.Iterators.filter; @@ -32,6 +33,7 @@ import static com.google.common.collect.Iterators.mergeSorted; import static com.google.common.collect.Iterators.peekingIterator; import static com.google.common.collect.Iterators.singletonIterator; +import static com.google.common.collect.Iterators.transform; import static com.google.common.collect.Iterators.tryFind; import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.testing.IteratorFeature.MODIFIABLE; @@ -42,6 +44,7 @@ import static java.util.Collections.emptySet; import static java.util.Collections.singleton; import static java.util.Collections.singletonList; +import static java.util.Comparator.comparing; import static org.junit.Assert.assertThrows; import com.google.common.annotations.GwtCompatible; @@ -425,7 +428,7 @@ public void testTryFind_alwaysFalse_isPresent() { public void testTransform() { Iterator input = asList("1", "2", "3").iterator(); Iterator result = - Iterators.transform( + transform( input, new Function() { @Override @@ -443,7 +446,7 @@ public void testTransformRemove() { List list = Lists.newArrayList("1", "2", "3"); Iterator input = list.iterator(); Iterator iterator = - Iterators.transform( + transform( input, new Function() { @Override @@ -461,7 +464,7 @@ public Integer apply(String from) { public void testPoorlyBehavedTransform() { Iterator input = asList("1", "not a number", "3").iterator(); Iterator result = - Iterators.transform( + transform( input, new Function() { @Override @@ -477,7 +480,7 @@ public Integer apply(String from) { public void testNullFriendlyTransform() { Iterator<@Nullable Integer> input = Arrays.<@Nullable Integer>asList(1, 2, null, 3).iterator(); Iterator result = - Iterators.transform( + transform( input, new Function<@Nullable Integer, String>() { @Override @@ -668,7 +671,7 @@ public void testConcatNoIteratorsYieldsEmpty() { new EmptyIteratorTester() { @Override protected Iterator newTargetIterator() { - return Iterators.concat(); + return concat(); } }.test(); } @@ -678,7 +681,7 @@ public void testConcatOneEmptyIteratorYieldsEmpty() { new EmptyIteratorTester() { @Override protected Iterator newTargetIterator() { - return Iterators.concat(iterateOver()); + return concat(iterateOver()); } }.test(); } @@ -688,7 +691,7 @@ public void testConcatMultipleEmptyIteratorsYieldsEmpty() { new EmptyIteratorTester() { @Override protected Iterator newTargetIterator() { - return Iterators.concat(iterateOver(), iterateOver()); + return concat(iterateOver(), iterateOver()); } }.test(); } @@ -698,7 +701,7 @@ public void testConcatSingletonYieldsSingleton() { new SingletonIteratorTester() { @Override protected Iterator newTargetIterator() { - return Iterators.concat(iterateOver(1)); + return concat(iterateOver(1)); } }.test(); } @@ -708,7 +711,7 @@ public void testConcatEmptyAndSingletonAndEmptyYieldsSingleton() { new SingletonIteratorTester() { @Override protected Iterator newTargetIterator() { - return Iterators.concat(iterateOver(), iterateOver(1), iterateOver()); + return concat(iterateOver(), iterateOver(1), iterateOver()); } }.test(); } @@ -718,7 +721,7 @@ public void testConcatSingletonAndSingletonYieldsDoubleton() { new DoubletonIteratorTester() { @Override protected Iterator newTargetIterator() { - return Iterators.concat(iterateOver(1), iterateOver(2)); + return concat(iterateOver(1), iterateOver(2)); } }.test(); } @@ -728,7 +731,7 @@ public void testConcatSingletonAndSingletonWithEmptiesYieldsDoubleton() { new DoubletonIteratorTester() { @Override protected Iterator newTargetIterator() { - return Iterators.concat(iterateOver(1), iterateOver(), iterateOver(), iterateOver(2)); + return concat(iterateOver(1), iterateOver(), iterateOver(), iterateOver(2)); } }.test(); } @@ -739,26 +742,26 @@ public void testConcatUnmodifiable() { 5, UNMODIFIABLE, asList(1, 2), IteratorTester.KnownOrder.KNOWN_ORDER) { @Override protected Iterator newTargetIterator() { - return Iterators.concat( + return concat( asList(1).iterator(), Arrays.asList().iterator(), asList(2).iterator()); } }.test(); } public void testConcatPartiallyAdvancedSecond() { - Iterator itr1 = Iterators.concat(singletonIterator("a"), Iterators.forArray("b", "c")); + Iterator itr1 = concat(singletonIterator("a"), Iterators.forArray("b", "c")); assertThat(itr1.next()).isEqualTo("a"); assertThat(itr1.next()).isEqualTo("b"); - Iterator itr2 = Iterators.concat(singletonIterator("d"), itr1); + Iterator itr2 = concat(singletonIterator("d"), itr1); assertThat(itr2.next()).isEqualTo("d"); assertThat(itr2.next()).isEqualTo("c"); } public void testConcatPartiallyAdvancedFirst() { - Iterator itr1 = Iterators.concat(singletonIterator("a"), Iterators.forArray("b", "c")); + Iterator itr1 = concat(singletonIterator("a"), Iterators.forArray("b", "c")); assertThat(itr1.next()).isEqualTo("a"); assertThat(itr1.next()).isEqualTo("b"); - Iterator itr2 = Iterators.concat(itr1, singletonIterator("d")); + Iterator itr2 = concat(itr1, singletonIterator("d")); assertThat(itr2.next()).isEqualTo("c"); assertThat(itr2.next()).isEqualTo("d"); } @@ -769,7 +772,7 @@ public void testConcatContainingNull() { (Iterator>) Arrays.<@Nullable Iterator>asList(iterateOver(1, 2), null, iterateOver(3)) .iterator(); - Iterator result = Iterators.concat(input); + Iterator result = concat(input); assertEquals(1, (int) result.next()); assertEquals(2, (int) result.next()); assertThrows(NullPointerException.class, () -> result.hasNext()); @@ -780,16 +783,14 @@ public void testConcatContainingNull() { public void testConcatVarArgsContainingNull() { assertThrows( NullPointerException.class, - () -> - Iterators.concat( - iterateOver(1, 2), null, iterateOver(3), iterateOver(4), iterateOver(5))); + () -> concat(iterateOver(1, 2), null, iterateOver(3), iterateOver(4), iterateOver(5))); } public void testConcatNested_appendToEnd() { int nestingDepth = 128; Iterator iterator = iterateOver(); for (int i = 0; i < nestingDepth; i++) { - iterator = Iterators.concat(iterator, iterateOver(1)); + iterator = concat(iterator, iterateOver(1)); } assertEquals(nestingDepth, Iterators.size(iterator)); } @@ -798,7 +799,7 @@ public void testConcatNested_appendToBeginning() { int nestingDepth = 128; Iterator iterator = iterateOver(); for (int i = 0; i < nestingDepth; i++) { - iterator = Iterators.concat(iterateOver(1), iterator); + iterator = concat(iterateOver(1), iterator); } assertEquals(nestingDepth, Iterators.size(iterator)); } @@ -1555,7 +1556,7 @@ public void testMergeSorted_stable_issue5773Example() { ImmutableList left = ImmutableList.of(new TestDatum("B", 1), new TestDatum("C", 1)); ImmutableList right = ImmutableList.of(new TestDatum("A", 2), new TestDatum("C", 2)); - Comparator comparator = Comparator.comparing(d -> d.letter); + Comparator comparator = comparing(d -> d.letter); // When elements compare as equal (both C's have same letter), our merge should always return C1 // before C2, since C1 is from the first iterator. @@ -1579,7 +1580,7 @@ public void testMergeSorted_stable_allEqual() { ImmutableList second = ImmutableList.of(new TestDatum("A", 3), new TestDatum("A", 4)); - Comparator comparator = Comparator.comparing(d -> d.letter); + Comparator comparator = comparing(d -> d.letter); Iterator merged = mergeSorted(ImmutableList.of(first.iterator(), second.iterator()), comparator); diff --git a/guava-tests/test/com/google/common/collect/ListsTest.java b/guava-tests/test/com/google/common/collect/ListsTest.java index d4eacce82f18..35b22930109f 100644 --- a/guava-tests/test/com/google/common/collect/ListsTest.java +++ b/guava-tests/test/com/google/common/collect/ListsTest.java @@ -21,6 +21,7 @@ import static com.google.common.collect.Lists.cartesianProduct; import static com.google.common.collect.Lists.charactersOf; import static com.google.common.collect.Lists.computeArrayListCapacity; +import static com.google.common.collect.Lists.newArrayListWithCapacity; import static com.google.common.collect.Lists.newArrayListWithExpectedSize; import static com.google.common.collect.Lists.partition; import static com.google.common.collect.Lists.transform; @@ -335,15 +336,15 @@ public void testNewArrayListEmpty() { } public void testNewArrayListWithCapacity() { - ArrayList list = Lists.newArrayListWithCapacity(0); + ArrayList list = newArrayListWithCapacity(0); assertEquals(emptyList(), list); - ArrayList bigger = Lists.newArrayListWithCapacity(256); + ArrayList bigger = newArrayListWithCapacity(256); assertEquals(emptyList(), bigger); } public void testNewArrayListWithCapacity_negative() { - assertThrows(IllegalArgumentException.class, () -> Lists.newArrayListWithCapacity(-1)); + assertThrows(IllegalArgumentException.class, () -> newArrayListWithCapacity(-1)); } public void testNewArrayListWithExpectedSize() { diff --git a/guava-tests/test/com/google/common/collect/MapsCollectionTest.java b/guava-tests/test/com/google/common/collect/MapsCollectionTest.java index 2bd475175ebb..2a071559b9a4 100644 --- a/guava-tests/test/com/google/common/collect/MapsCollectionTest.java +++ b/guava-tests/test/com/google/common/collect/MapsCollectionTest.java @@ -18,7 +18,13 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Maps.filterEntries; +import static com.google.common.collect.Maps.filterKeys; +import static com.google.common.collect.Maps.filterValues; +import static com.google.common.collect.Maps.transformEntries; import static com.google.common.collect.Maps.transformValues; +import static com.google.common.collect.Maps.unmodifiableNavigableMap; +import static com.google.common.collect.Sets.newTreeSet; import static com.google.common.collect.testing.Helpers.mapEntry; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Collections.sort; @@ -77,7 +83,7 @@ public static Test suite() { protected SortedMap create(Entry[] entries) { SafeTreeMap map = new SafeTreeMap<>(); putEntries(map, entries); - return Maps.unmodifiableNavigableMap(map); + return unmodifiableNavigableMap(map); } }) .named("unmodifiableNavigableMap[SafeTreeMap]") @@ -257,7 +263,7 @@ public SampleElements> samples() { @Override public NavigableMap create(Object... elements) { - NavigableSet set = Sets.newTreeSet(Ordering.natural()); + NavigableSet set = newTreeSet(Ordering.natural()); for (Object e : elements) { Entry entry = (Entry) e; checkNotNull(entry.getValue()); @@ -323,7 +329,7 @@ protected Map create(Entry[] entries) { Map map = new HashMap<>(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterKeys(map, FILTER_KEYS); + return filterKeys(map, FILTER_KEYS); } }) .named("Maps.filterKeys[Map, Predicate]") @@ -342,7 +348,7 @@ protected Map create(Entry[] entries) { Map map = new HashMap<>(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterValues(map, FILTER_VALUES); + return filterValues(map, FILTER_VALUES); } }) .named("Maps.filterValues[Map, Predicate]") @@ -361,7 +367,7 @@ protected Map create(Entry[] entries) { Map map = new HashMap<>(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterEntries(map, FILTER_ENTRIES); + return filterEntries(map, FILTER_ENTRIES); } }) .named("Maps.filterEntries[Map, Predicate]") @@ -380,8 +386,8 @@ protected Map create(Entry[] entries) { Map map = new HashMap<>(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - map = Maps.filterEntries(map, FILTER_ENTRIES_1); - return Maps.filterEntries(map, FILTER_ENTRIES_2); + map = filterEntries(map, FILTER_ENTRIES_1); + return filterEntries(map, FILTER_ENTRIES_2); } }) .named("Maps.filterEntries[Maps.filterEntries[Map, Predicate], Predicate]") @@ -405,7 +411,7 @@ protected BiMap create(Entry[] entries) { BiMap map = HashBiMap.create(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterKeys(map, FILTER_KEYS); + return filterKeys(map, FILTER_KEYS); } }) .named("Maps.filterKeys[BiMap, Predicate]") @@ -423,7 +429,7 @@ protected BiMap create(Entry[] entries) { BiMap map = HashBiMap.create(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterValues(map, FILTER_VALUES); + return filterValues(map, FILTER_VALUES); } }) .named("Maps.filterValues[BiMap, Predicate]") @@ -442,7 +448,7 @@ protected BiMap create(Entry[] entries) { BiMap map = HashBiMap.create(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterEntries(map, FILTER_ENTRIES); + return filterEntries(map, FILTER_ENTRIES); } }) .named("Maps.filterEntries[BiMap, Predicate]") @@ -466,7 +472,7 @@ protected SortedMap create(Entry[] entries) { SortedMap map = new NonNavigableSortedMap(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterKeys(map, FILTER_KEYS); + return filterKeys(map, FILTER_KEYS); } }) .named("Maps.filterKeys[SortedMap, Predicate]") @@ -481,7 +487,7 @@ protected SortedMap create(Entry[] entries) { SortedMap map = new NonNavigableSortedMap(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterValues(map, FILTER_VALUES); + return filterValues(map, FILTER_VALUES); } }) .named("Maps.filterValues[SortedMap, Predicate]") @@ -496,7 +502,7 @@ protected SortedMap create(Entry[] entries) { SortedMap map = new NonNavigableSortedMap(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); - return Maps.filterEntries(map, FILTER_ENTRIES); + return filterEntries(map, FILTER_ENTRIES); } }) .named("Maps.filterEntries[SortedMap, Predicate]") @@ -517,7 +523,7 @@ protected NavigableMap create(Entry[] entries) { putEntries(map, entries); map.put("banana", "toast"); map.put("eggplant", "spam"); - return Maps.filterKeys(map, FILTER_KEYS); + return filterKeys(map, FILTER_KEYS); } }) .named("Maps.filterKeys[NavigableMap, Predicate]") @@ -533,7 +539,7 @@ protected NavigableMap create(Entry[] entries) { putEntries(map, entries); map.put("banana", "toast"); map.put("eggplant", "spam"); - return Maps.filterValues(map, FILTER_VALUES); + return filterValues(map, FILTER_VALUES); } }) .named("Maps.filterValues[NavigableMap, Predicate]") @@ -549,7 +555,7 @@ protected NavigableMap create(Entry[] entries) { putEntries(map, entries); map.put("banana", "toast"); map.put("eggplant", "spam"); - return Maps.filterEntries(map, FILTER_ENTRIES); + return filterEntries(map, FILTER_ENTRIES); } }) .named("Maps.filterEntries[NavigableMap, Predicate]") @@ -619,7 +625,7 @@ public boolean apply(Entry entry) { private static class NonNavigableSortedSet extends ForwardingSortedSet { - private final SortedSet delegate = Sets.newTreeSet(Ordering.natural()); + private final SortedSet delegate = newTreeSet(Ordering.natural()); @Override protected SortedSet delegate() { @@ -697,7 +703,7 @@ protected Map create(Entry[] entries) { for (Entry entry : entries) { map.put(entry.getKey(), encode(entry.getValue())); } - return Maps.transformEntries(map, DECODE_ENTRY_TRANSFORMER); + return transformEntries(map, DECODE_ENTRY_TRANSFORMER); } }) .named("Maps.transformEntries[Map, EntryTransformer]") @@ -742,7 +748,7 @@ protected SortedMap create(Entry[] entries) { for (Entry entry : entries) { map.put(entry.getKey(), encode(entry.getValue())); } - return Maps.transformEntries(map, DECODE_ENTRY_TRANSFORMER); + return transformEntries(map, DECODE_ENTRY_TRANSFORMER); } }) .named("Maps.transformEntries[SortedMap, EntryTransformer]") @@ -785,7 +791,7 @@ protected NavigableMap create(Entry[] entries) { for (Entry entry : entries) { map.put(entry.getKey(), encode(entry.getValue())); } - return Maps.transformEntries(map, DECODE_ENTRY_TRANSFORMER); + return transformEntries(map, DECODE_ENTRY_TRANSFORMER); } }) .named("Maps.transformEntries[NavigableMap, EntryTransformer]") diff --git a/guava-tests/test/com/google/common/collect/MapsTest.java b/guava-tests/test/com/google/common/collect/MapsTest.java index c22db30e1144..dc4f7dff8ea3 100644 --- a/guava-tests/test/com/google/common/collect/MapsTest.java +++ b/guava-tests/test/com/google/common/collect/MapsTest.java @@ -17,9 +17,11 @@ package com.google.common.collect; import static com.google.common.collect.Maps.immutableEntry; +import static com.google.common.collect.Maps.toMap; import static com.google.common.collect.Maps.transformEntries; import static com.google.common.collect.Maps.transformValues; import static com.google.common.collect.Maps.unmodifiableNavigableMap; +import static com.google.common.collect.Sets.newTreeSet; import static com.google.common.collect.testing.Helpers.mapEntry; import static com.google.common.testing.SerializableTester.reserializeAndAssert; import static com.google.common.truth.Truth.assertThat; @@ -698,7 +700,7 @@ public void testAsMapEmpty() { } private static class NonNavigableSortedSet extends ForwardingSortedSet { - private final SortedSet delegate = Sets.newTreeSet(); + private final SortedSet delegate = newTreeSet(); @Override protected SortedSet delegate() { @@ -773,7 +775,7 @@ public void testAsMapSortedEmpty() { @GwtIncompatible // NavigableMap public void testAsMapNavigable() { - NavigableSet strings = Sets.newTreeSet(asList("one", "two", "three")); + NavigableSet strings = newTreeSet(asList("one", "two", "three")); NavigableMap map = Maps.asMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertEquals(Integer.valueOf(5), map.get("three")); @@ -820,7 +822,7 @@ public void testAsMapNavigable() { @GwtIncompatible // NavigableMap public void testAsMapNavigableReadsThrough() { - NavigableSet strings = Sets.newTreeSet(); + NavigableSet strings = newTreeSet(); Collections.addAll(strings, "one", "two", "three"); NavigableMap map = Maps.asMap(strings, LENGTH_FUNCTION); assertThat(map.comparator()).isNull(); @@ -854,7 +856,7 @@ public void testAsMapNavigableReadsThrough() { @GwtIncompatible // NavigableMap public void testAsMapNavigableWritesThrough() { - NavigableSet strings = Sets.newTreeSet(); + NavigableSet strings = newTreeSet(); Collections.addAll(strings, "one", "two", "three"); NavigableMap map = Maps.asMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); @@ -891,7 +893,7 @@ public void testAsMapNavigableEmpty() { public void testToMap() { Iterable strings = ImmutableList.of("one", "two", "three"); - ImmutableMap map = Maps.toMap(strings, LENGTH_FUNCTION); + ImmutableMap map = toMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertThat(map.entrySet()) .containsExactly(mapEntry("one", 3), mapEntry("two", 3), mapEntry("three", 5)) @@ -900,7 +902,7 @@ public void testToMap() { public void testToMapIterator() { Iterator strings = ImmutableList.of("one", "two", "three").iterator(); - ImmutableMap map = Maps.toMap(strings, LENGTH_FUNCTION); + ImmutableMap map = toMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertThat(map.entrySet()) .containsExactly(mapEntry("one", 3), mapEntry("two", 3), mapEntry("three", 5)) @@ -909,7 +911,7 @@ public void testToMapIterator() { public void testToMapWithDuplicateKeys() { Iterable strings = ImmutableList.of("one", "two", "three", "two", "one"); - ImmutableMap map = Maps.toMap(strings, LENGTH_FUNCTION); + ImmutableMap map = toMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertThat(map.entrySet()) .containsExactly(mapEntry("one", 3), mapEntry("two", 3), mapEntry("three", 5)) @@ -920,12 +922,12 @@ public void testToMapWithNullKeys() { Iterable<@Nullable String> strings = asList("one", null, "three"); assertThrows( NullPointerException.class, - () -> Maps.toMap((Iterable) strings, Functions.constant("foo"))); + () -> toMap((Iterable) strings, Functions.constant("foo"))); } public void testToMapWithNullValues() { Iterable strings = ImmutableList.of("one", "two", "three"); - assertThrows(NullPointerException.class, () -> Maps.toMap(strings, Functions.constant(null))); + assertThrows(NullPointerException.class, () -> toMap(strings, Functions.constant(null))); } private static final ImmutableBiMap INT_TO_STRING_MAP = diff --git a/guava-tests/test/com/google/common/collect/MinMaxPriorityQueueTest.java b/guava-tests/test/com/google/common/collect/MinMaxPriorityQueueTest.java index b3bbb1dae47c..beea6c915fa8 100644 --- a/guava-tests/test/com/google/common/collect/MinMaxPriorityQueueTest.java +++ b/guava-tests/test/com/google/common/collect/MinMaxPriorityQueueTest.java @@ -16,6 +16,7 @@ package com.google.common.collect; +import static com.google.common.collect.Lists.newArrayListWithCapacity; import static com.google.common.collect.Platform.reduceExponentIfGwt; import static com.google.common.collect.Platform.reduceIterationsIfGwt; import static com.google.common.collect.Sets.newHashSet; @@ -358,7 +359,7 @@ public void testIteratorRegressionChildlessUncle() { q.remove(10); // Now we're in the critical state: [1, 15, 13, 8, 14] // Removing 8 while iterating caused duplicates in iteration result. - List result = Lists.newArrayListWithCapacity(initial.size()); + List result = newArrayListWithCapacity(initial.size()); for (Iterator iter = q.iterator(); iter.hasNext(); ) { Integer value = iter.next(); result.add(value); @@ -696,7 +697,7 @@ public void testExhaustive_pollAndPush() { List expected = createOrderedList(size); for (Collection perm : Collections2.permutations(expected)) { MinMaxPriorityQueue q = MinMaxPriorityQueue.create(perm); - List elements = Lists.newArrayListWithCapacity(size); + List elements = newArrayListWithCapacity(size); while (!q.isEmpty()) { Integer next = q.pollFirst(); for (int i = 0; i <= size; i++) { @@ -717,7 +718,7 @@ public void testRegression_dataCorruption() { List expected = createOrderedList(size); MinMaxPriorityQueue q = MinMaxPriorityQueue.create(expected); List contents = new ArrayList<>(expected); - List elements = Lists.newArrayListWithCapacity(size); + List elements = newArrayListWithCapacity(size); while (!q.isEmpty()) { assertThat(q).containsExactlyElementsIn(contents); Integer next = q.pollFirst(); diff --git a/guava-tests/test/com/google/common/collect/MultimapsCollectionTest.java b/guava-tests/test/com/google/common/collect/MultimapsCollectionTest.java index 6b683e13633d..3b82d5bcd77b 100644 --- a/guava-tests/test/com/google/common/collect/MultimapsCollectionTest.java +++ b/guava-tests/test/com/google/common/collect/MultimapsCollectionTest.java @@ -22,6 +22,7 @@ import static com.google.common.collect.Multimaps.filterKeys; import static com.google.common.collect.Multimaps.filterValues; import static com.google.common.collect.Multimaps.synchronizedListMultimap; +import static com.google.common.collect.Sets.newLinkedHashSet; import static com.google.common.collect.testing.Helpers.mapEntry; import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES; import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; @@ -526,7 +527,7 @@ public SetMultimap create(Object... elements) { @Override public Collection createCollection(Iterable values) { - return Sets.newLinkedHashSet(values); + return newLinkedHashSet(values); } } diff --git a/guava-tests/test/com/google/common/collect/SetsFilterNavigableSetTest.java b/guava-tests/test/com/google/common/collect/SetsFilterNavigableSetTest.java index 2090e78098c6..c09efa6e4994 100644 --- a/guava-tests/test/com/google/common/collect/SetsFilterNavigableSetTest.java +++ b/guava-tests/test/com/google/common/collect/SetsFilterNavigableSetTest.java @@ -16,6 +16,8 @@ package com.google.common.collect; +import static com.google.common.collect.Sets.newTreeSet; + import com.google.common.base.Predicate; import com.google.common.collect.FilteredCollectionsTestUtil.AbstractFilteredNavigableSetTest; import java.util.NavigableSet; @@ -25,7 +27,7 @@ public final class SetsFilterNavigableSetTest extends AbstractFilteredNavigableSetTest { @Override NavigableSet createUnfiltered(Iterable contents) { - return Sets.newTreeSet(contents); + return newTreeSet(contents); } @Override diff --git a/guava-tests/test/com/google/common/collect/SetsFilterSortedSetTest.java b/guava-tests/test/com/google/common/collect/SetsFilterSortedSetTest.java index 6adf439ef663..7a20511e1c0f 100644 --- a/guava-tests/test/com/google/common/collect/SetsFilterSortedSetTest.java +++ b/guava-tests/test/com/google/common/collect/SetsFilterSortedSetTest.java @@ -16,6 +16,8 @@ package com.google.common.collect; +import static com.google.common.collect.Sets.newTreeSet; + import com.google.common.base.Predicate; import com.google.common.collect.FilteredCollectionsTestUtil.AbstractFilteredSortedSetTest; import java.util.SortedSet; @@ -27,7 +29,7 @@ public final class SetsFilterSortedSetTest extends AbstractFilteredSortedSetTest> { @Override SortedSet createUnfiltered(Iterable contents) { - TreeSet result = Sets.newTreeSet(contents); + TreeSet result = newTreeSet(contents); // we have to make the result not Navigable return new ForwardingSortedSet() { @Override diff --git a/guava-tests/test/com/google/common/collect/SetsTest.java b/guava-tests/test/com/google/common/collect/SetsTest.java index d1c91dedbb06..76a36416c9ea 100644 --- a/guava-tests/test/com/google/common/collect/SetsTest.java +++ b/guava-tests/test/com/google/common/collect/SetsTest.java @@ -18,8 +18,12 @@ import static com.google.common.collect.Iterables.unmodifiableIterable; import static com.google.common.collect.Sets.cartesianProduct; +import static com.google.common.collect.Sets.immutableEnumSet; import static com.google.common.collect.Sets.newEnumSet; import static com.google.common.collect.Sets.newHashSet; +import static com.google.common.collect.Sets.newIdentityHashSet; +import static com.google.common.collect.Sets.newLinkedHashSet; +import static com.google.common.collect.Sets.newTreeSet; import static com.google.common.collect.Sets.powerSet; import static com.google.common.collect.Sets.toImmutableEnumSet; import static com.google.common.collect.Sets.unmodifiableNavigableSet; @@ -141,7 +145,7 @@ protected Set create(String[] elements) { protected Set create(AnEnum[] elements) { AnEnum[] otherElements = new AnEnum[elements.length - 1]; arraycopy(elements, 1, otherElements, 0, otherElements.length); - return Sets.immutableEnumSet(elements[0], otherElements); + return immutableEnumSet(elements[0], otherElements); } }) .named("Sets.immutableEnumSet") @@ -230,7 +234,7 @@ public Set create(String[] elements) { new TestStringSetGenerator() { @Override public NavigableSet create(String[] elements) { - NavigableSet unfiltered = Sets.newTreeSet(); + NavigableSet unfiltered = newTreeSet(); unfiltered.add("yyy"); unfiltered.addAll(ImmutableList.copyOf(elements)); unfiltered.add("zzz"); @@ -290,7 +294,7 @@ private enum SomeEnum { @SuppressWarnings("DoNotCall") public void testImmutableEnumSet() { - Set units = Sets.immutableEnumSet(SomeEnum.D, SomeEnum.B); + Set units = immutableEnumSet(SomeEnum.D, SomeEnum.B); assertThat(units).containsExactly(SomeEnum.B, SomeEnum.D).inOrder(); assertThrows(UnsupportedOperationException.class, () -> units.remove(SomeEnum.B)); @@ -330,7 +334,7 @@ public void testToImmutableEnumSetReused() { @J2ktIncompatible @GwtIncompatible // SerializableTester public void testImmutableEnumSet_serialized() { - Set units = Sets.immutableEnumSet(SomeEnum.D, SomeEnum.B); + Set units = immutableEnumSet(SomeEnum.D, SomeEnum.B); assertThat(units).containsExactly(SomeEnum.B, SomeEnum.D).inOrder(); @@ -339,20 +343,20 @@ public void testImmutableEnumSet_serialized() { } public void testImmutableEnumSet_fromIterable() { - ImmutableSet none = Sets.immutableEnumSet(MinimalIterable.of()); + ImmutableSet none = immutableEnumSet(MinimalIterable.of()); assertThat(none).isEmpty(); - ImmutableSet one = Sets.immutableEnumSet(MinimalIterable.of(SomeEnum.B)); + ImmutableSet one = immutableEnumSet(MinimalIterable.of(SomeEnum.B)); assertThat(one).contains(SomeEnum.B); - ImmutableSet two = Sets.immutableEnumSet(MinimalIterable.of(SomeEnum.D, SomeEnum.B)); + ImmutableSet two = immutableEnumSet(MinimalIterable.of(SomeEnum.D, SomeEnum.B)); assertThat(two).containsExactly(SomeEnum.B, SomeEnum.D).inOrder(); } @GwtIncompatible @J2ktIncompatible public void testImmutableEnumSet_deserializationMakesDefensiveCopy() throws Exception { - ImmutableSet original = Sets.immutableEnumSet(SomeEnum.A, SomeEnum.B); + ImmutableSet original = immutableEnumSet(SomeEnum.A, SomeEnum.B); int handleOffset = 6; byte[] serializedForm = serializeWithBackReference(original, handleOffset); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(serializedForm)); @@ -462,19 +466,19 @@ public void testNewConcurrentHashSetFromCollection() { public void testNewLinkedHashSetEmpty() { @SuppressWarnings("UseCollectionConstructor") // test of factory method - LinkedHashSet set = Sets.newLinkedHashSet(); + LinkedHashSet set = newLinkedHashSet(); verifyLinkedHashSetContents(set, EMPTY_COLLECTION); } public void testNewLinkedHashSetFromCollection() { @SuppressWarnings("UseCollectionConstructor") // test of factory method - LinkedHashSet set = Sets.newLinkedHashSet(LONGER_LIST); + LinkedHashSet set = newLinkedHashSet(LONGER_LIST); verifyLinkedHashSetContents(set, LONGER_LIST); } public void testNewLinkedHashSetFromIterable() { LinkedHashSet set = - Sets.newLinkedHashSet( + newLinkedHashSet( new Iterable() { @Override public Iterator iterator() { @@ -495,12 +499,12 @@ public void testNewLinkedHashSetWithExpectedSizeLarge() { } public void testNewTreeSetEmpty() { - TreeSet set = Sets.newTreeSet(); + TreeSet set = newTreeSet(); verifySortedSetContents(set, EMPTY_COLLECTION, null); } public void testNewTreeSetEmptyDerived() { - TreeSet set = Sets.newTreeSet(); + TreeSet set = newTreeSet(); assertTrue(set.isEmpty()); set.add(new Derived("foo")); set.add(new Derived("bar")); @@ -508,7 +512,7 @@ public void testNewTreeSetEmptyDerived() { } public void testNewTreeSetEmptyNonGeneric() { - TreeSet set = Sets.newTreeSet(); + TreeSet set = newTreeSet(); assertTrue(set.isEmpty()); set.add(new LegacyComparable("foo")); set.add(new LegacyComparable("bar")); @@ -518,37 +522,37 @@ public void testNewTreeSetEmptyNonGeneric() { } public void testNewTreeSetFromCollection() { - TreeSet set = Sets.newTreeSet(SOME_COLLECTION); + TreeSet set = newTreeSet(SOME_COLLECTION); verifySortedSetContents(set, SOME_COLLECTION, null); } public void testNewTreeSetFromIterable() { - TreeSet set = Sets.newTreeSet(SOME_ITERABLE); + TreeSet set = newTreeSet(SOME_ITERABLE); verifySortedSetContents(set, SOME_ITERABLE, null); } public void testNewTreeSetFromIterableDerived() { Iterable iterable = asList(new Derived("foo"), new Derived("bar")); - TreeSet set = Sets.newTreeSet(iterable); + TreeSet set = newTreeSet(iterable); assertThat(set).containsExactly(new Derived("bar"), new Derived("foo")).inOrder(); } public void testNewTreeSetFromIterableNonGeneric() { Iterable iterable = asList(new LegacyComparable("foo"), new LegacyComparable("bar")); - TreeSet set = Sets.newTreeSet(iterable); + TreeSet set = newTreeSet(iterable); assertThat(set) .containsExactly(new LegacyComparable("bar"), new LegacyComparable("foo")) .inOrder(); } public void testNewTreeSetEmptyWithComparator() { - TreeSet set = Sets.newTreeSet(SOME_COMPARATOR); + TreeSet set = newTreeSet(SOME_COMPARATOR); verifySortedSetContents(set, EMPTY_COLLECTION, SOME_COMPARATOR); } public void testNewIdentityHashSet() { - Set set = Sets.newIdentityHashSet(); + Set set = newIdentityHashSet(); MyInteger value1 = new MyInteger(12357); MyInteger value2 = new MyInteger(12357); assertTrue(set.add(value1)); @@ -1092,7 +1096,7 @@ private static void verifySetContents(Set set, Iterable contents) { @GwtIncompatible // NavigableSet public void testUnmodifiableNavigableSet() { - TreeSet mod = Sets.newTreeSet(); + TreeSet mod = newTreeSet(); mod.add(1); mod.add(2); mod.add(3); diff --git a/guava-tests/test/com/google/common/collect/SortedIterablesTest.java b/guava-tests/test/com/google/common/collect/SortedIterablesTest.java index 9b1d04bba477..8f0f507f50c2 100644 --- a/guava-tests/test/com/google/common/collect/SortedIterablesTest.java +++ b/guava-tests/test/com/google/common/collect/SortedIterablesTest.java @@ -14,6 +14,8 @@ package com.google.common.collect; +import static com.google.common.collect.Sets.newTreeSet; + import com.google.common.annotations.GwtCompatible; import junit.framework.TestCase; import org.jspecify.annotations.NullMarked; @@ -27,14 +29,14 @@ @NullMarked public class SortedIterablesTest extends TestCase { public void testSameComparator() { - assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), Sets.newTreeSet())); + assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), newTreeSet())); assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), Maps.newTreeMap().keySet())); assertTrue( SortedIterables.hasSameComparator( - Ordering.natural().reverse(), Sets.newTreeSet(Ordering.natural().reverse()))); + Ordering.natural().reverse(), newTreeSet(Ordering.natural().reverse()))); } public void testComparator() { - assertEquals(Ordering.natural(), SortedIterables.comparator(Sets.newTreeSet())); + assertEquals(Ordering.natural(), SortedIterables.comparator(newTreeSet())); } } diff --git a/guava-tests/test/com/google/common/collect/TreeMultisetTest.java b/guava-tests/test/com/google/common/collect/TreeMultisetTest.java index 862c06f922ae..561d358cdc19 100644 --- a/guava-tests/test/com/google/common/collect/TreeMultisetTest.java +++ b/guava-tests/test/com/google/common/collect/TreeMultisetTest.java @@ -17,6 +17,7 @@ package com.google.common.collect; import static com.google.common.collect.BoundType.CLOSED; +import static com.google.common.collect.Sets.newTreeSet; import static com.google.common.truth.Truth.assertThat; import static java.util.Arrays.asList; import static java.util.Collections.sort; @@ -116,7 +117,7 @@ protected Set create(String[] elements) { @Override public List order(List insertionOrder) { - return new ArrayList<>(Sets.newTreeSet(insertionOrder)); + return new ArrayList<>(newTreeSet(insertionOrder)); } }) .named("TreeMultiset[Ordering.natural].elementSet") diff --git a/guava-tests/test/com/google/common/eventbus/DispatcherTest.java b/guava-tests/test/com/google/common/eventbus/DispatcherTest.java index 9d8eed2e8252..fb96b43d0c33 100644 --- a/guava-tests/test/com/google/common/eventbus/DispatcherTest.java +++ b/guava-tests/test/com/google/common/eventbus/DispatcherTest.java @@ -17,9 +17,9 @@ package com.google.common.eventbus; import static com.google.common.truth.Truth.assertThat; +import static com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly; import com.google.common.collect.ImmutableList; -import com.google.common.util.concurrent.Uninterruptibles; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.CountDownLatch; @@ -114,7 +114,7 @@ public void testLegacyAsyncDispatcher() { }) .start(); - Uninterruptibles.awaitUninterruptibly(latch); + awaitUninterruptibly(latch); // See Dispatcher.LegacyAsyncDispatcher for an explanation of why there aren't really any // useful testable guarantees about the behavior of that dispatcher in a multithreaded diff --git a/guava-tests/test/com/google/common/graph/GraphsTest.java b/guava-tests/test/com/google/common/graph/GraphsTest.java index b52f0807bd20..87ab3f28e203 100644 --- a/guava-tests/test/com/google/common/graph/GraphsTest.java +++ b/guava-tests/test/com/google/common/graph/GraphsTest.java @@ -16,6 +16,7 @@ package com.google.common.graph; +import static com.google.common.graph.AbstractNetworkTest.validateNetwork; import static com.google.common.graph.Graphs.TransitiveClosureSelfLoopStrategy.ADD_SELF_LOOPS_ALWAYS; import static com.google.common.graph.Graphs.TransitiveClosureSelfLoopStrategy.ADD_SELF_LOOPS_FOR_CYCLES; import static com.google.common.graph.Graphs.copyOf; @@ -456,7 +457,7 @@ public void transpose_directedNetwork() { Network transpose = transpose(directedGraph); assertThat(transpose).isEqualTo(expectedTranspose); assertThat(transpose(transpose)).isSameInstanceAs(directedGraph); - AbstractNetworkTest.validateNetwork(transpose); + validateNetwork(transpose); assertThat(transpose.edgesConnecting(N1, N2)).isEmpty(); assertThat(transpose.edgeConnecting(N1, N2)).isEmpty(); @@ -472,7 +473,7 @@ public void transpose_directedNetwork() { assertThat(transpose.edgesConnecting(N1, N2)).containsExactly(E21); assertThat(transpose.edgeConnecting(N1, N2)).hasValue(E21); assertThat(transpose.edgeConnectingOrNull(N1, N2)).isEqualTo(E21); - AbstractNetworkTest.validateNetwork(transpose); + validateNetwork(transpose); } @Test diff --git a/guava-tests/test/com/google/common/graph/NetworkMutationTest.java b/guava-tests/test/com/google/common/graph/NetworkMutationTest.java index 1ba3eaf053f9..6478aef17297 100644 --- a/guava-tests/test/com/google/common/graph/NetworkMutationTest.java +++ b/guava-tests/test/com/google/common/graph/NetworkMutationTest.java @@ -16,6 +16,7 @@ package com.google.common.graph; +import static com.google.common.graph.AbstractNetworkTest.validateNetwork; import static com.google.common.truth.Truth.assertThat; import static java.util.Collections.shuffle; @@ -57,7 +58,7 @@ private static void testNetworkMutation(NetworkBuilder assertThat(network.nodes()).isEmpty(); assertThat(network.edges()).isEmpty(); - AbstractNetworkTest.validateNetwork(network); + validateNetwork(network); while (network.nodes().size() < NUM_NODES) { network.addNode(gen.nextInt(NODE_POOL_SIZE)); @@ -74,7 +75,7 @@ private static void testNetworkMutation(NetworkBuilder assertThat(network.nodes()).hasSize(NUM_NODES); assertThat(network.edges()).hasSize(NUM_EDGES); - AbstractNetworkTest.validateNetwork(network); + validateNetwork(network); shuffle(edgeList, gen); int numEdgesToRemove = gen.nextInt(NUM_EDGES); @@ -85,7 +86,7 @@ private static void testNetworkMutation(NetworkBuilder assertThat(network.nodes()).hasSize(NUM_NODES); assertThat(network.edges()).hasSize(NUM_EDGES - numEdgesToRemove); - AbstractNetworkTest.validateNetwork(network); + validateNetwork(network); shuffle(nodeList, gen); int numNodesToRemove = gen.nextInt(NUM_NODES); @@ -95,7 +96,7 @@ private static void testNetworkMutation(NetworkBuilder assertThat(network.nodes()).hasSize(NUM_NODES - numNodesToRemove); // Number of edges remaining is unknown (node's incident edges have been removed). - AbstractNetworkTest.validateNetwork(network); + validateNetwork(network); for (int i = numNodesToRemove; i < NUM_NODES; ++i) { assertThat(network.removeNode(nodeList.get(i))).isTrue(); @@ -103,7 +104,7 @@ private static void testNetworkMutation(NetworkBuilder assertThat(network.nodes()).isEmpty(); assertThat(network.edges()).isEmpty(); // no edges can remain if there's no nodes - AbstractNetworkTest.validateNetwork(network); + validateNetwork(network); shuffle(nodeList, gen); for (Integer node : nodeList) { @@ -119,7 +120,7 @@ private static void testNetworkMutation(NetworkBuilder assertThat(network.nodes()).hasSize(NUM_NODES); assertThat(network.edges()).hasSize(NUM_EDGES); - AbstractNetworkTest.validateNetwork(network); + validateNetwork(network); } } diff --git a/guava-tests/test/com/google/common/graph/ValueGraphTest.java b/guava-tests/test/com/google/common/graph/ValueGraphTest.java index 321c4d4876b5..bddeb47d5d0c 100644 --- a/guava-tests/test/com/google/common/graph/ValueGraphTest.java +++ b/guava-tests/test/com/google/common/graph/ValueGraphTest.java @@ -16,6 +16,7 @@ package com.google.common.graph; +import static com.google.common.graph.AbstractNetworkTest.validateNetwork; import static com.google.common.graph.GraphConstants.ENDPOINTS_MISMATCH; import static com.google.common.graph.TestUtil.assertStronglyEquivalent; import static com.google.common.truth.Truth.assertThat; @@ -57,7 +58,7 @@ public void validateGraphState() { assertThat(graph.allowsSelfLoops()).isEqualTo(asGraph.allowsSelfLoops()); Network> asNetwork = graph.asNetwork(); - AbstractNetworkTest.validateNetwork(asNetwork); + validateNetwork(asNetwork); assertThat(graph.nodes()).isEqualTo(asNetwork.nodes()); assertThat(graph.edges()).hasSize(asNetwork.edges().size()); assertThat(graph.nodeOrder()).isEqualTo(asNetwork.nodeOrder()); diff --git a/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java b/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java index 1d6a1bd7c3ca..2c9fa8febf7c 100644 --- a/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java +++ b/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java @@ -16,13 +16,13 @@ package com.google.common.hash; +import static com.google.common.collect.Iterables.concat; import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.UTF_16LE; import static java.util.Collections.singleton; import static org.junit.Assert.assertThrows; import com.google.common.annotations.J2ktIncompatible; -import com.google.common.collect.Iterables; import com.google.common.hash.HashTestUtils.RandomHasherAction; import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; @@ -150,7 +150,7 @@ public void testExhaustive() throws Exception { Control control = new Control(); Hasher controlSink = control.newHasher(1024); - Iterable sinksAndControl = Iterables.concat(sinks, singleton(controlSink)); + Iterable sinksAndControl = concat(sinks, singleton(controlSink)); for (int insertion = 0; insertion < totalInsertions; insertion++) { RandomHasherAction.pickAtRandom(random).performAction(random, sinksAndControl); } diff --git a/guava-tests/test/com/google/common/hash/BloomFilterTest.java b/guava-tests/test/com/google/common/hash/BloomFilterTest.java index a1fdf2ea59de..a274e77d8bea 100644 --- a/guava-tests/test/com/google/common/hash/BloomFilterTest.java +++ b/guava-tests/test/com/google/common/hash/BloomFilterTest.java @@ -25,6 +25,7 @@ import static com.google.common.testing.SerializableTester.reserializeAndAssert; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; +import static com.google.common.util.concurrent.Uninterruptibles.joinUninterruptibly; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertThrows; @@ -37,7 +38,6 @@ import com.google.common.primitives.Ints; import com.google.common.testing.EqualsTester; import com.google.common.testing.NullPointerTester; -import com.google.common.util.concurrent.Uninterruptibles; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.math.RoundingMode; @@ -604,7 +604,7 @@ private static List runThreadsAndReturnExceptions(int numThreads, Run t.start(); } for (Thread t : threads) { - Uninterruptibles.joinUninterruptibly(t); + joinUninterruptibly(t); } return exceptions; } diff --git a/guava-tests/test/com/google/common/hash/FarmHashFingerprint64Test.java b/guava-tests/test/com/google/common/hash/FarmHashFingerprint64Test.java index 33684349671d..06555c9764ef 100644 --- a/guava-tests/test/com/google/common/hash/FarmHashFingerprint64Test.java +++ b/guava-tests/test/com/google/common/hash/FarmHashFingerprint64Test.java @@ -16,13 +16,13 @@ package com.google.common.hash; +import static com.google.common.base.Strings.repeat; import static com.google.common.hash.Hashing.farmHashFingerprint64; import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.ISO_8859_1; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.asList; -import com.google.common.base.Strings; import junit.framework.TestCase; import org.jspecify.annotations.NullUnmarked; @@ -42,9 +42,9 @@ public class FarmHashFingerprint64Test extends TestCase { public void testReallySimpleFingerprints() { assertEquals(8581389452482819506L, fingerprint("test".getBytes(UTF_8))); // 32 characters long - assertEquals(-4196240717365766262L, fingerprint(Strings.repeat("test", 8).getBytes(UTF_8))); + assertEquals(-4196240717365766262L, fingerprint(repeat("test", 8).getBytes(UTF_8))); // 256 characters long - assertEquals(3500507768004279527L, fingerprint(Strings.repeat("test", 64).getBytes(UTF_8))); + assertEquals(3500507768004279527L, fingerprint(repeat("test", 64).getBytes(UTF_8))); } public void testStringsConsistency() { diff --git a/guava-tests/test/com/google/common/hash/Fingerprint2011Test.java b/guava-tests/test/com/google/common/hash/Fingerprint2011Test.java index a6057e13f539..83b9b165641f 100644 --- a/guava-tests/test/com/google/common/hash/Fingerprint2011Test.java +++ b/guava-tests/test/com/google/common/hash/Fingerprint2011Test.java @@ -2,6 +2,7 @@ package com.google.common.hash; +import static com.google.common.base.Strings.repeat; import static com.google.common.hash.Hashing.fingerprint2011; import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.ISO_8859_1; @@ -9,7 +10,6 @@ import static java.util.Arrays.asList; import com.google.common.annotations.J2ktIncompatible; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Ordering; import com.google.common.primitives.UnsignedLong; @@ -67,9 +67,9 @@ public class Fingerprint2011Test extends TestCase { public void testReallySimpleFingerprints() { assertEquals(8473225671271759044L, fingerprint("test".getBytes(UTF_8))); // 32 characters long - assertEquals(7345148637025587076L, fingerprint(Strings.repeat("test", 8).getBytes(UTF_8))); + assertEquals(7345148637025587076L, fingerprint(repeat("test", 8).getBytes(UTF_8))); // 256 characters long - assertEquals(4904844928629814570L, fingerprint(Strings.repeat("test", 64).getBytes(UTF_8))); + assertEquals(4904844928629814570L, fingerprint(repeat("test", 64).getBytes(UTF_8))); } public void testStringsConsistency() { diff --git a/guava-tests/test/com/google/common/io/ByteStreamsTest.java b/guava-tests/test/com/google/common/io/ByteStreamsTest.java index 6db73b08d81e..36f1cc157c40 100644 --- a/guava-tests/test/com/google/common/io/ByteStreamsTest.java +++ b/guava-tests/test/com/google/common/io/ByteStreamsTest.java @@ -16,6 +16,8 @@ package com.google.common.io; +import static com.google.common.io.ByteStreams.newDataInput; +import static com.google.common.io.ByteStreams.newDataOutput; import static com.google.common.truth.Truth.assertThat; import static java.lang.System.arraycopy; import static java.nio.charset.StandardCharsets.US_ASCII; @@ -135,26 +137,26 @@ private static void skipHelper(long n, int expect, InputStream in) throws IOExce public void testNewDataInput_empty() { byte[] b = new byte[0]; - ByteArrayDataInput in = ByteStreams.newDataInput(b); + ByteArrayDataInput in = newDataInput(b); assertThrows(IllegalStateException.class, in::readInt); } public void testNewDataInput_normal() { - ByteArrayDataInput in = ByteStreams.newDataInput(bytes); + ByteArrayDataInput in = newDataInput(bytes); assertEquals(0x12345678, in.readInt()); assertEquals(0x76543210, in.readInt()); assertThrows(IllegalStateException.class, in::readInt); } public void testNewDataInput_readFully() { - ByteArrayDataInput in = ByteStreams.newDataInput(bytes); + ByteArrayDataInput in = newDataInput(bytes); byte[] actual = new byte[bytes.length]; in.readFully(actual); assertThat(actual).isEqualTo(bytes); } public void testNewDataInput_readFullyAndThenSome() { - ByteArrayDataInput in = ByteStreams.newDataInput(bytes); + ByteArrayDataInput in = newDataInput(bytes); byte[] actual = new byte[bytes.length * 2]; IllegalStateException ex = assertThrows(IllegalStateException.class, () -> in.readFully(actual)); @@ -162,7 +164,7 @@ public void testNewDataInput_readFullyAndThenSome() { } public void testNewDataInput_readFullyWithOffset() { - ByteArrayDataInput in = ByteStreams.newDataInput(bytes); + ByteArrayDataInput in = newDataInput(bytes); byte[] actual = new byte[4]; in.readFully(actual, 2, 2); assertEquals(0, actual[0]); @@ -173,8 +175,7 @@ public void testNewDataInput_readFullyWithOffset() { public void testNewDataInput_readLine() { ByteArrayDataInput in = - ByteStreams.newDataInput( - "This is a line\r\nThis too\rand this\nand also this".getBytes(UTF_8)); + newDataInput("This is a line\r\nThis too\rand this\nand also this".getBytes(UTF_8)); assertThat(in.readLine()).isEqualTo("This is a line"); assertThat(in.readLine()).isEqualTo("This too"); assertThat(in.readLine()).isEqualTo("and this"); @@ -183,14 +184,14 @@ public void testNewDataInput_readLine() { public void testNewDataInput_readFloat() { byte[] data = {0x12, 0x34, 0x56, 0x78, 0x76, 0x54, 0x32, 0x10}; - ByteArrayDataInput in = ByteStreams.newDataInput(data); + ByteArrayDataInput in = newDataInput(data); assertThat(in.readFloat()).isEqualTo(Float.intBitsToFloat(0x12345678)); assertThat(in.readFloat()).isEqualTo(Float.intBitsToFloat(0x76543210)); } public void testNewDataInput_readDouble() { byte[] data = {0x12, 0x34, 0x56, 0x78, 0x76, 0x54, 0x32, 0x10}; - ByteArrayDataInput in = ByteStreams.newDataInput(data); + ByteArrayDataInput in = newDataInput(data); assertThat(in.readDouble()).isEqualTo(Double.longBitsToDouble(0x1234567876543210L)); } @@ -198,13 +199,13 @@ public void testNewDataInput_readUTF() { byte[] data = new byte[17]; data[1] = 15; arraycopy("Kilroy was here".getBytes(UTF_8), 0, data, 2, 15); - ByteArrayDataInput in = ByteStreams.newDataInput(data); + ByteArrayDataInput in = newDataInput(data); assertThat(in.readUTF()).isEqualTo("Kilroy was here"); } public void testNewDataInput_readChar() { byte[] data = "qed".getBytes(UTF_16BE); - ByteArrayDataInput in = ByteStreams.newDataInput(data); + ByteArrayDataInput in = newDataInput(data); assertEquals('q', in.readChar()); assertEquals('e', in.readChar()); assertEquals('d', in.readChar()); @@ -212,7 +213,7 @@ public void testNewDataInput_readChar() { public void testNewDataInput_readUnsignedShort() { byte[] data = {0, 0, 0, 1, (byte) 0xFF, (byte) 0xFF, 0x12, 0x34}; - ByteArrayDataInput in = ByteStreams.newDataInput(data); + ByteArrayDataInput in = newDataInput(data); assertEquals(0, in.readUnsignedShort()); assertEquals(1, in.readUnsignedShort()); assertEquals(65535, in.readUnsignedShort()); @@ -221,17 +222,17 @@ public void testNewDataInput_readUnsignedShort() { public void testNewDataInput_readLong() { byte[] data = {0x12, 0x34, 0x56, 0x78, 0x76, 0x54, 0x32, 0x10}; - ByteArrayDataInput in = ByteStreams.newDataInput(data); + ByteArrayDataInput in = newDataInput(data); assertEquals(0x1234567876543210L, in.readLong()); } public void testNewDataInput_readBoolean() { - ByteArrayDataInput in = ByteStreams.newDataInput(bytes); + ByteArrayDataInput in = newDataInput(bytes); assertTrue(in.readBoolean()); } public void testNewDataInput_readByte() { - ByteArrayDataInput in = ByteStreams.newDataInput(bytes); + ByteArrayDataInput in = newDataInput(bytes); for (byte aByte : bytes) { assertEquals(aByte, in.readByte()); } @@ -240,7 +241,7 @@ public void testNewDataInput_readByte() { } public void testNewDataInput_readUnsignedByte() { - ByteArrayDataInput in = ByteStreams.newDataInput(bytes); + ByteArrayDataInput in = newDataInput(bytes); for (byte aByte : bytes) { assertEquals(aByte, in.readUnsignedByte()); } @@ -250,70 +251,70 @@ public void testNewDataInput_readUnsignedByte() { } public void testNewDataInput_offset() { - ByteArrayDataInput in = ByteStreams.newDataInput(bytes, 2); + ByteArrayDataInput in = newDataInput(bytes, 2); assertEquals(0x56787654, in.readInt()); assertThrows(IllegalStateException.class, in::readInt); } public void testNewDataInput_skip() { - ByteArrayDataInput in = ByteStreams.newDataInput(new byte[2]); + ByteArrayDataInput in = newDataInput(new byte[2]); assertEquals(2, in.skipBytes(2)); assertEquals(0, in.skipBytes(1)); } public void testNewDataInput_bais() { ByteArrayInputStream bais = new ByteArrayInputStream(new byte[] {0x12, 0x34, 0x56, 0x78}); - ByteArrayDataInput in = ByteStreams.newDataInput(bais); + ByteArrayDataInput in = newDataInput(bais); assertEquals(0x12345678, in.readInt()); } public void testNewDataOutput_empty() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); assertThat(out.toByteArray()).isEmpty(); } public void testNewDataOutput_writeInt() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeInt(0x12345678); out.writeInt(0x76543210); assertThat(out.toByteArray()).isEqualTo(bytes); } public void testNewDataOutput_sized() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(4); + ByteArrayDataOutput out = newDataOutput(4); out.writeInt(0x12345678); out.writeInt(0x76543210); assertThat(out.toByteArray()).isEqualTo(bytes); } public void testNewDataOutput_writeLong() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeLong(0x1234567876543210L); assertThat(out.toByteArray()).isEqualTo(bytes); } public void testNewDataOutput_writeByteArray() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.write(bytes); assertThat(out.toByteArray()).isEqualTo(bytes); } public void testNewDataOutput_writeByte() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.write(0x12); out.writeByte(0x34); assertThat(out.toByteArray()).isEqualTo(new byte[] {0x12, 0x34}); } public void testNewDataOutput_writeByteOffset() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.write(bytes, 4, 2); byte[] expected = {bytes[4], bytes[5]}; assertThat(out.toByteArray()).isEqualTo(expected); } public void testNewDataOutput_writeBoolean() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeBoolean(true); out.writeBoolean(false); byte[] expected = {(byte) 1, (byte) 0}; @@ -321,7 +322,7 @@ public void testNewDataOutput_writeBoolean() { } public void testNewDataOutput_writeChar() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeChar('a'); assertThat(out.toByteArray()).isEqualTo(new byte[] {0, 97}); } @@ -331,7 +332,7 @@ public void testNewDataOutput_writeChar() { new byte[] {-2, -1, 0, 114, 0, -55, 0, 115, 0, 117, 0, 109, 0, -55}; public void testNewDataOutput_writeChars() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeChars("r\u00C9sum\u00C9"); // need to remove byte order mark before comparing byte[] expected = Arrays.copyOfRange(utf16ExpectedWithBom, 2, 14); @@ -346,7 +347,7 @@ public void testUtf16Expected() { } public void testNewDataOutput_writeUTF() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeUTF("r\u00C9sum\u00C9"); byte[] expected = "r\u00C9sum\u00C9".getBytes(UTF_8); byte[] actual = out.toByteArray(); @@ -357,19 +358,19 @@ public void testNewDataOutput_writeUTF() { } public void testNewDataOutput_writeShort() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeShort(0x1234); assertThat(out.toByteArray()).isEqualTo(new byte[] {0x12, 0x34}); } public void testNewDataOutput_writeDouble() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeDouble(Double.longBitsToDouble(0x1234567876543210L)); assertThat(out.toByteArray()).isEqualTo(bytes); } public void testNewDataOutput_writeFloat() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); + ByteArrayDataOutput out = newDataOutput(); out.writeFloat(Float.intBitsToFloat(0x12345678)); out.writeFloat(Float.intBitsToFloat(0x76543210)); assertThat(out.toByteArray()).isEqualTo(bytes); @@ -377,7 +378,7 @@ public void testNewDataOutput_writeFloat() { public void testNewDataOutput_baos() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ByteArrayDataOutput out = ByteStreams.newDataOutput(baos); + ByteArrayDataOutput out = newDataOutput(baos); out.writeInt(0x12345678); assertEquals(4, baos.size()); assertThat(baos.toByteArray()).isEqualTo(new byte[] {0x12, 0x34, 0x56, 0x78}); diff --git a/guava-tests/test/com/google/common/io/CharStreamsTest.java b/guava-tests/test/com/google/common/io/CharStreamsTest.java index 9e130a16e3e6..eb0f1b8792d7 100644 --- a/guava-tests/test/com/google/common/io/CharStreamsTest.java +++ b/guava-tests/test/com/google/common/io/CharStreamsTest.java @@ -16,10 +16,10 @@ package com.google.common.io; +import static com.google.common.base.Strings.repeat; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import java.io.EOFException; import java.io.FilterReader; @@ -230,7 +230,7 @@ public void testCopy_toWriter_fromReadable() throws IOException { @SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8 public void testCopyWithReaderThatDoesNotFillBuffer() throws IOException { // need a long enough string for the buffer to hit 0 remaining before the copy completes - String string = Strings.repeat("0123456789", 100); + String string = repeat("0123456789", 100); StringBuilder b = new StringBuilder(); // the main assertion of this test is here... the copy will fail if the buffer size goes down // each time it is not filled completely diff --git a/guava-tests/test/com/google/common/io/FilesTest.java b/guava-tests/test/com/google/common/io/FilesTest.java index ddbbccc1ffc8..52b5c02ba9e9 100644 --- a/guava-tests/test/com/google/common/io/FilesTest.java +++ b/guava-tests/test/com/google/common/io/FilesTest.java @@ -17,6 +17,7 @@ package com.google.common.io; import static com.google.common.hash.Hashing.sha512; +import static com.google.common.primitives.Bytes.asList; import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.US_ASCII; import static java.nio.charset.StandardCharsets.UTF_16LE; @@ -24,7 +25,6 @@ import static org.junit.Assert.assertThrows; import com.google.common.collect.ImmutableList; -import com.google.common.primitives.Bytes; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; @@ -631,7 +631,7 @@ public byte[] getResult() { File asciiFile = getTestFile("ascii.txt"); byte[] result = Files.readBytes(asciiFile, processor); - assertEquals(Bytes.asList(Files.toByteArray(asciiFile)), Bytes.asList(result)); + assertEquals(asList(Files.toByteArray(asciiFile)), asList(result)); } public void testReadBytes_returnFalse() throws IOException { diff --git a/guava-tests/test/com/google/common/io/LittleEndianDataInputStreamTest.java b/guava-tests/test/com/google/common/io/LittleEndianDataInputStreamTest.java index 5f50d17c6aa6..d94d728bd273 100644 --- a/guava-tests/test/com/google/common/io/LittleEndianDataInputStreamTest.java +++ b/guava-tests/test/com/google/common/io/LittleEndianDataInputStreamTest.java @@ -16,10 +16,10 @@ package com.google.common.io; +import static com.google.common.primitives.Bytes.asList; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; -import com.google.common.primitives.Bytes; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInput; @@ -73,7 +73,7 @@ public void testReadFully() throws IOException { DataInput in = new LittleEndianDataInputStream(new ByteArrayInputStream(data)); byte[] b = new byte[data.length]; in.readFully(b); - assertEquals(Bytes.asList(data), Bytes.asList(b)); + assertEquals(asList(data), asList(b)); } public void testReadUnsignedByte_eof() throws IOException { diff --git a/guava-tests/test/com/google/common/io/LittleEndianDataOutputStreamTest.java b/guava-tests/test/com/google/common/io/LittleEndianDataOutputStreamTest.java index e7c2fd32e64f..634d50b63a2d 100644 --- a/guava-tests/test/com/google/common/io/LittleEndianDataOutputStreamTest.java +++ b/guava-tests/test/com/google/common/io/LittleEndianDataOutputStreamTest.java @@ -16,10 +16,10 @@ package com.google.common.io; +import static com.google.common.primitives.Bytes.asList; import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.ISO_8859_1; -import com.google.common.primitives.Bytes; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInput; @@ -145,6 +145,6 @@ public void testWriteChars() throws IOException { } private static void assertEquals(byte[] expected, byte[] actual) { - assertEquals(Bytes.asList(expected), Bytes.asList(actual)); + assertEquals(asList(expected), asList(actual)); } } diff --git a/guava-tests/test/com/google/common/math/BigIntegerMathTest.java b/guava-tests/test/com/google/common/math/BigIntegerMathTest.java index 75daea933205..204a541e6f1a 100644 --- a/guava-tests/test/com/google/common/math/BigIntegerMathTest.java +++ b/guava-tests/test/com/google/common/math/BigIntegerMathTest.java @@ -16,6 +16,7 @@ package com.google.common.math; +import static com.google.common.math.BigIntegerMath.sqrt; import static com.google.common.math.MathTesting.ALL_BIGINTEGER_CANDIDATES; import static com.google.common.math.MathTesting.ALL_ROUNDING_MODES; import static com.google.common.math.MathTesting.ALL_SAFE_ROUNDING_MODES; @@ -106,8 +107,7 @@ public void testFloorPowerOfTwoZero() { @GwtIncompatible // TODO public void testConstantSqrt2PrecomputedBits() { assertEquals( - BigIntegerMath.sqrt( - BigInteger.ZERO.setBit(2 * BigIntegerMath.SQRT2_PRECOMPUTE_THRESHOLD + 1), FLOOR), + sqrt(BigInteger.ZERO.setBit(2 * BigIntegerMath.SQRT2_PRECOMPUTE_THRESHOLD + 1), FLOOR), BigIntegerMath.SQRT2_PRECOMPUTED_BITS); } @@ -298,15 +298,14 @@ public void testLog10TrivialOnPowerOf10() { @GwtIncompatible // TODO public void testSqrtZeroAlwaysZero() { for (RoundingMode mode : ALL_ROUNDING_MODES) { - assertEquals(ZERO, BigIntegerMath.sqrt(ZERO, mode)); + assertEquals(ZERO, sqrt(ZERO, mode)); } } @GwtIncompatible // TODO public void testSqrtNegativeAlwaysThrows() { for (RoundingMode mode : ALL_ROUNDING_MODES) { - assertThrows( - IllegalArgumentException.class, () -> BigIntegerMath.sqrt(BigInteger.valueOf(-1), mode)); + assertThrows(IllegalArgumentException.class, () -> sqrt(BigInteger.valueOf(-1), mode)); } } @@ -314,7 +313,7 @@ public void testSqrtNegativeAlwaysThrows() { public void testSqrtFloor() { for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) { for (RoundingMode mode : asList(FLOOR, DOWN)) { - BigInteger result = BigIntegerMath.sqrt(x, mode); + BigInteger result = sqrt(x, mode); assertThat(result).isGreaterThan(ZERO); assertThat(result.pow(2)).isAtMost(x); assertThat(result.add(ONE).pow(2)).isGreaterThan(x); @@ -326,7 +325,7 @@ public void testSqrtFloor() { public void testSqrtCeiling() { for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) { for (RoundingMode mode : asList(CEILING, UP)) { - BigInteger result = BigIntegerMath.sqrt(x, mode); + BigInteger result = sqrt(x, mode); assertThat(result).isGreaterThan(ZERO); assertThat(result.pow(2)).isAtLeast(x); assertTrue(result.signum() == 0 || result.subtract(ONE).pow(2).compareTo(x) < 0); @@ -338,11 +337,11 @@ public void testSqrtCeiling() { @GwtIncompatible // TODO public void testSqrtExact() { for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) { - BigInteger floor = BigIntegerMath.sqrt(x, FLOOR); + BigInteger floor = sqrt(x, FLOOR); // We only expect an exception if x was not a perfect square. boolean isPerfectSquare = floor.pow(2).equals(x); try { - assertEquals(floor, BigIntegerMath.sqrt(x, UNNECESSARY)); + assertEquals(floor, sqrt(x, UNNECESSARY)); assertTrue(isPerfectSquare); } catch (ArithmeticException e) { assertFalse(isPerfectSquare); @@ -353,7 +352,7 @@ public void testSqrtExact() { @GwtIncompatible // TODO public void testSqrtHalfUp() { for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) { - BigInteger result = BigIntegerMath.sqrt(x, HALF_UP); + BigInteger result = sqrt(x, HALF_UP); BigInteger plusHalfSquared = result.pow(2).add(result).shiftLeft(2).add(ONE); BigInteger x4 = x.shiftLeft(2); // sqrt(x) < result + 0.5, so 4 * x < (result + 0.5)^2 * 4 @@ -369,7 +368,7 @@ public void testSqrtHalfUp() { @GwtIncompatible // TODO public void testSqrtHalfDown() { for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) { - BigInteger result = BigIntegerMath.sqrt(x, HALF_DOWN); + BigInteger result = sqrt(x, HALF_DOWN); BigInteger plusHalfSquared = result.pow(2).add(result).shiftLeft(2).add(ONE); BigInteger x4 = x.shiftLeft(2); // sqrt(x) <= result + 0.5, so 4 * x <= (result + 0.5)^2 * 4 @@ -386,11 +385,11 @@ public void testSqrtHalfDown() { @GwtIncompatible // TODO public void testSqrtHalfEven() { for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) { - BigInteger halfEven = BigIntegerMath.sqrt(x, HALF_EVEN); + BigInteger halfEven = sqrt(x, HALF_EVEN); // Now figure out what rounding mode we should behave like (it depends if FLOOR was // odd/even). - boolean floorWasOdd = BigIntegerMath.sqrt(x, FLOOR).testBit(0); - assertEquals(BigIntegerMath.sqrt(x, floorWasOdd ? HALF_UP : HALF_DOWN), halfEven); + boolean floorWasOdd = sqrt(x, FLOOR).testBit(0); + assertEquals(sqrt(x, floorWasOdd ? HALF_UP : HALF_DOWN), halfEven); } } diff --git a/guava-tests/test/com/google/common/math/DoubleMathTest.java b/guava-tests/test/com/google/common/math/DoubleMathTest.java index 91716044745e..c599dbe24525 100644 --- a/guava-tests/test/com/google/common/math/DoubleMathTest.java +++ b/guava-tests/test/com/google/common/math/DoubleMathTest.java @@ -16,8 +16,10 @@ package com.google.common.math; +import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.Iterables.get; import static com.google.common.collect.Iterables.size; +import static com.google.common.math.DoubleMath.isMathematicalInteger; import static com.google.common.math.MathTesting.ALL_DOUBLE_CANDIDATES; import static com.google.common.math.MathTesting.ALL_ROUNDING_MODES; import static com.google.common.math.MathTesting.ALL_SAFE_ROUNDING_MODES; @@ -44,7 +46,6 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; import com.google.common.primitives.Doubles; import com.google.common.testing.NullPointerTester; import java.math.BigDecimal; @@ -468,21 +469,21 @@ private strictfp double trueLog2(double d) { @GwtIncompatible // DoubleMath.isMathematicalInteger public void testIsMathematicalIntegerIntegral() { for (double d : INTEGRAL_DOUBLE_CANDIDATES) { - assertTrue(DoubleMath.isMathematicalInteger(d)); + assertTrue(isMathematicalInteger(d)); } } @GwtIncompatible // DoubleMath.isMathematicalInteger public void testIsMathematicalIntegerFractional() { for (double d : FRACTIONAL_DOUBLE_CANDIDATES) { - assertFalse(DoubleMath.isMathematicalInteger(d)); + assertFalse(isMathematicalInteger(d)); } } @GwtIncompatible // DoubleMath.isMathematicalInteger public void testIsMathematicalIntegerNotFinite() { for (double d : asList(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN)) { - assertFalse(DoubleMath.isMathematicalInteger(d)); + assertFalse(isMathematicalInteger(d)); } } @@ -511,8 +512,7 @@ public void testFactorialNegative() { private static final Iterable TOLERANCE_CANDIDATES = ImmutableList.copyOf( - Iterables.concat( - FINITE_TOLERANCE_CANDIDATES, ImmutableList.of(Double.POSITIVE_INFINITY))); + concat(FINITE_TOLERANCE_CANDIDATES, ImmutableList.of(Double.POSITIVE_INFINITY))); private static final ImmutableList BAD_TOLERANCE_CANDIDATES = ImmutableList.copyOf( diff --git a/guava-tests/test/com/google/common/math/IntMathTest.java b/guava-tests/test/com/google/common/math/IntMathTest.java index 734ebeb73a50..976b63e7cac0 100644 --- a/guava-tests/test/com/google/common/math/IntMathTest.java +++ b/guava-tests/test/com/google/common/math/IntMathTest.java @@ -16,6 +16,7 @@ package com.google.common.math; +import static com.google.common.math.BigIntegerMath.sqrt; import static com.google.common.math.IntMath.checkedAdd; import static com.google.common.math.IntMath.checkedMultiply; import static com.google.common.math.IntMath.checkedSubtract; @@ -114,8 +115,7 @@ public void testFloorPowerOfTwoZero() { @GwtIncompatible // BigIntegerMath // TODO(cpovirk): GWT-enable BigIntegerMath public void testConstantMaxPowerOfSqrt2Unsigned() { assertThat(IntMath.MAX_POWER_OF_SQRT2_UNSIGNED) - .isEqualTo( - BigIntegerMath.sqrt(BigInteger.ZERO.setBit(2 * Integer.SIZE - 1), FLOOR).intValue()); + .isEqualTo(sqrt(BigInteger.ZERO.setBit(2 * Integer.SIZE - 1), FLOOR).intValue()); } @GwtIncompatible // pow() @@ -136,10 +136,7 @@ public void testMaxLog10ForLeadingZeros() { @GwtIncompatible // BigIntegerMath // TODO(cpovirk): GWT-enable BigIntegerMath public void testConstantsHalfPowersOf10() { for (int i = 0; i < IntMath.halfPowersOf10.length; i++) { - assertThat( - min( - Integer.MAX_VALUE, - BigIntegerMath.sqrt(BigInteger.TEN.pow(2 * i + 1), FLOOR).longValue())) + assertThat(min(Integer.MAX_VALUE, sqrt(BigInteger.TEN.pow(2 * i + 1), FLOOR).longValue())) .isEqualTo(IntMath.halfPowersOf10[i]); } } @@ -304,7 +301,7 @@ public void testSqrtMatchesBigInteger() { // The BigInteger implementation is tested separately, use it as the reference. // Promote the int value (rather than using intValue() on the expected value) to avoid // any risk of truncation which could lead to a false positive. - assertThat(bigInt(sqrt(x, mode))).isEqualTo(BigIntegerMath.sqrt(bigInt(x), mode)); + assertThat(bigInt(sqrt(x, mode))).isEqualTo(sqrt(bigInt(x), mode)); } } } diff --git a/guava-tests/test/com/google/common/math/LongMathTest.java b/guava-tests/test/com/google/common/math/LongMathTest.java index 25b0ecfd9c7d..71f3bb634360 100644 --- a/guava-tests/test/com/google/common/math/LongMathTest.java +++ b/guava-tests/test/com/google/common/math/LongMathTest.java @@ -16,6 +16,7 @@ package com.google.common.math; +import static com.google.common.math.BigIntegerMath.sqrt; import static com.google.common.math.LongMath.checkedAdd; import static com.google.common.math.LongMath.checkedMultiply; import static com.google.common.math.LongMath.checkedSubtract; @@ -115,8 +116,7 @@ public void testFloorPowerOfTwoZero() { @GwtIncompatible // TODO public void testConstantMaxPowerOfSqrt2Unsigned() { assertThat(LongMath.MAX_POWER_OF_SQRT2_UNSIGNED) - .isEqualTo( - BigIntegerMath.sqrt(BigInteger.ZERO.setBit(2 * Long.SIZE - 1), FLOOR).longValue()); + .isEqualTo(sqrt(BigInteger.ZERO.setBit(2 * Long.SIZE - 1), FLOOR).longValue()); } @GwtIncompatible // BigIntegerMath // TODO(cpovirk): GWT-enable BigIntegerMath @@ -140,10 +140,9 @@ public void testConstantsPowersOf10() { public void testConstantsHalfPowersOf10() { for (int i = 0; i < LongMath.halfPowersOf10.length; i++) { assertThat(bigInt(LongMath.halfPowersOf10[i])) - .isEqualTo(BigIntegerMath.sqrt(BigInteger.TEN.pow(2 * i + 1), FLOOR)); + .isEqualTo(sqrt(BigInteger.TEN.pow(2 * i + 1), FLOOR)); } - BigInteger nextBigger = - BigIntegerMath.sqrt(BigInteger.TEN.pow(2 * LongMath.halfPowersOf10.length + 1), FLOOR); + BigInteger nextBigger = sqrt(BigInteger.TEN.pow(2 * LongMath.halfPowersOf10.length + 1), FLOOR); assertThat(nextBigger).isGreaterThan(bigInt(Long.MAX_VALUE)); } @@ -340,7 +339,7 @@ public void testSqrtMatchesBigInteger() { for (RoundingMode mode : ALL_SAFE_ROUNDING_MODES) { // Promote the long value (rather than using longValue() on the expected value) to avoid // any risk of truncation which could lead to a false positive. - assertThat(bigInt(sqrt(x, mode))).isEqualTo(BigIntegerMath.sqrt(bigInt(x), mode)); + assertThat(bigInt(sqrt(x, mode))).isEqualTo(sqrt(bigInt(x), mode)); } } } diff --git a/guava-tests/test/com/google/common/math/MathTesting.java b/guava-tests/test/com/google/common/math/MathTesting.java index 2517df978823..4bcfb74da7ca 100644 --- a/guava-tests/test/com/google/common/math/MathTesting.java +++ b/guava-tests/test/com/google/common/math/MathTesting.java @@ -16,8 +16,10 @@ package com.google.common.math; +import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.transform; +import static java.lang.Math.round; import static java.math.BigInteger.ONE; import static java.math.BigInteger.ZERO; import static java.math.RoundingMode.CEILING; @@ -32,7 +34,6 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; import com.google.common.primitives.Doubles; import java.math.BigInteger; import java.math.RoundingMode; @@ -86,13 +87,12 @@ public final class MathTesting { POSITIVE_INTEGER_CANDIDATES = intValues.build(); NEGATIVE_INTEGER_CANDIDATES = ImmutableList.copyOf( - Iterables.concat( + concat( transform(POSITIVE_INTEGER_CANDIDATES, x -> -x), ImmutableList.of(Integer.MIN_VALUE))); NONZERO_INTEGER_CANDIDATES = - ImmutableList.copyOf( - Iterables.concat(POSITIVE_INTEGER_CANDIDATES, NEGATIVE_INTEGER_CANDIDATES)); - ALL_INTEGER_CANDIDATES = Iterables.concat(NONZERO_INTEGER_CANDIDATES, ImmutableList.of(0)); + ImmutableList.copyOf(concat(POSITIVE_INTEGER_CANDIDATES, NEGATIVE_INTEGER_CANDIDATES)); + ALL_INTEGER_CANDIDATES = concat(NONZERO_INTEGER_CANDIDATES, ImmutableList.of(0)); } /* @@ -123,10 +123,9 @@ public final class MathTesting { longValues.add(194368031998L).add(194368031999L); // sqrt(2^75) rounded up and down POSITIVE_LONG_CANDIDATES = longValues.build(); NEGATIVE_LONG_CANDIDATES = - Iterables.concat( - transform(POSITIVE_LONG_CANDIDATES, x -> -x), ImmutableList.of(Long.MIN_VALUE)); - NONZERO_LONG_CANDIDATES = Iterables.concat(POSITIVE_LONG_CANDIDATES, NEGATIVE_LONG_CANDIDATES); - ALL_LONG_CANDIDATES = Iterables.concat(NONZERO_LONG_CANDIDATES, ImmutableList.of(0L)); + concat(transform(POSITIVE_LONG_CANDIDATES, x -> -x), ImmutableList.of(Long.MIN_VALUE)); + NONZERO_LONG_CANDIDATES = concat(POSITIVE_LONG_CANDIDATES, NEGATIVE_LONG_CANDIDATES); + ALL_LONG_CANDIDATES = concat(NONZERO_LONG_CANDIDATES, ImmutableList.of(0L)); } /* @@ -177,9 +176,8 @@ public final class MathTesting { POSITIVE_BIGINTEGER_CANDIDATES = bigValues.build(); NEGATIVE_BIGINTEGER_CANDIDATES = transform(POSITIVE_BIGINTEGER_CANDIDATES, BigInteger::negate); NONZERO_BIGINTEGER_CANDIDATES = - Iterables.concat(POSITIVE_BIGINTEGER_CANDIDATES, NEGATIVE_BIGINTEGER_CANDIDATES); - ALL_BIGINTEGER_CANDIDATES = - Iterables.concat(NONZERO_BIGINTEGER_CANDIDATES, ImmutableList.of(ZERO)); + concat(POSITIVE_BIGINTEGER_CANDIDATES, NEGATIVE_BIGINTEGER_CANDIDATES); + ALL_BIGINTEGER_CANDIDATES = concat(NONZERO_BIGINTEGER_CANDIDATES, ImmutableList.of(ZERO)); } static final ImmutableSet INTEGRAL_DOUBLE_CANDIDATES; @@ -228,7 +226,7 @@ public final class MathTesting { } for (double delta : Doubles.asList(0.01, 0.1, 0.25, 0.499, 0.5, 0.501, 0.7, 0.8)) { double x = d + delta; - if (x != Math.round(x)) { + if (x != round(x)) { fractionalBuilder.add(x); } } @@ -243,11 +241,10 @@ public final class MathTesting { } } FRACTIONAL_DOUBLE_CANDIDATES = fractionalBuilder.build(); - FINITE_DOUBLE_CANDIDATES = - Iterables.concat(FRACTIONAL_DOUBLE_CANDIDATES, INTEGRAL_DOUBLE_CANDIDATES); + FINITE_DOUBLE_CANDIDATES = concat(FRACTIONAL_DOUBLE_CANDIDATES, INTEGRAL_DOUBLE_CANDIDATES); POSITIVE_FINITE_DOUBLE_CANDIDATES = filter(FINITE_DOUBLE_CANDIDATES, input -> input > 0.0); - DOUBLE_CANDIDATES_EXCEPT_NAN = Iterables.concat(FINITE_DOUBLE_CANDIDATES, INFINITIES); - ALL_DOUBLE_CANDIDATES = Iterables.concat(DOUBLE_CANDIDATES_EXCEPT_NAN, asList(Double.NaN)); + DOUBLE_CANDIDATES_EXCEPT_NAN = concat(FINITE_DOUBLE_CANDIDATES, INFINITIES); + ALL_DOUBLE_CANDIDATES = concat(DOUBLE_CANDIDATES_EXCEPT_NAN, asList(Double.NaN)); } private MathTesting() {} diff --git a/guava-tests/test/com/google/common/net/InternetDomainNameTest.java b/guava-tests/test/com/google/common/net/InternetDomainNameTest.java index a0b2b0661d4a..60cf95c44dc4 100644 --- a/guava-tests/test/com/google/common/net/InternetDomainNameTest.java +++ b/guava-tests/test/com/google/common/net/InternetDomainNameTest.java @@ -16,6 +16,8 @@ package com.google.common.net; +import static com.google.common.base.Strings.repeat; +import static com.google.common.collect.Iterables.concat; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; @@ -23,9 +25,7 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Ascii; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; import com.google.common.testing.EqualsTester; import com.google.common.testing.NullPointerTester; import junit.framework.TestCase; @@ -49,13 +49,13 @@ public final class InternetDomainNameTest extends TestCase { /** A domain part which is valid under lenient validation, but invalid under strict validation. */ @SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8 - static final String LOTS_OF_DELTAS = Strings.repeat(DELTA, 62); + static final String LOTS_OF_DELTAS = repeat(DELTA, 62); @SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8 - private static final String ALMOST_TOO_MANY_LEVELS = Strings.repeat("a.", 127); + private static final String ALMOST_TOO_MANY_LEVELS = repeat("a.", 127); @SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8 - private static final String ALMOST_TOO_LONG = Strings.repeat("aaaaa.", 40) + "1234567890.c"; + private static final String ALMOST_TOO_LONG = repeat("aaaaa.", 40) + "1234567890.c"; private static final ImmutableSet VALID_NAME = ImmutableSet.of( @@ -422,9 +422,8 @@ public void testInvalidTopPrivateDomain() { } public void testIsValid() { - Iterable validCases = Iterables.concat(VALID_NAME, PS, NO_PS, NON_PS); - Iterable invalidCases = - Iterables.concat(INVALID_NAME, VALID_IP_ADDRS, INVALID_IP_ADDRS); + Iterable validCases = concat(VALID_NAME, PS, NO_PS, NON_PS); + Iterable invalidCases = concat(INVALID_NAME, VALID_IP_ADDRS, INVALID_IP_ADDRS); for (String valid : validCases) { assertTrue(valid, InternetDomainName.isValid(valid)); diff --git a/guava-tests/test/com/google/common/reflect/InvokableTest.java b/guava-tests/test/com/google/common/reflect/InvokableTest.java index 8844882676bc..9fbed85cc1af 100644 --- a/guava-tests/test/com/google/common/reflect/InvokableTest.java +++ b/guava-tests/test/com/google/common/reflect/InvokableTest.java @@ -16,13 +16,13 @@ package com.google.common.reflect; +import static com.google.common.collect.Iterables.concat; import static com.google.common.truth.Truth.assertThat; import static java.util.Collections.nCopies; import static org.junit.Assert.assertThrows; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; import com.google.common.testing.EqualsTester; import com.google.common.testing.NullPointerTester; import com.google.errorprone.annotations.Keep; @@ -750,14 +750,14 @@ private Prepender() { @SuppressWarnings("UnusedTypeParameter") // examined with reflection static Iterable prepend(@NotBlank String first, Iterable tail) { - return Iterables.concat(ImmutableList.of(first), tail); + return concat(ImmutableList.of(first), tail); } // We are testing reflective access to an unnecessary `throws` clause. @SuppressWarnings("ThrowsUncheckedException") Iterable prepend(Iterable tail) throws IllegalArgumentException, NullPointerException { - return Iterables.concat(nCopies(times, prefix), tail); + return concat(nCopies(times, prefix), tail); } static Invokable constructor(Class... parameterTypes) throws Exception { diff --git a/guava-tests/test/com/google/common/reflect/TypeResolverTest.java b/guava-tests/test/com/google/common/reflect/TypeResolverTest.java index 464eebdd466c..8b3ecdcc9275 100644 --- a/guava-tests/test/com/google/common/reflect/TypeResolverTest.java +++ b/guava-tests/test/com/google/common/reflect/TypeResolverTest.java @@ -16,6 +16,8 @@ package com.google.common.reflect; +import static com.google.common.reflect.Types.subtypeOf; +import static com.google.common.reflect.Types.supertypeOf; import static org.junit.Assert.assertThrows; import java.lang.reflect.ParameterizedType; @@ -119,14 +121,14 @@ public void testWhere_parameterizedTypeMapping() { new TypeCapture>() {}.capture()) .resolveType(t)); assertEquals( - Types.subtypeOf(String.class), + subtypeOf(String.class), new TypeResolver() .where( new TypeCapture>() {}.capture(), new TypeCapture>() {}.capture()) .resolveType(t)); assertEquals( - Types.supertypeOf(String.class), + supertypeOf(String.class), new TypeResolver() .where( new TypeCapture>() {}.capture(), diff --git a/guava-tests/test/com/google/common/reflect/TypeTokenResolutionTest.java b/guava-tests/test/com/google/common/reflect/TypeTokenResolutionTest.java index 4cbab64246e1..e7a143234ce3 100644 --- a/guava-tests/test/com/google/common/reflect/TypeTokenResolutionTest.java +++ b/guava-tests/test/com/google/common/reflect/TypeTokenResolutionTest.java @@ -16,6 +16,8 @@ package com.google.common.reflect; +import static com.google.common.reflect.Types.newArrayType; +import static com.google.common.reflect.Types.newParameterizedType; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; @@ -281,7 +283,7 @@ private static final class GenericArray { public void testGenericArrayType() { GenericArray genericArray = new GenericArray<>(); assertEquals(GenericArray.class.getTypeParameters()[0], genericArray.t); - assertEquals(Types.newArrayType(genericArray.t), genericArray.array); + assertEquals(newArrayType(genericArray.t), genericArray.array); } public void testClassWrapper() { @@ -413,7 +415,7 @@ public void testResolveToGenericArrayType() { (GenericArrayType) new Holder[]>() {}.getContentType(); ParameterizedType listType = (ParameterizedType) arrayType.getGenericComponentType(); assertEquals(List.class, listType.getRawType()); - assertEquals(Types.newArrayType(int[].class), listType.getActualTypeArguments()[0]); + assertEquals(newArrayType(int[].class), listType.getActualTypeArguments()[0]); } private abstract class WithGenericBound { @@ -454,7 +456,7 @@ public void testWithGenericBoundInTypeVariable() throws Exception { public void testWithRecursiveBoundInTypeVariable() throws Exception { TypeVariable typeVariable = (TypeVariable) new WithGenericBound() {}.getTargetType("withRecursiveBound"); - assertEquals(Types.newParameterizedType(Enum.class, typeVariable), typeVariable.getBounds()[0]); + assertEquals(newParameterizedType(Enum.class, typeVariable), typeVariable.getBounds()[0]); } public void testWithMutualRecursiveBoundInTypeVariable() throws Exception { @@ -463,8 +465,8 @@ public void testWithMutualRecursiveBoundInTypeVariable() throws Exception { new WithGenericBound() {}.getTargetType("withMutualRecursiveBound"); TypeVariable k = (TypeVariable) paramType.getActualTypeArguments()[0]; TypeVariable v = (TypeVariable) paramType.getActualTypeArguments()[1]; - assertEquals(Types.newParameterizedType(List.class, v), k.getBounds()[0]); - assertEquals(Types.newParameterizedType(List.class, k), v.getBounds()[0]); + assertEquals(newParameterizedType(List.class, v), k.getBounds()[0]); + assertEquals(newParameterizedType(List.class, k), v.getBounds()[0]); } public void testWithGenericLowerBoundInWildcard() throws Exception { diff --git a/guava-tests/test/com/google/common/reflect/TypeTokenTest.java b/guava-tests/test/com/google/common/reflect/TypeTokenTest.java index 54da7471297d..4832f20269f1 100644 --- a/guava-tests/test/com/google/common/reflect/TypeTokenTest.java +++ b/guava-tests/test/com/google/common/reflect/TypeTokenTest.java @@ -16,6 +16,10 @@ package com.google.common.reflect; +import static com.google.common.reflect.Types.newArrayType; +import static com.google.common.reflect.Types.newParameterizedType; +import static com.google.common.reflect.Types.subtypeOf; +import static com.google.common.reflect.Types.supertypeOf; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; @@ -107,7 +111,7 @@ public void testGetType() { public void testNonStaticLocalClass() { class Local {} TypeToken> type = new TypeToken>() {}; - assertEquals(Types.newParameterizedType(Local.class, String.class), type.getType()); + assertEquals(newParameterizedType(Local.class, String.class), type.getType()); assertEquals(new Local() {}.getClass().getGenericSuperclass(), type.getType()); } @@ -118,7 +122,7 @@ public void testStaticLocalClass() { private static void doTestStaticLocalClass() { class Local {} TypeToken> type = new TypeToken>() {}; - assertEquals(Types.newParameterizedType(Local.class, String.class), type.getType()); + assertEquals(newParameterizedType(Local.class, String.class), type.getType()); assertEquals(new Local() {}.getClass().getGenericSuperclass(), type.getType()); } @@ -451,30 +455,28 @@ void testGetGenericSuperclass_typeVariable_boundIsTypeVariableAndInterface() { public void testGetGenericSuperclass_wildcard_lowerBounded() { assertEquals( - TypeToken.of(Object.class), - TypeToken.of(Types.supertypeOf(String.class)).getGenericSuperclass()); + TypeToken.of(Object.class), TypeToken.of(supertypeOf(String.class)).getGenericSuperclass()); assertEquals( new TypeToken() {}, - TypeToken.of(Types.supertypeOf(String[].class)).getGenericSuperclass()); + TypeToken.of(supertypeOf(String[].class)).getGenericSuperclass()); assertEquals( new TypeToken() {}, - TypeToken.of(Types.supertypeOf(CharSequence.class)).getGenericSuperclass()); + TypeToken.of(supertypeOf(CharSequence.class)).getGenericSuperclass()); } public void testGetGenericSuperclass_wildcard_boundIsClass() { assertEquals( - TypeToken.of(Object.class), - TypeToken.of(Types.subtypeOf(Object.class)).getGenericSuperclass()); + TypeToken.of(Object.class), TypeToken.of(subtypeOf(Object.class)).getGenericSuperclass()); assertEquals( new TypeToken() {}, - TypeToken.of(Types.subtypeOf(Object[].class)).getGenericSuperclass()); + TypeToken.of(subtypeOf(Object[].class)).getGenericSuperclass()); } public void testGetGenericSuperclass_wildcard_boundIsInterface() { - assertThat(TypeToken.of(Types.subtypeOf(CharSequence.class)).getGenericSuperclass()).isNull(); + assertThat(TypeToken.of(subtypeOf(CharSequence.class)).getGenericSuperclass()).isNull(); assertEquals( new TypeToken() {}, - TypeToken.of(Types.subtypeOf(CharSequence[].class)).getGenericSuperclass()); + TypeToken.of(subtypeOf(CharSequence[].class)).getGenericSuperclass()); } public void testGetGenericInterfaces_typeVariable_unbounded() { @@ -529,18 +531,18 @@ void testGetGenericInterfaces_typeVariable_boundIsTypeVariableAndInterface() { } public void testGetGenericInterfaces_wildcard_lowerBounded() { - assertThat(TypeToken.of(Types.supertypeOf(String.class)).getGenericInterfaces()).isEmpty(); - assertThat(TypeToken.of(Types.supertypeOf(String[].class)).getGenericInterfaces()).isEmpty(); + assertThat(TypeToken.of(supertypeOf(String.class)).getGenericInterfaces()).isEmpty(); + assertThat(TypeToken.of(supertypeOf(String[].class)).getGenericInterfaces()).isEmpty(); } public void testGetGenericInterfaces_wildcard_boundIsClass() { - assertThat(TypeToken.of(Types.subtypeOf(Object.class)).getGenericInterfaces()).isEmpty(); - assertThat(TypeToken.of(Types.subtypeOf(Object[].class)).getGenericInterfaces()).isEmpty(); + assertThat(TypeToken.of(subtypeOf(Object.class)).getGenericInterfaces()).isEmpty(); + assertThat(TypeToken.of(subtypeOf(Object[].class)).getGenericInterfaces()).isEmpty(); } public void testGetGenericInterfaces_wildcard_boundIsInterface() { TypeToken> interfaceType = new TypeToken>() {}; - makeUnmodifiable(TypeToken.of(Types.subtypeOf(interfaceType.getType())).getGenericInterfaces()) + makeUnmodifiable(TypeToken.of(subtypeOf(interfaceType.getType())).getGenericInterfaces()) .containsExactly(interfaceType); assertHasArrayInterfaces(new TypeToken[]>() {}); } @@ -624,7 +626,7 @@ public void testAssignableGenericArrayToClass() { } public void testAssignableWildcardBoundedByArrayToArrayClass() { - Type wildcardType = Types.subtypeOf(Object[].class); + Type wildcardType = subtypeOf(Object[].class); assertTrue(TypeToken.of(Object[].class).isSupertypeOf(wildcardType)); assertTrue(TypeToken.of(Object.class).isSupertypeOf(wildcardType)); assertFalse(TypeToken.of(wildcardType).isSupertypeOf(wildcardType)); @@ -640,8 +642,8 @@ public void testAssignableWildcardTypeParameterToClassTypeParameter() { } public void testAssignableArrayClassToBoundedWildcard() { - TypeToken subtypeOfArray = TypeToken.of(Types.subtypeOf(Object[].class)); - TypeToken supertypeOfArray = TypeToken.of(Types.supertypeOf(Object[].class)); + TypeToken subtypeOfArray = TypeToken.of(subtypeOf(Object[].class)); + TypeToken supertypeOfArray = TypeToken.of(supertypeOf(Object[].class)); assertFalse(subtypeOfArray.isSupertypeOf(Object[].class)); assertFalse(subtypeOfArray.isSupertypeOf(Object[][].class)); assertFalse(subtypeOfArray.isSupertypeOf(String[].class)); @@ -664,16 +666,16 @@ public void testAssignableClassTypeParameterToWildcardTypeParameter() { } public void testAssignableNonParameterizedClassToWildcard() { - TypeToken supertypeOfString = TypeToken.of(Types.supertypeOf(String.class)); + TypeToken supertypeOfString = TypeToken.of(supertypeOf(String.class)); assertFalse(supertypeOfString.isSupertypeOf(supertypeOfString)); assertFalse(supertypeOfString.isSupertypeOf(Object.class)); assertFalse(supertypeOfString.isSupertypeOf(CharSequence.class)); assertTrue(supertypeOfString.isSupertypeOf(String.class)); - assertTrue(supertypeOfString.isSupertypeOf(Types.subtypeOf(String.class))); + assertTrue(supertypeOfString.isSupertypeOf(subtypeOf(String.class))); } public void testAssignableWildcardBoundedByIntArrayToArrayClass() { - Type wildcardType = Types.subtypeOf(int[].class); + Type wildcardType = subtypeOf(int[].class); assertTrue(TypeToken.of(int[].class).isSupertypeOf(wildcardType)); assertTrue(TypeToken.of(Object.class).isSupertypeOf(wildcardType)); assertFalse(TypeToken.of(wildcardType).isSupertypeOf(wildcardType)); @@ -689,8 +691,8 @@ public void testAssignableWildcardTypeParameterBoundedByIntArrayToArrayClassType } public void testAssignableWildcardToWildcard() { - TypeToken subtypeOfArray = TypeToken.of(Types.subtypeOf(Object[].class)); - TypeToken supertypeOfArray = TypeToken.of(Types.supertypeOf(Object[].class)); + TypeToken subtypeOfArray = TypeToken.of(subtypeOf(Object[].class)); + TypeToken supertypeOfArray = TypeToken.of(supertypeOf(Object[].class)); assertTrue(supertypeOfArray.isSupertypeOf(subtypeOfArray)); assertFalse(supertypeOfArray.isSupertypeOf(supertypeOfArray)); assertFalse(subtypeOfArray.isSupertypeOf(subtypeOfArray)); @@ -976,10 +978,10 @@ public void testIsArray_genericArrayClasses() { } public void testIsArray_wildcardType() { - assertTrue(TypeToken.of(Types.subtypeOf(Object[].class)).isArray()); - assertTrue(TypeToken.of(Types.subtypeOf(int[].class)).isArray()); - assertFalse(TypeToken.of(Types.subtypeOf(Object.class)).isArray()); - assertFalse(TypeToken.of(Types.supertypeOf(Object[].class)).isArray()); + assertTrue(TypeToken.of(subtypeOf(Object[].class)).isArray()); + assertTrue(TypeToken.of(subtypeOf(int[].class)).isArray()); + assertFalse(TypeToken.of(subtypeOf(Object.class)).isArray()); + assertFalse(TypeToken.of(supertypeOf(Object[].class)).isArray()); } public void testPrimitiveWrappingAndUnwrapping() { @@ -991,7 +993,7 @@ public void testPrimitiveWrappingAndUnwrapping() { } assertNotPrimitiveNorWrapper(TypeToken.of(String.class)); assertNotPrimitiveNorWrapper(TypeToken.of(Object[].class)); - assertNotPrimitiveNorWrapper(TypeToken.of(Types.subtypeOf(Object.class))); + assertNotPrimitiveNorWrapper(TypeToken.of(subtypeOf(Object.class))); assertNotPrimitiveNorWrapper(new TypeToken>() {}); assertNotPrimitiveNorWrapper(TypeToken.of(new TypeCapture() {}.capture())); } @@ -1021,16 +1023,14 @@ public void testGetComponentType_genericArrayClasses() { public void testGetComponentType_wildcardType() { assertEquals( - Types.subtypeOf(Object.class), - TypeToken.of(Types.subtypeOf(Object[].class)).getComponentType().getType()); - assertEquals( - Types.subtypeOf(Object[].class), - Types.newArrayType( - TypeToken.of(Types.subtypeOf(Object[].class)).getComponentType().getType())); + subtypeOf(Object.class), + TypeToken.of(subtypeOf(Object[].class)).getComponentType().getType()); assertEquals( - int.class, TypeToken.of(Types.subtypeOf(int[].class)).getComponentType().getType()); - assertThat(TypeToken.of(Types.subtypeOf(Object.class)).getComponentType()).isNull(); - assertThat(TypeToken.of(Types.supertypeOf(Object[].class)).getComponentType()).isNull(); + subtypeOf(Object[].class), + newArrayType(TypeToken.of(subtypeOf(Object[].class)).getComponentType().getType())); + assertEquals(int.class, TypeToken.of(subtypeOf(int[].class)).getComponentType().getType()); + assertThat(TypeToken.of(subtypeOf(Object.class)).getComponentType()).isNull(); + assertThat(TypeToken.of(supertypeOf(Object[].class)).getComponentType()).isNull(); } private interface NumberList {} @@ -1054,7 +1054,7 @@ public void testToGenericType() { TypeToken genericType = TypeToken.toGenericType(Iterable.class); assertThat(genericType.getRawType()).isEqualTo(Iterable.class); assertEquals( - Types.newParameterizedType(Iterable.class, Iterable.class.getTypeParameters()[0]), + newParameterizedType(Iterable.class, Iterable.class.getTypeParameters()[0]), genericType.getType()); } @@ -1085,9 +1085,9 @@ private interface StringListArrayIterable extends ListIterable {} public void testGetSupertype_withTypeVariable() { ParameterizedType expectedType = - Types.newParameterizedType( + newParameterizedType( Iterable.class, - Types.newParameterizedType(List.class, ListIterable.class.getTypeParameters()[0])); + newParameterizedType(List.class, ListIterable.class.getTypeParameters()[0])); assertEquals( expectedType, TypeToken.of(ListIterable.class).getSupertype(Iterable.class).getType()); } @@ -1103,8 +1103,7 @@ void testGetSupertype_typeVariableWithMultipleBounds() { public void testGetSupertype_withoutTypeVariable() { ParameterizedType expectedType = - Types.newParameterizedType( - Iterable.class, Types.newParameterizedType(List.class, String.class)); + newParameterizedType(Iterable.class, newParameterizedType(List.class, String.class)); assertEquals( expectedType, TypeToken.of(StringListIterable.class).getSupertype(Iterable.class).getType()); @@ -1116,8 +1115,7 @@ public void testGetSupertype_chained() { (TypeToken>) TypeToken.of(StringListIterable.class).getSupertype(ListIterable.class); ParameterizedType expectedType = - Types.newParameterizedType( - Iterable.class, Types.newParameterizedType(List.class, String.class)); + newParameterizedType(Iterable.class, newParameterizedType(List.class, String.class)); assertEquals(expectedType, listIterableType.getSupertype(Iterable.class).getType()); } @@ -1137,7 +1135,7 @@ public void testGetSupertype_fromWildcard() { @SuppressWarnings("unchecked") // can't do new TypeToken() {} TypeToken> type = (TypeToken>) - TypeToken.of(Types.subtypeOf(new TypeToken>() {}.getType())); + TypeToken.of(subtypeOf(new TypeToken>() {}.getType())); assertEquals(new TypeToken>() {}, type.getSupertype(Iterable.class)); } @@ -1151,7 +1149,7 @@ public > void testGetSupertype_fromTypeVariable() { @SuppressWarnings("rawtypes") // purpose is to test raw type public void testGetSupertype_fromRawClass() { assertEquals( - Types.newParameterizedType(Iterable.class, List.class.getTypeParameters()[0]), + newParameterizedType(Iterable.class, List.class.getTypeParameters()[0]), new TypeToken() {}.getSupertype(Iterable.class).getType()); } @@ -1172,10 +1170,10 @@ private interface ListMap extends Map> {} public void testGetSupertype_fullyGenericType() { ParameterizedType expectedType = - Types.newParameterizedType( + newParameterizedType( Map.class, ListMap.class.getTypeParameters()[0], - Types.newParameterizedType(List.class, ListMap.class.getTypeParameters()[1])); + newParameterizedType(List.class, ListMap.class.getTypeParameters()[1])); assertEquals(expectedType, TypeToken.of(ListMap.class).getSupertype(Map.class).getType()); } @@ -1234,7 +1232,7 @@ public void testGetSubtype_fromWildcard() { @SuppressWarnings("unchecked") // can't do new TypeToken() {} TypeToken> type = (TypeToken>) - TypeToken.of(Types.supertypeOf(new TypeToken>() {}.getType())); + TypeToken.of(supertypeOf(new TypeToken>() {}.getType())); assertEquals(new TypeToken>() {}, type.getSubtype(List.class)); } @@ -1242,7 +1240,7 @@ public void testGetSubtype_fromWildcard_lowerBoundNotSupertype() { @SuppressWarnings("unchecked") // can't do new TypeToken() {} TypeToken> type = (TypeToken>) - TypeToken.of(Types.supertypeOf(new TypeToken>() {}.getType())); + TypeToken.of(supertypeOf(new TypeToken>() {}.getType())); assertThrows(IllegalArgumentException.class, () -> type.getSubtype(List.class)); } @@ -1250,7 +1248,7 @@ public void testGetSubtype_fromWildcard_upperBounded() { @SuppressWarnings("unchecked") // can't do new TypeToken() {} TypeToken> type = (TypeToken>) - TypeToken.of(Types.subtypeOf(new TypeToken>() {}.getType())); + TypeToken.of(subtypeOf(new TypeToken>() {}.getType())); assertThrows(IllegalArgumentException.class, () -> type.getSubtype(Iterable.class)); } @@ -1808,11 +1806,10 @@ static void verifyConsistentRawType() { public void testRawTypes() { RawTypeConsistencyTester.verifyConsistentRawType(); - assertThat(TypeToken.of(Types.subtypeOf(Object.class)).getRawType()).isEqualTo(Object.class); - assertThat(TypeToken.of(Types.subtypeOf(CharSequence.class)).getRawType()) + assertThat(TypeToken.of(subtypeOf(Object.class)).getRawType()).isEqualTo(Object.class); + assertThat(TypeToken.of(subtypeOf(CharSequence.class)).getRawType()) .isEqualTo(CharSequence.class); - assertThat(TypeToken.of(Types.supertypeOf(CharSequence.class)).getRawType()) - .isEqualTo(Object.class); + assertThat(TypeToken.of(supertypeOf(CharSequence.class)).getRawType()).isEqualTo(Object.class); } private abstract static class IKnowMyType { diff --git a/guava-tests/test/com/google/common/reflect/TypeVisitorTest.java b/guava-tests/test/com/google/common/reflect/TypeVisitorTest.java index d466067c8970..6712b3cf8d29 100644 --- a/guava-tests/test/com/google/common/reflect/TypeVisitorTest.java +++ b/guava-tests/test/com/google/common/reflect/TypeVisitorTest.java @@ -16,6 +16,8 @@ package com.google.common.reflect; +import static com.google.common.reflect.Types.subtypeOf; + import java.lang.reflect.GenericArrayType; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -57,7 +59,7 @@ void visitTypeVariable(TypeVariable t) {} } public void testVisitWildcardType() { - WildcardType type = Types.subtypeOf(String.class); + WildcardType type = subtypeOf(String.class); assertVisited(type); new BaseTypeVisitor() { @Override diff --git a/guava-tests/test/com/google/common/reflect/TypesTest.java b/guava-tests/test/com/google/common/reflect/TypesTest.java index c5508287b1fb..b8d282d38505 100644 --- a/guava-tests/test/com/google/common/reflect/TypesTest.java +++ b/guava-tests/test/com/google/common/reflect/TypesTest.java @@ -16,6 +16,11 @@ package com.google.common.reflect; +import static com.google.common.reflect.Types.newArrayType; +import static com.google.common.reflect.Types.newArtificialTypeVariable; +import static com.google.common.reflect.Types.newParameterizedType; +import static com.google.common.reflect.Types.subtypeOf; +import static com.google.common.reflect.Types.supertypeOf; import static com.google.common.testing.SerializableTester.reserialize; import static com.google.common.testing.SerializableTester.reserializeAndAssert; import static com.google.common.truth.Truth.assertThat; @@ -51,8 +56,7 @@ public class TypesTest extends TestCase { public void testNewParameterizedType_ownerTypeImplied() throws Exception { ParameterizedType jvmType = (ParameterizedType) new TypeCapture>() {}.capture(); - ParameterizedType ourType = - Types.newParameterizedType(Entry.class, String.class, Integer.class); + ParameterizedType ourType = newParameterizedType(Entry.class, String.class, Integer.class); assertEquals(jvmType, ourType); assertEquals(Map.class, ourType.getOwnerType()); } @@ -60,8 +64,7 @@ public void testNewParameterizedType_ownerTypeImplied() throws Exception { public void testNewParameterizedType() { ParameterizedType jvmType = (ParameterizedType) new TypeCapture>() {}.capture(); - ParameterizedType ourType = - Types.newParameterizedType(HashMap.class, String.class, int[][].class); + ParameterizedType ourType = newParameterizedType(HashMap.class, String.class, int[][].class); new EqualsTester().addEqualityGroup(jvmType, ourType).testEquals(); assertThat(ourType.toString()).isEqualTo(jvmType.toString()); @@ -72,7 +75,7 @@ public void testNewParameterizedType() { .containsExactlyElementsIn(asList(jvmType.getActualTypeArguments())) .inOrder(); assertEquals( - asList(String.class, Types.newArrayType(Types.newArrayType(int.class))), + asList(String.class, newArrayType(newArrayType(int.class))), asList(ourType.getActualTypeArguments())); assertThat(ourType.getOwnerType()).isNull(); } @@ -80,7 +83,7 @@ public void testNewParameterizedType() { public void testNewParameterizedType_nonStaticLocalClass() { class LocalClass {} Type jvmType = new LocalClass() {}.getClass().getGenericSuperclass(); - Type ourType = Types.newParameterizedType(LocalClass.class, String.class); + Type ourType = newParameterizedType(LocalClass.class, String.class); assertEquals(jvmType, ourType); } @@ -91,7 +94,7 @@ public void testNewParameterizedType_staticLocalClass() { private static void doTestNewParameterizedTypeStaticLocalClass() { class LocalClass {} Type jvmType = new LocalClass() {}.getClass().getGenericSuperclass(); - Type ourType = Types.newParameterizedType(LocalClass.class, String.class); + Type ourType = newParameterizedType(LocalClass.class, String.class); assertEquals(jvmType, ourType); } @@ -116,7 +119,7 @@ public void testNewParameterizedTypeWithOwner() { } public void testNewParameterizedType_serializable() { - reserializeAndAssert(Types.newParameterizedType(Entry.class, String.class, Integer.class)); + reserializeAndAssert(newParameterizedType(Entry.class, String.class, Integer.class)); } public void testNewParameterizedType_ownerMismatch() { @@ -127,7 +130,7 @@ public void testNewParameterizedType_ownerMismatch() { public void testNewParameterizedType_ownerMissing() { assertEquals( - Types.newParameterizedType(Entry.class, String.class, Integer.class), + newParameterizedType(Entry.class, String.class, Integer.class), Types.newParameterizedTypeWithOwner(null, Entry.class, String.class, Integer.class)); } @@ -146,10 +149,10 @@ public void testNewParameterizedType_primitiveTypeParameters() { public void testNewArrayType() { Type jvmType1 = new TypeCapture[]>() {}.capture(); GenericArrayType ourType1 = - (GenericArrayType) Types.newArrayType(Types.newParameterizedType(List.class, String.class)); + (GenericArrayType) newArrayType(newParameterizedType(List.class, String.class)); @SuppressWarnings("rawtypes") // test of raw types Type jvmType2 = new TypeCapture() {}.capture(); - Type ourType2 = Types.newArrayType(List.class); + Type ourType2 = newArrayType(List.class); new EqualsTester() .addEqualityGroup(jvmType1, ourType1) .addEqualityGroup(jvmType2, ourType2) @@ -161,30 +164,30 @@ public void testNewArrayType() { public void testNewArrayTypeOfArray() { Type jvmType = new TypeCapture() {}.capture(); - Type ourType = Types.newArrayType(int[].class); + Type ourType = newArrayType(int[].class); assertThat(ourType.toString()).isEqualTo(jvmType.toString()); new EqualsTester().addEqualityGroup(jvmType, ourType).testEquals(); } public void testNewArrayType_primitive() { Type jvmType = new TypeCapture() {}.capture(); - Type ourType = Types.newArrayType(int.class); + Type ourType = newArrayType(int.class); assertThat(ourType.toString()).isEqualTo(jvmType.toString()); new EqualsTester().addEqualityGroup(jvmType, ourType).testEquals(); } public void testNewArrayType_upperBoundedWildcard() { - Type wildcard = Types.subtypeOf(Number.class); - assertEquals(Types.subtypeOf(Number[].class), Types.newArrayType(wildcard)); + Type wildcard = subtypeOf(Number.class); + assertEquals(subtypeOf(Number[].class), newArrayType(wildcard)); } public void testNewArrayType_lowerBoundedWildcard() { - Type wildcard = Types.supertypeOf(Number.class); - assertEquals(Types.supertypeOf(Number[].class), Types.newArrayType(wildcard)); + Type wildcard = supertypeOf(Number.class); + assertEquals(supertypeOf(Number[].class), newArrayType(wildcard)); } public void testNewArrayType_serializable() { - reserializeAndAssert(Types.newArrayType(int[].class)); + reserializeAndAssert(newArrayType(int[].class)); } private static class WithWildcardType { @@ -215,9 +218,9 @@ public void testNewWildcardType() throws Exception { WildcardType objectBoundJvmType = WithWildcardType.getWildcardType("withObjectBound"); WildcardType upperBoundJvmType = WithWildcardType.getWildcardType("withUpperBound"); WildcardType lowerBoundJvmType = WithWildcardType.getWildcardType("withLowerBound"); - WildcardType objectBound = Types.subtypeOf(Object.class); - WildcardType upperBound = Types.subtypeOf(int[][].class); - WildcardType lowerBound = Types.supertypeOf(String[][].class); + WildcardType objectBound = subtypeOf(Object.class); + WildcardType upperBound = subtypeOf(int[][].class); + WildcardType lowerBound = supertypeOf(String[][].class); assertEqualWildcardType(noBoundJvmType, objectBound); assertEqualWildcardType(objectBoundJvmType, objectBound); @@ -232,13 +235,13 @@ public void testNewWildcardType() throws Exception { } public void testNewWildcardType_primitiveTypeBound() { - assertThrows(IllegalArgumentException.class, () -> Types.subtypeOf(int.class)); + assertThrows(IllegalArgumentException.class, () -> subtypeOf(int.class)); } public void testNewWildcardType_serializable() { - reserializeAndAssert(Types.supertypeOf(String.class)); - reserializeAndAssert(Types.subtypeOf(String.class)); - reserializeAndAssert(Types.subtypeOf(Object.class)); + reserializeAndAssert(supertypeOf(String.class)); + reserializeAndAssert(subtypeOf(String.class)); + reserializeAndAssert(subtypeOf(Object.class)); } private static void assertEqualWildcardType(WildcardType expected, WildcardType actual) { @@ -306,18 +309,17 @@ public void testNewTypeVariable() throws Exception { public void testNewTypeVariable_primitiveTypeBound() { assertThrows( IllegalArgumentException.class, - () -> Types.newArtificialTypeVariable(List.class, "E", int.class)); + () -> newArtificialTypeVariable(List.class, "E", int.class)); } public void testNewTypeVariable_serializable() throws Exception { assertThrows( - RuntimeException.class, - () -> reserialize(Types.newArtificialTypeVariable(List.class, "E"))); + RuntimeException.class, () -> reserialize(newArtificialTypeVariable(List.class, "E"))); } private static TypeVariable withBounds( TypeVariable typeVariable, Type... bounds) { - return Types.newArtificialTypeVariable( + return newArtificialTypeVariable( typeVariable.getGenericDeclaration(), typeVariable.getName(), bounds); } @@ -359,7 +361,7 @@ private static void assertEqualTypeVariable(TypeVariable expected, TypeVariab */ public void testNewParameterizedTypeImmutability() { Type[] typesIn = {String.class, Integer.class}; - ParameterizedType parameterizedType = Types.newParameterizedType(Map.class, typesIn); + ParameterizedType parameterizedType = newParameterizedType(Map.class, typesIn); typesIn[0] = null; typesIn[1] = null; @@ -374,7 +376,7 @@ public void testNewParameterizedTypeImmutability() { public void testNewParameterizedTypeWithWrongNumberOfTypeArguments() { assertThrows( IllegalArgumentException.class, - () -> Types.newParameterizedType(Map.class, String.class, Integer.class, Long.class)); + () -> newParameterizedType(Map.class, String.class, Integer.class, Long.class)); } public void testToString() { diff --git a/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java b/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java index 9ac68f3ddd11..c4f11c6b3710 100644 --- a/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java @@ -19,6 +19,7 @@ import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION; import static com.google.common.base.StandardSystemProperty.OS_NAME; import static com.google.common.collect.Iterables.getOnlyElement; +import static com.google.common.collect.Sets.newIdentityHashSet; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; import static com.google.common.util.concurrent.Futures.immediateCancelledFuture; @@ -26,6 +27,8 @@ import static com.google.common.util.concurrent.Futures.immediateFuture; import static com.google.common.util.concurrent.MoreExecutors.directExecutor; import static com.google.common.util.concurrent.SneakyThrows.sneakyThrow; +import static com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly; +import static com.google.common.util.concurrent.Uninterruptibles.getUninterruptibly; import static java.util.Arrays.asList; import static java.util.Collections.shuffle; import static java.util.Collections.singletonList; @@ -40,7 +43,6 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.Range; -import com.google.common.collect.Sets; import com.google.common.primitives.Ints; import com.google.common.util.concurrent.internal.InternalFutureFailureAccess; import java.util.ArrayList; @@ -504,11 +506,11 @@ public void testFutureBash() { return null; } }; - Set finalResults = synchronizedSet(Sets.newIdentityHashSet()); + Set finalResults = synchronizedSet(newIdentityHashSet()); Runnable collectResultsRunnable = () -> { try { - String result = Uninterruptibles.getUninterruptibly(currentFuture.get()); + String result = getUninterruptibly(currentFuture.get()); finalResults.add(result); } catch (ExecutionException e) { finalResults.add(e.getCause()); @@ -523,7 +525,7 @@ public void testFutureBash() { Future future = currentFuture.get(); while (true) { try { - String result = Uninterruptibles.getUninterruptibly(future, 0, SECONDS); + String result = getUninterruptibly(future, 0, SECONDS); finalResults.add(result); break; } catch (ExecutionException e) { @@ -619,11 +621,11 @@ public void testSetFutureCancelBash() { setFutureCompletionSuccess.set(future.set("hello-async-world")); awaitUnchecked(barrier); }; - Set finalResults = synchronizedSet(Sets.newIdentityHashSet()); + Set finalResults = synchronizedSet(newIdentityHashSet()); Runnable collectResultsRunnable = () -> { try { - String result = Uninterruptibles.getUninterruptibly(currentFuture.get()); + String result = getUninterruptibly(currentFuture.get()); finalResults.add(result); } catch (ExecutionException e) { finalResults.add(e.getCause()); @@ -638,7 +640,7 @@ public void testSetFutureCancelBash() { Future future = currentFuture.get(); while (true) { try { - String result = Uninterruptibles.getUninterruptibly(future, 0, SECONDS); + String result = getUninterruptibly(future, 0, SECONDS); finalResults.add(result); break; } catch (ExecutionException e) { @@ -736,11 +738,11 @@ public void testSetFutureCancelBash_withDoneFuture() { return null; } }; - Set finalResults = synchronizedSet(Sets.newIdentityHashSet()); + Set finalResults = synchronizedSet(newIdentityHashSet()); Runnable collectResultsRunnable = () -> { try { - String result = Uninterruptibles.getUninterruptibly(currentFuture.get()); + String result = getUninterruptibly(currentFuture.get()); finalResults.add(result); } catch (ExecutionException e) { finalResults.add(e.getCause()); @@ -1255,7 +1257,7 @@ public void run() { } void awaitInLoop() { - Uninterruptibles.awaitUninterruptibly(completedIteration); + awaitUninterruptibly(completedIteration); } } diff --git a/guava-tests/test/com/google/common/util/concurrent/InterruptibleTaskTest.java b/guava-tests/test/com/google/common/util/concurrent/InterruptibleTaskTest.java index e33daded5621..680bc14f4c26 100644 --- a/guava-tests/test/com/google/common/util/concurrent/InterruptibleTaskTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/InterruptibleTaskTest.java @@ -16,6 +16,7 @@ package com.google.common.util.concurrent; import static com.google.common.truth.Truth.assertThat; +import static com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly; import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertThrows; @@ -198,7 +199,7 @@ static final class SlowChannel extends AbstractInterruptibleChannel { @Override protected void implCloseChannel() { - Uninterruptibles.awaitUninterruptibly(exitClose); + awaitUninterruptibly(exitClose); } void doBegin() { diff --git a/guava-tests/test/com/google/common/util/concurrent/MoreExecutorsTest.java b/guava-tests/test/com/google/common/util/concurrent/MoreExecutorsTest.java index 5a2d685ce1cb..114b81924770 100644 --- a/guava-tests/test/com/google/common/util/concurrent/MoreExecutorsTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/MoreExecutorsTest.java @@ -36,6 +36,7 @@ import static com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService; import static com.google.common.util.concurrent.MoreExecutors.renamingDecorator; import static com.google.common.util.concurrent.MoreExecutors.shutdownAndAwaitTermination; +import static com.google.common.util.concurrent.Uninterruptibles.joinUninterruptibly; import static java.util.Collections.nCopies; import static java.util.concurrent.TimeUnit.DAYS; import static java.util.concurrent.TimeUnit.MILLISECONDS; @@ -223,7 +224,7 @@ public void run() { waiter.start(); awaitTimedWaiting(waiter); service.shutdown(); - Uninterruptibles.joinUninterruptibly(waiter, 10, SECONDS); + joinUninterruptibly(waiter, 10, SECONDS); if (waiter.isAlive()) { waiter.interrupt(); fail("awaitTermination failed to trigger after shutdown()"); diff --git a/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java b/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java index c11d88b2ace4..e585dee85b28 100644 --- a/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java @@ -22,6 +22,8 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; import static com.google.common.util.concurrent.MoreExecutors.directExecutor; +import static com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly; +import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly; import static java.util.Arrays.asList; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.SECONDS; @@ -92,7 +94,7 @@ protected void doStart() { new Thread() { @Override public void run() { - Uninterruptibles.sleepUninterruptibly(delay, MILLISECONDS); + sleepUninterruptibly(delay, MILLISECONDS); notifyStarted(); } }.start(); @@ -103,7 +105,7 @@ protected void doStop() { new Thread() { @Override public void run() { - Uninterruptibles.sleepUninterruptibly(delay, MILLISECONDS); + sleepUninterruptibly(delay, MILLISECONDS); notifyStopped(); } }.start(); @@ -173,7 +175,7 @@ public void testServiceStartupTimes_selfStartingServices() { protected void doStart() { super.doStart(); // This will delay service listener execution at least 150 milliseconds - Uninterruptibles.sleepUninterruptibly(150, MILLISECONDS); + sleepUninterruptibly(150, MILLISECONDS); } }; Service a = @@ -490,7 +492,7 @@ public void run() { // We need to wait for the main thread to leave the ServiceManager.startAsync call // to // ensure that the thread running the failure callbacks is not the main thread. - Uninterruptibles.awaitUninterruptibly(afterStarted); + awaitUninterruptibly(afterStarted); notifyFailed(new Exception("boom")); } }.start(); @@ -508,7 +510,7 @@ protected void doStop() { public void failure(Service service) { failEnter.countDown(); // block until after the service manager is shutdown - Uninterruptibles.awaitUninterruptibly(failLeave); + awaitUninterruptibly(failLeave); } }, directExecutor()); diff --git a/guava-tests/test/com/google/common/util/concurrent/StripedTest.java b/guava-tests/test/com/google/common/util/concurrent/StripedTest.java index 70e4cbb1f0ad..9bf1750797e8 100644 --- a/guava-tests/test/com/google/common/util/concurrent/StripedTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/StripedTest.java @@ -17,6 +17,7 @@ package com.google.common.util.concurrent; import static com.google.common.collect.Iterables.concat; +import static com.google.common.collect.Sets.newIdentityHashSet; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; @@ -184,7 +185,7 @@ public void testBasicInvariants() { } private static void assertBasicInvariants(Striped striped) { - Set observed = Sets.newIdentityHashSet(); // for the sake of weakly referenced locks. + Set observed = newIdentityHashSet(); // for the sake of weakly referenced locks. // this gets the stripes with #getAt(index) for (int i = 0; i < striped.size(); i++) { Object object = striped.getAt(i); diff --git a/guava-tests/test/com/google/common/util/concurrent/WrappingExecutorServiceTest.java b/guava-tests/test/com/google/common/util/concurrent/WrappingExecutorServiceTest.java index d84fe6a2ac92..db55c556da7d 100644 --- a/guava-tests/test/com/google/common/util/concurrent/WrappingExecutorServiceTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/WrappingExecutorServiceTest.java @@ -16,6 +16,7 @@ package com.google.common.util.concurrent; +import static com.google.common.base.Predicates.instanceOf; import static com.google.common.collect.Iterables.all; import static com.google.common.truth.Truth.assertThat; import static com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService; @@ -26,7 +27,6 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import java.util.ArrayList; @@ -307,7 +307,7 @@ public void execute(Runnable command) { } private static void assertTaskWrapped(Collection> tasks) { - Predicate p = Predicates.instanceOf(WrappedCallable.class); + Predicate p = instanceOf(WrappedCallable.class); assertTrue(all(tasks, p)); } } diff --git a/guava/src/com/google/common/cache/LocalCache.java b/guava/src/com/google/common/cache/LocalCache.java index 30f5578e2009..4a90a7320b01 100644 --- a/guava/src/com/google/common/cache/LocalCache.java +++ b/guava/src/com/google/common/cache/LocalCache.java @@ -49,7 +49,6 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; import com.google.common.util.concurrent.UncheckedExecutionException; -import com.google.common.util.concurrent.Uninterruptibles; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.concurrent.GuardedBy; import com.google.errorprone.annotations.concurrent.LazyInit; @@ -2387,7 +2386,7 @@ V scheduleRefresh( ListenableFuture result = loadAsync(key, hash, loadingValueReference, loader); if (result.isDone()) { try { - return Uninterruptibles.getUninterruptibly(result); + return getUninterruptibly(result); } catch (Throwable t) { // don't let refresh exceptions propagate; error was already logged } diff --git a/guava/src/com/google/common/collect/Collections2.java b/guava/src/com/google/common/collect/Collections2.java index 39e7dc97d21a..48a0b703118a 100644 --- a/guava/src/com/google/common/collect/Collections2.java +++ b/guava/src/com/google/common/collect/Collections2.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.and; import static com.google.common.collect.CollectPreconditions.checkNonnegative; import static com.google.common.collect.Iterables.any; import static java.lang.Math.min; @@ -27,7 +28,6 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.base.Function; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.common.math.IntMath; import com.google.common.primitives.Ints; import java.util.AbstractCollection; @@ -131,7 +131,7 @@ static class FilteredCollection extends AbstractColl } FilteredCollection createCombined(Predicate newPredicate) { - return new FilteredCollection<>(unfiltered, Predicates.and(predicate, newPredicate)); + return new FilteredCollection<>(unfiltered, and(predicate, newPredicate)); } @Override diff --git a/guava/src/com/google/common/collect/FilteredKeyMultimap.java b/guava/src/com/google/common/collect/FilteredKeyMultimap.java index 280735c5b477..5ed5220d4e0f 100644 --- a/guava/src/com/google/common/collect/FilteredKeyMultimap.java +++ b/guava/src/com/google/common/collect/FilteredKeyMultimap.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkPositionIndex; +import static com.google.common.collect.Maps.filterKeys; import static java.util.Collections.emptyList; import static java.util.Collections.emptySet; @@ -217,7 +218,7 @@ Collection createValues() { @Override Map> createAsMap() { - return Maps.filterKeys(unfiltered.asMap(), keyPredicate); + return filterKeys(unfiltered.asMap(), keyPredicate); } @Override diff --git a/guava/src/com/google/common/collect/ImmutableRangeSet.java b/guava/src/com/google/common/collect/ImmutableRangeSet.java index 4da6fa8513c7..7cd4d2cf3368 100644 --- a/guava/src/com/google/common/collect/ImmutableRangeSet.java +++ b/guava/src/com/google/common/collect/ImmutableRangeSet.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkElementIndex; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.Iterables.getOnlyElement; import static com.google.common.collect.Iterators.emptyIterator; import static com.google.common.collect.Iterators.peekingIterator; @@ -421,7 +422,7 @@ private ImmutableRangeSet lazyComplement() { * @since 21.0 */ public ImmutableRangeSet union(RangeSet other) { - return unionOf(Iterables.concat(asRanges(), other.asRanges())); + return unionOf(concat(asRanges(), other.asRanges())); } /** diff --git a/guava/src/com/google/common/collect/ImmutableSortedMultiset.java b/guava/src/com/google/common/collect/ImmutableSortedMultiset.java index df494e02a6a9..4807f6500dcf 100644 --- a/guava/src/com/google/common/collect/ImmutableSortedMultiset.java +++ b/guava/src/com/google/common/collect/ImmutableSortedMultiset.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Lists.newArrayListWithCapacity; import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; @@ -171,7 +172,7 @@ public static > ImmutableSortedMultiset of( public static > ImmutableSortedMultiset of( E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) { int size = remaining.length + 6; - List all = Lists.newArrayListWithCapacity(size); + List all = newArrayListWithCapacity(size); Collections.addAll(all, e1, e2, e3, e4, e5, e6); Collections.addAll(all, remaining); return copyOf(Ordering.natural(), all); diff --git a/guava/src/com/google/common/collect/Iterables.java b/guava/src/com/google/common/collect/Iterables.java index 45bcf4c0da54..c2557d27e50f 100644 --- a/guava/src/com/google/common/collect/Iterables.java +++ b/guava/src/com/google/common/collect/Iterables.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.instanceOf; import static com.google.common.collect.CollectPreconditions.checkRemove; import com.google.common.annotations.GwtCompatible; @@ -25,7 +26,6 @@ import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.InlineMe; import java.util.Collection; @@ -618,7 +618,7 @@ public Spliterator spliterator() { public static Iterable filter(Iterable unfiltered, Class desiredType) { checkNotNull(unfiltered); checkNotNull(desiredType); - return (Iterable) filter(unfiltered, Predicates.instanceOf(desiredType)); + return (Iterable) filter(unfiltered, instanceOf(desiredType)); } /** diff --git a/guava/src/com/google/common/collect/Maps.java b/guava/src/com/google/common/collect/Maps.java index 2e2695a61c30..98cfa202f403 100644 --- a/guava/src/com/google/common/collect/Maps.java +++ b/guava/src/com/google/common/collect/Maps.java @@ -18,11 +18,14 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.and; import static com.google.common.base.Predicates.compose; import static com.google.common.collect.CollectPreconditions.checkEntryNotNull; import static com.google.common.collect.CollectPreconditions.checkNonnegative; import static com.google.common.collect.Iterables.any; +import static com.google.common.collect.Iterables.removeFirstMatching; import static com.google.common.collect.Iterators.filter; +import static com.google.common.collect.Iterators.transform; import static com.google.common.collect.NullnessCasts.uncheckedCastNullableTToT; import static com.google.common.collect.Sets.unmodifiableNavigableSet; import static java.lang.Math.ceil; @@ -38,7 +41,6 @@ import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.common.collect.MapDifference.ValueDifference; import com.google.common.primitives.Ints; import com.google.errorprone.annotations.CanIgnoreReturnValue; @@ -2162,8 +2164,7 @@ public Set keySet() { @Override Iterator> entryIterator() { - return Iterators.transform( - fromMap.entrySet().iterator(), asEntryToEntryFunction(transformer)); + return transform(fromMap.entrySet().iterator(), asEntryToEntryFunction(transformer)); } @Override @@ -2772,7 +2773,7 @@ NavigableMap filterEntries( */ private static Map filterFiltered( AbstractFilteredMap map, Predicate> entryPredicate) { - return new FilteredEntryMap<>(map.unfiltered, Predicates.and(map.predicate, entryPredicate)); + return new FilteredEntryMap<>(map.unfiltered, and(map.predicate, entryPredicate)); } /** @@ -2782,7 +2783,7 @@ NavigableMap filterEntries( private static SortedMap filterFiltered( FilteredEntrySortedMap map, Predicate> entryPredicate) { - Predicate> predicate = Predicates.and(map.predicate, entryPredicate); + Predicate> predicate = and(map.predicate, entryPredicate); return new FilteredEntrySortedMap<>(map.sortedMap(), predicate); } @@ -2794,7 +2795,7 @@ SortedMap filterFiltered( private static NavigableMap filterFiltered( FilteredEntryNavigableMap map, Predicate> entryPredicate) { - Predicate> predicate = Predicates.and(map.entryPredicate, entryPredicate); + Predicate> predicate = and(map.entryPredicate, entryPredicate); return new FilteredEntryNavigableMap<>(map.unfiltered, predicate); } @@ -2805,7 +2806,7 @@ NavigableMap filterFiltered( private static BiMap filterFiltered( FilteredEntryBiMap map, Predicate> entryPredicate) { - Predicate> predicate = Predicates.and(map.predicate, entryPredicate); + Predicate> predicate = and(map.predicate, entryPredicate); return new FilteredEntryBiMap<>(map.unfiltered(), predicate); } @@ -3292,12 +3293,12 @@ public Set> entrySet() { @Override public @Nullable Entry pollFirstEntry() { - return Iterables.removeFirstMatching(unfiltered.entrySet(), entryPredicate); + return removeFirstMatching(unfiltered.entrySet(), entryPredicate); } @Override public @Nullable Entry pollLastEntry() { - return Iterables.removeFirstMatching(unfiltered.descendingMap().entrySet(), entryPredicate); + return removeFirstMatching(unfiltered.descendingMap().entrySet(), entryPredicate); } @Override diff --git a/guava/src/com/google/common/collect/Multimaps.java b/guava/src/com/google/common/collect/Multimaps.java index 3718e2e986b9..4adedc1543e2 100644 --- a/guava/src/com/google/common/collect/Multimaps.java +++ b/guava/src/com/google/common/collect/Multimaps.java @@ -17,13 +17,16 @@ package com.google.common.collect; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.and; import static com.google.common.collect.CollectPreconditions.checkNonnegative; import static com.google.common.collect.CollectPreconditions.checkRemove; import static com.google.common.collect.Maps.immutableEntry; import static com.google.common.collect.Maps.safeGet; +import static com.google.common.collect.Maps.unmodifiableEntrySet; import static com.google.common.collect.Multisets.unmodifiableMultiset; import static com.google.common.collect.NullnessCasts.uncheckedCastNullableTToT; import static com.google.common.collect.Sets.unmodifiableNavigableSet; +import static java.util.Collections.unmodifiableCollection; import static java.util.Collections.unmodifiableList; import static java.util.Collections.unmodifiableMap; import static java.util.Collections.unmodifiableSet; @@ -35,7 +38,6 @@ import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Function; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.common.base.Supplier; import com.google.common.collect.Maps.EntryTransformer; import com.google.errorprone.annotations.CanIgnoreReturnValue; @@ -49,7 +51,6 @@ import java.io.Serializable; import java.util.AbstractCollection; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; @@ -257,7 +258,7 @@ protected Collection createCollection() { } else if (collection instanceof List) { return unmodifiableList((List) collection); } else { - return Collections.unmodifiableCollection(collection); + return unmodifiableCollection(collection); } } @@ -788,7 +789,7 @@ public Collection replaceValues(@ParametricNullness K key, Iterable values() { Collection result = values; if (result == null) { - values = result = Collections.unmodifiableCollection(delegate.values()); + values = result = unmodifiableCollection(delegate.values()); } return result; } @@ -849,7 +850,7 @@ public Set get(@ParametricNullness K key) { @Override public Set> entries() { - return Maps.unmodifiableEntrySet(delegate().entries()); + return unmodifiableEntrySet(delegate().entries()); } @Override @@ -1051,7 +1052,7 @@ public static ListMultimap unmodifiableListMultimap( } else if (collection instanceof List) { return unmodifiableList((List) collection); } - return Collections.unmodifiableCollection(collection); + return unmodifiableCollection(collection); } /** @@ -1065,9 +1066,9 @@ public static ListMultimap unmodifiableListMultimap( private static Collection> unmodifiableEntries(Collection> entries) { if (entries instanceof Set) { - return Maps.unmodifiableEntrySet((Set>) entries); + return unmodifiableEntrySet((Set>) entries); } - return new Maps.UnmodifiableEntries<>(Collections.unmodifiableCollection(entries)); + return new Maps.UnmodifiableEntries<>(unmodifiableCollection(entries)); } /** @@ -1968,8 +1969,7 @@ public void clear() { return filterKeys((ListMultimap) unfiltered, keyPredicate); } else if (unfiltered instanceof FilteredKeyMultimap) { FilteredKeyMultimap prev = (FilteredKeyMultimap) unfiltered; - return new FilteredKeyMultimap<>( - prev.unfiltered, Predicates.and(prev.keyPredicate, keyPredicate)); + return new FilteredKeyMultimap<>(prev.unfiltered, and(prev.keyPredicate, keyPredicate)); } else if (unfiltered instanceof FilteredMultimap) { FilteredMultimap prev = (FilteredMultimap) unfiltered; return filterFiltered(prev, Maps.keyPredicateOnEntries(keyPredicate)); @@ -2010,8 +2010,7 @@ SetMultimap filterKeys( SetMultimap unfiltered, Predicate keyPredicate) { if (unfiltered instanceof FilteredKeySetMultimap) { FilteredKeySetMultimap prev = (FilteredKeySetMultimap) unfiltered; - return new FilteredKeySetMultimap<>( - prev.unfiltered(), Predicates.and(prev.keyPredicate, keyPredicate)); + return new FilteredKeySetMultimap<>(prev.unfiltered(), and(prev.keyPredicate, keyPredicate)); } else if (unfiltered instanceof FilteredSetMultimap) { FilteredSetMultimap prev = (FilteredSetMultimap) unfiltered; return filterFiltered(prev, Maps.keyPredicateOnEntries(keyPredicate)); @@ -2052,8 +2051,7 @@ ListMultimap filterKeys( ListMultimap unfiltered, Predicate keyPredicate) { if (unfiltered instanceof FilteredKeyListMultimap) { FilteredKeyListMultimap prev = (FilteredKeyListMultimap) unfiltered; - return new FilteredKeyListMultimap<>( - prev.unfiltered(), Predicates.and(prev.keyPredicate, keyPredicate)); + return new FilteredKeyListMultimap<>(prev.unfiltered(), and(prev.keyPredicate, keyPredicate)); } else { return new FilteredKeyListMultimap<>(unfiltered, keyPredicate); } @@ -2204,7 +2202,7 @@ SetMultimap filterEntries( private static Multimap filterFiltered( FilteredMultimap multimap, Predicate> entryPredicate) { - Predicate> predicate = Predicates.and(multimap.entryPredicate(), entryPredicate); + Predicate> predicate = and(multimap.entryPredicate(), entryPredicate); return new FilteredEntryMultimap<>(multimap.unfiltered(), predicate); } @@ -2217,7 +2215,7 @@ Multimap filterFiltered( private static SetMultimap filterFiltered( FilteredSetMultimap multimap, Predicate> entryPredicate) { - Predicate> predicate = Predicates.and(multimap.entryPredicate(), entryPredicate); + Predicate> predicate = and(multimap.entryPredicate(), entryPredicate); return new FilteredEntrySetMultimap<>(multimap.unfiltered(), predicate); } diff --git a/guava/src/com/google/common/collect/Multisets.java b/guava/src/com/google/common/collect/Multisets.java index 5097a82d74f0..c05f66f5c27d 100644 --- a/guava/src/com/google/common/collect/Multisets.java +++ b/guava/src/com/google/common/collect/Multisets.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.and; import static com.google.common.collect.CollectPreconditions.checkNonnegative; import static com.google.common.collect.CollectPreconditions.checkRemove; import static java.lang.Math.max; @@ -32,7 +33,6 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.common.collect.Multiset.Entry; import com.google.common.math.IntMath; import com.google.common.primitives.Ints; @@ -321,7 +321,7 @@ public final int getCount() { // Support clear(), removeAll(), and retainAll() when filtering a filtered // collection. FilteredMultiset filtered = (FilteredMultiset) unfiltered; - Predicate combinedPredicate = Predicates.and(filtered.predicate, predicate); + Predicate combinedPredicate = and(filtered.predicate, predicate); return new FilteredMultiset<>(filtered.unfiltered, combinedPredicate); } return new FilteredMultiset<>(unfiltered, predicate); diff --git a/guava/src/com/google/common/collect/Sets.java b/guava/src/com/google/common/collect/Sets.java index 691cdf276c42..5209473fdfc8 100644 --- a/guava/src/com/google/common/collect/Sets.java +++ b/guava/src/com/google/common/collect/Sets.java @@ -18,8 +18,10 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.and; import static com.google.common.collect.CollectPreconditions.checkNonnegative; import static com.google.common.collect.Iterables.find; +import static com.google.common.collect.Iterables.removeFirstMatching; import static com.google.common.collect.Iterators.find; import static com.google.common.math.IntMath.saturatedAdd; import static java.lang.Math.max; @@ -31,7 +33,6 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.common.collect.Collections2.FilteredCollection; import com.google.common.math.IntMath; import com.google.errorprone.annotations.CanIgnoreReturnValue; @@ -1196,7 +1197,7 @@ int maxSize() { // Support clear(), removeAll(), and retainAll() when filtering a filtered // collection. FilteredSet filtered = (FilteredSet) unfiltered; - Predicate combinedPredicate = Predicates.and(filtered.predicate, predicate); + Predicate combinedPredicate = and(filtered.predicate, predicate); return new FilteredSet<>((Set) filtered.unfiltered, combinedPredicate); } @@ -1233,7 +1234,7 @@ int maxSize() { // Support clear(), removeAll(), and retainAll() when filtering a filtered // collection. FilteredSet filtered = (FilteredSet) unfiltered; - Predicate combinedPredicate = Predicates.and(filtered.predicate, predicate); + Predicate combinedPredicate = and(filtered.predicate, predicate); return new FilteredSortedSet<>((SortedSet) filtered.unfiltered, combinedPredicate); } @@ -1271,7 +1272,7 @@ int maxSize() { // Support clear(), removeAll(), and retainAll() when filtering a filtered // collection. FilteredSet filtered = (FilteredSet) unfiltered; - Predicate combinedPredicate = Predicates.and(filtered.predicate, predicate); + Predicate combinedPredicate = and(filtered.predicate, predicate); return new FilteredNavigableSet<>((NavigableSet) filtered.unfiltered, combinedPredicate); } @@ -1376,12 +1377,12 @@ NavigableSet unfiltered() { @Override public @Nullable E pollFirst() { - return Iterables.removeFirstMatching(unfiltered(), predicate); + return removeFirstMatching(unfiltered(), predicate); } @Override public @Nullable E pollLast() { - return Iterables.removeFirstMatching(unfiltered().descendingSet(), predicate); + return removeFirstMatching(unfiltered().descendingSet(), predicate); } @Override diff --git a/guava/src/com/google/common/collect/Tables.java b/guava/src/com/google/common/collect/Tables.java index e7edd5590dbe..2018209bab67 100644 --- a/guava/src/com/google/common/collect/Tables.java +++ b/guava/src/com/google/common/collect/Tables.java @@ -18,7 +18,9 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterators.transform; import static com.google.common.collect.NullnessCasts.uncheckedCastNullableTToT; +import static java.util.Collections.unmodifiableCollection; import static java.util.Collections.unmodifiableMap; import static java.util.Collections.unmodifiableSet; import static java.util.Collections.unmodifiableSortedMap; @@ -318,7 +320,7 @@ public Collection values() { @Override Iterator> cellIterator() { - return Iterators.transform(original.cellSet().iterator(), Tables::transposeCell); + return transform(original.cellSet().iterator(), Tables::transposeCell); } @Override @@ -490,7 +492,7 @@ Cell applyToValue(Cell cell) { @Override Iterator> cellIterator() { - return Iterators.transform(fromTable.cellSet().iterator(), this::applyToValue); + return transform(fromTable.cellSet().iterator(), this::applyToValue); } @Override @@ -621,7 +623,7 @@ public Map> rowMap() { @Override public Collection values() { - return Collections.unmodifiableCollection(super.values()); + return unmodifiableCollection(super.values()); } @GwtIncompatible @J2ktIncompatible private static final long serialVersionUID = 0; diff --git a/guava/src/com/google/common/eventbus/SubscriberRegistry.java b/guava/src/com/google/common/eventbus/SubscriberRegistry.java index 158635ccdc54..7484d250f04a 100644 --- a/guava/src/com/google/common/eventbus/SubscriberRegistry.java +++ b/guava/src/com/google/common/eventbus/SubscriberRegistry.java @@ -16,6 +16,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterators.concat; +import static com.google.common.collect.Lists.newArrayListWithCapacity; import static java.util.Arrays.asList; import com.google.common.annotations.VisibleForTesting; @@ -26,8 +28,6 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.primitives.Primitives; @@ -125,8 +125,7 @@ Set getSubscribersForTesting(Class eventType) { Iterator getSubscribers(Object event) { ImmutableSet> eventTypes = flattenHierarchy(event.getClass()); - List> subscriberIterators = - Lists.newArrayListWithCapacity(eventTypes.size()); + List> subscriberIterators = newArrayListWithCapacity(eventTypes.size()); for (Class eventType : eventTypes) { CopyOnWriteArraySet eventSubscribers = subscribers.get(eventType); @@ -136,7 +135,7 @@ Iterator getSubscribers(Object event) { } } - return Iterators.concat(subscriberIterators.iterator()); + return concat(subscriberIterators.iterator()); } /** diff --git a/guava/src/com/google/common/graph/AbstractBaseGraph.java b/guava/src/com/google/common/graph/AbstractBaseGraph.java index c1ec51da5c5a..98572d071db2 100644 --- a/guava/src/com/google/common/graph/AbstractBaseGraph.java +++ b/guava/src/com/google/common/graph/AbstractBaseGraph.java @@ -19,6 +19,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static com.google.common.collect.Iterators.concat; +import static com.google.common.collect.Iterators.transform; import static com.google.common.graph.GraphConstants.ENDPOINTS_MISMATCH; import static com.google.common.graph.GraphConstants.NODE_PAIR_REMOVED_FROM_GRAPH; import static com.google.common.graph.GraphConstants.NODE_REMOVED_FROM_GRAPH; @@ -113,18 +115,18 @@ public Set> incidentEdges(N node) { public UnmodifiableIterator> iterator() { if (graph.isDirected()) { return Iterators.unmodifiableIterator( - Iterators.concat( - Iterators.transform( + concat( + transform( graph.predecessors(node).iterator(), (N predecessor) -> EndpointPair.ordered(predecessor, node)), - Iterators.transform( + transform( // filter out 'node' from successors (already covered by predecessors, // above) Sets.difference(graph.successors(node), ImmutableSet.of(node)).iterator(), (N successor) -> EndpointPair.ordered(node, successor)))); } else { return Iterators.unmodifiableIterator( - Iterators.transform( + transform( graph.adjacentNodes(node).iterator(), (N adjacentNode) -> EndpointPair.unordered(node, adjacentNode))); } @@ -250,7 +252,7 @@ public Set> inEdges(N node) { @Override public UnmodifiableIterator> iterator() { return Iterators.unmodifiableIterator( - Iterators.transform( + transform( graph.predecessors(node).iterator(), (N predecessor) -> graph.isDirected() @@ -270,7 +272,7 @@ public Set> outEdges(N node) { @Override public UnmodifiableIterator> iterator() { return Iterators.unmodifiableIterator( - Iterators.transform( + transform( graph.successors(node).iterator(), (N successor) -> graph.isDirected() diff --git a/guava/src/com/google/common/graph/AbstractDirectedNetworkConnections.java b/guava/src/com/google/common/graph/AbstractDirectedNetworkConnections.java index 9993dd91029e..ca63b49c0e70 100644 --- a/guava/src/com/google/common/graph/AbstractDirectedNetworkConnections.java +++ b/guava/src/com/google/common/graph/AbstractDirectedNetworkConnections.java @@ -18,12 +18,12 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static com.google.common.collect.Iterables.concat; import static com.google.common.graph.Graphs.checkNonNegative; import static com.google.common.graph.Graphs.checkPositive; import static java.util.Collections.unmodifiableSet; import static java.util.Objects.requireNonNull; -import com.google.common.collect.Iterables; import com.google.common.collect.Iterators; import com.google.common.collect.Sets; import com.google.common.collect.UnmodifiableIterator; @@ -68,7 +68,7 @@ public Set incidentEdges() { public UnmodifiableIterator iterator() { Iterable incidentEdges = (selfLoopCount == 0) - ? Iterables.concat(inEdgeMap.keySet(), outEdgeMap.keySet()) + ? concat(inEdgeMap.keySet(), outEdgeMap.keySet()) : Sets.union(inEdgeMap.keySet(), outEdgeMap.keySet()); return Iterators.unmodifiableIterator(incidentEdges.iterator()); } diff --git a/guava/src/com/google/common/graph/AbstractNetwork.java b/guava/src/com/google/common/graph/AbstractNetwork.java index 6caac7f63886..56dee44c54e0 100644 --- a/guava/src/com/google/common/graph/AbstractNetwork.java +++ b/guava/src/com/google/common/graph/AbstractNetwork.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterators.transform; import static com.google.common.graph.GraphConstants.EDGE_REMOVED_FROM_GRAPH; import static com.google.common.graph.GraphConstants.ENDPOINTS_MISMATCH; import static com.google.common.graph.GraphConstants.MULTIPLE_EDGES_CONNECTING; @@ -27,7 +28,6 @@ import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterators; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import com.google.common.math.IntMath; @@ -72,8 +72,7 @@ public Set> edges() { return new AbstractSet>() { @Override public Iterator> iterator() { - return Iterators.transform( - AbstractNetwork.this.edges().iterator(), edge -> incidentNodes(edge)); + return transform(AbstractNetwork.this.edges().iterator(), edge -> incidentNodes(edge)); } @Override diff --git a/guava/src/com/google/common/graph/DirectedGraphConnections.java b/guava/src/com/google/common/graph/DirectedGraphConnections.java index bf1c04e9b3dd..87ac0ea4f427 100644 --- a/guava/src/com/google/common/graph/DirectedGraphConnections.java +++ b/guava/src/com/google/common/graph/DirectedGraphConnections.java @@ -19,6 +19,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static com.google.common.collect.Iterators.concat; +import static com.google.common.collect.Iterators.transform; import static com.google.common.graph.GraphConstants.INNER_CAPACITY; import static com.google.common.graph.GraphConstants.INNER_LOAD_FACTOR; import static com.google.common.graph.Graphs.checkNonNegative; @@ -28,7 +30,6 @@ import com.google.common.base.Function; import com.google.common.collect.AbstractIterator; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterators; import com.google.common.collect.UnmodifiableIterator; import java.util.AbstractSet; import java.util.ArrayList; @@ -371,16 +372,16 @@ public Iterator> incidentEdgeIterator(N thisNode) { Iterator> resultWithDoubleSelfLoop; if (orderedNodeConnections == null) { resultWithDoubleSelfLoop = - Iterators.concat( - Iterators.transform( + concat( + transform( predecessors().iterator(), (N predecessor) -> EndpointPair.ordered(predecessor, thisNode)), - Iterators.transform( + transform( successors().iterator(), (N successor) -> EndpointPair.ordered(thisNode, successor))); } else { resultWithDoubleSelfLoop = - Iterators.transform( + transform( orderedNodeConnections.iterator(), (NodeConnection connection) -> { if (connection instanceof NodeConnection.Succ) { diff --git a/guava/src/com/google/common/graph/Graphs.java b/guava/src/com/google/common/graph/Graphs.java index 09107afd91b9..5addb2a91aca 100644 --- a/guava/src/com/google/common/graph/Graphs.java +++ b/guava/src/com/google/common/graph/Graphs.java @@ -17,12 +17,12 @@ package com.google.common.graph; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.collect.Iterators.transform; import static com.google.common.graph.GraphConstants.NODE_NOT_IN_GRAPH; import static com.google.common.graph.Graphs.TransitiveClosureSelfLoopStrategy.ADD_SELF_LOOPS_ALWAYS; import static java.util.Objects.requireNonNull; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterators; import com.google.common.collect.Maps; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.ArrayDeque; @@ -368,7 +368,7 @@ public Set> incidentEdges(N node) { return new IncidentEdgeSet(this, node, IncidentEdgeSet.EdgeType.BOTH) { @Override public Iterator> iterator() { - return Iterators.transform( + return transform( delegate().incidentEdges(node).iterator(), edge -> EndpointPair.of(delegate(), edge.nodeV(), edge.nodeU())); } diff --git a/guava/src/com/google/common/graph/UndirectedGraphConnections.java b/guava/src/com/google/common/graph/UndirectedGraphConnections.java index 8d2276a8666e..aaf0d5a84be4 100644 --- a/guava/src/com/google/common/graph/UndirectedGraphConnections.java +++ b/guava/src/com/google/common/graph/UndirectedGraphConnections.java @@ -17,12 +17,12 @@ package com.google.common.graph; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterators.transform; import static com.google.common.graph.GraphConstants.INNER_CAPACITY; import static com.google.common.graph.GraphConstants.INNER_LOAD_FACTOR; import static java.util.Collections.unmodifiableSet; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterators; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; @@ -78,7 +78,7 @@ public Set successors() { @Override public Iterator> incidentEdgeIterator(N thisNode) { - return Iterators.transform( + return transform( adjacentNodeValues.keySet().iterator(), (N incidentNode) -> EndpointPair.unordered(thisNode, incidentNode)); } diff --git a/guava/src/com/google/common/hash/BloomFilter.java b/guava/src/com/google/common/hash/BloomFilter.java index 0a3209d46d50..e58c1ec58fce 100644 --- a/guava/src/com/google/common/hash/BloomFilter.java +++ b/guava/src/com/google/common/hash/BloomFilter.java @@ -19,6 +19,7 @@ import static java.lang.Byte.toUnsignedInt; import static java.lang.Math.log; import static java.lang.Math.max; +import static java.lang.Math.round; import com.google.common.annotations.Beta; import com.google.common.annotations.J2ktIncompatible; @@ -554,7 +555,7 @@ public int hashCode() { @VisibleForTesting static int optimalNumOfHashFunctions(double p) { // -log(p) / log(2), ensuring the result is rounded to avoid truncation. - return max(1, (int) Math.round(-log(p) / LOG_TWO)); + return max(1, (int) round(-log(p) / LOG_TWO)); } /** diff --git a/guava/src/com/google/common/math/LongMath.java b/guava/src/com/google/common/math/LongMath.java index fa0a4635adc7..f3c7728b8ba9 100644 --- a/guava/src/com/google/common/math/LongMath.java +++ b/guava/src/com/google/common/math/LongMath.java @@ -22,6 +22,7 @@ import static com.google.common.math.MathPreconditions.checkRoundingUnnecessary; import static java.lang.Math.abs; import static java.lang.Math.ceil; +import static java.lang.Math.floor; import static java.lang.Math.min; import static java.lang.Math.nextDown; import static java.lang.Math.nextUp; @@ -1299,7 +1300,7 @@ public static double roundToDouble(long x, RoundingMode mode) { roundCeilingAsDouble = roundArbitrarily; roundCeiling = roundArbitrarilyAsLong; roundFloorAsDouble = nextDown(roundArbitrarily); - roundFloor = (long) Math.floor(roundFloorAsDouble); + roundFloor = (long) floor(roundFloorAsDouble); } long deltaToFloor = x - roundFloor; diff --git a/guava/src/com/google/common/net/InetAddresses.java b/guava/src/com/google/common/net/InetAddresses.java index 0bfe6b26a559..b940760b75d7 100644 --- a/guava/src/com/google/common/net/InetAddresses.java +++ b/guava/src/com/google/common/net/InetAddresses.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.hash.Hashing.murmur3_32_fixed; +import static com.google.common.io.ByteStreams.newDataInput; import static java.lang.Math.max; import static java.lang.System.arraycopy; import static java.util.Objects.requireNonNull; @@ -25,7 +26,6 @@ import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.CharMatcher; import com.google.common.base.MoreObjects; -import com.google.common.io.ByteStreams; import com.google.common.primitives.Ints; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.FormatMethod; @@ -832,10 +832,10 @@ public static TeredoInfo getTeredoInfo(Inet6Address ip) { byte[] bytes = ip.getAddress(); Inet4Address server = getInet4Address(Arrays.copyOfRange(bytes, 4, 8)); - int flags = ByteStreams.newDataInput(bytes, 8).readShort() & 0xffff; + int flags = newDataInput(bytes, 8).readShort() & 0xffff; // Teredo obfuscates the mapped client port, per section 4 of the RFC. - int port = ~ByteStreams.newDataInput(bytes, 10).readShort() & 0xffff; + int port = ~newDataInput(bytes, 10).readShort() & 0xffff; byte[] clientBytes = Arrays.copyOfRange(bytes, 12, 16); for (int i = 0; i < clientBytes.length; i++) { @@ -1063,7 +1063,7 @@ public static Inet4Address getCoercedIPv4Address(InetAddress ip) { * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { - return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); + return newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); } /** diff --git a/guava/src/com/google/common/primitives/SignedBytes.java b/guava/src/com/google/common/primitives/SignedBytes.java index f66b4bc84cb1..77506e8beac1 100644 --- a/guava/src/com/google/common/primitives/SignedBytes.java +++ b/guava/src/com/google/common/primitives/SignedBytes.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkPositionIndexes; +import static com.google.common.primitives.Bytes.reverse; import static java.util.Arrays.sort; import com.google.common.annotations.GwtCompatible; @@ -212,6 +213,6 @@ public static void sortDescending(byte[] array, int fromIndex, int toIndex) { checkNotNull(array); checkPositionIndexes(fromIndex, toIndex, array.length); sort(array, fromIndex, toIndex); - Bytes.reverse(array, fromIndex, toIndex); + reverse(array, fromIndex, toIndex); } } diff --git a/guava/src/com/google/common/reflect/Invokable.java b/guava/src/com/google/common/reflect/Invokable.java index 2f3015c8d5da..073d7d6cd5ed 100644 --- a/guava/src/com/google/common/reflect/Invokable.java +++ b/guava/src/com/google/common/reflect/Invokable.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.reflect.Types.newParameterizedType; import static java.lang.System.arraycopy; import com.google.common.collect.ImmutableList; @@ -448,7 +449,7 @@ Type getGenericReturnType() { Class declaringClass = getDeclaringClass(); TypeVariable[] typeParams = declaringClass.getTypeParameters(); if (typeParams.length > 0) { - return Types.newParameterizedType(declaringClass, typeParams); + return newParameterizedType(declaringClass, typeParams); } else { return declaringClass; } diff --git a/guava/src/com/google/common/reflect/MutableTypeToInstanceMap.java b/guava/src/com/google/common/reflect/MutableTypeToInstanceMap.java index 7d355cc6677c..35701bb5cf04 100644 --- a/guava/src/com/google/common/reflect/MutableTypeToInstanceMap.java +++ b/guava/src/com/google/common/reflect/MutableTypeToInstanceMap.java @@ -15,11 +15,11 @@ package com.google.common.reflect; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterators.transform; import com.google.common.collect.ForwardingMap; import com.google.common.collect.ForwardingMapEntry; import com.google.common.collect.ForwardingSet; -import com.google.common.collect.Iterators; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.DoNotCall; import java.util.HashMap; @@ -155,7 +155,7 @@ public Object[] toArray() { private static Iterator> transformEntries( Iterator> entries) { - return Iterators.transform(entries, UnmodifiableEntry::new); + return transform(entries, UnmodifiableEntry::new); } private UnmodifiableEntry(Entry delegate) { diff --git a/guava/src/com/google/common/reflect/TypeResolver.java b/guava/src/com/google/common/reflect/TypeResolver.java index 9e184a47855d..e3542a917cbb 100644 --- a/guava/src/com/google/common/reflect/TypeResolver.java +++ b/guava/src/com/google/common/reflect/TypeResolver.java @@ -17,6 +17,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static com.google.common.reflect.Types.newArrayType; +import static com.google.common.reflect.Types.newArtificialTypeVariable; import static java.util.Arrays.asList; import com.google.common.base.Joiner; @@ -251,7 +253,7 @@ private WildcardType resolveWildcardType(WildcardType type) { private Type resolveGenericArrayType(GenericArrayType type) { Type componentType = type.getGenericComponentType(); Type resolvedComponentType = resolveType(componentType); - return Types.newArrayType(resolvedComponentType); + return newArrayType(resolvedComponentType); } private ParameterizedType resolveParameterizedType(ParameterizedType type) { @@ -380,7 +382,7 @@ Type resolveInternal(TypeVariable var, TypeTable forDependants) { && Arrays.equals(bounds, resolvedBounds)) { return var; } - return Types.newArtificialTypeVariable( + return newArtificialTypeVariable( var.getGenericDeclaration(), var.getName(), resolvedBounds); } // in case the type is yet another type variable. @@ -487,8 +489,7 @@ final Type capture(Type type) { } if (type instanceof GenericArrayType) { GenericArrayType arrayType = (GenericArrayType) type; - return Types.newArrayType( - notForTypeVariable().capture(arrayType.getGenericComponentType())); + return newArrayType(notForTypeVariable().capture(arrayType.getGenericComponentType())); } if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; @@ -519,7 +520,7 @@ final Type capture(Type type) { TypeVariable captureAsTypeVariable(Type[] upperBounds) { String name = "capture#" + id.incrementAndGet() + "-of ? extends " + Joiner.on('&').join(upperBounds); - return Types.newArtificialTypeVariable(WildcardCapturer.class, name, upperBounds); + return newArtificialTypeVariable(WildcardCapturer.class, name, upperBounds); } private WildcardCapturer forTypeVariable(TypeVariable typeParam) { diff --git a/guava/src/com/google/common/reflect/TypeToken.java b/guava/src/com/google/common/reflect/TypeToken.java index 0bbdae02ca87..486e3adda9e6 100644 --- a/guava/src/com/google/common/reflect/TypeToken.java +++ b/guava/src/com/google/common/reflect/TypeToken.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static com.google.common.reflect.Types.newArrayType; import static java.lang.Math.max; import static java.util.Arrays.asList; import static java.util.Objects.requireNonNull; @@ -1027,7 +1028,7 @@ private static Type canonicalizeWildcardsInType(Type type) { return canonicalizeWildcardsInParameterizedType((ParameterizedType) type); } if (type instanceof GenericArrayType) { - return Types.newArrayType( + return newArrayType( canonicalizeWildcardsInType(((GenericArrayType) type).getGenericComponentType())); } return type; @@ -1167,7 +1168,7 @@ private boolean isOwnedBySubtypeOf(Type supertype) { static TypeToken toGenericType(Class cls) { if (cls.isArray()) { Type arrayOfGenericType = - Types.newArrayType( + newArrayType( // If we are passed with int[].class, don't turn it to GenericArrayType toGenericType(cls.getComponentType()).runtimeType); @SuppressWarnings("unchecked") // array is covariant diff --git a/guava/src/com/google/common/util/concurrent/CycleDetectingLockFactory.java b/guava/src/com/google/common/util/concurrent/CycleDetectingLockFactory.java index 5a71a4c1b1b7..b2bb64796b1e 100644 --- a/guava/src/com/google/common/util/concurrent/CycleDetectingLockFactory.java +++ b/guava/src/com/google/common/util/concurrent/CycleDetectingLockFactory.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Lists.newArrayListWithCapacity; +import static com.google.common.collect.Sets.newIdentityHashSet; import static java.util.Collections.unmodifiableMap; import static java.util.Objects.requireNonNull; @@ -25,10 +26,8 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; import com.google.common.collect.MapMaker; import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import com.google.j2objc.annotations.Weak; import java.util.ArrayList; import java.util.Arrays; @@ -304,7 +303,7 @@ static > Map createNodes(Class clazz) { EnumMap map = Maps.newEnumMap(clazz); E[] keys = clazz.getEnumConstants(); int numKeys = keys.length; - ArrayList nodes = Lists.newArrayListWithCapacity(numKeys); + ArrayList nodes = newArrayListWithCapacity(numKeys); // Create a LockGraphNode for each enum value. for (E key : keys) { LockGraphNode node = new LockGraphNode(getLockName(key)); @@ -652,7 +651,7 @@ void checkAcquiredLock(Policy policy, LockGraphNode acquiredLock) { } // Otherwise, it's the first time seeing this lock relationship. Look for // a path from the acquiredLock to this. - Set seen = Sets.newIdentityHashSet(); + Set seen = newIdentityHashSet(); ExampleStackTrace path = acquiredLock.findPathTo(this, seen); if (path == null) { diff --git a/guava/src/com/google/common/util/concurrent/MoreExecutors.java b/guava/src/com/google/common/util/concurrent/MoreExecutors.java index 22a53c402363..37284987878a 100644 --- a/guava/src/com/google/common/util/concurrent/MoreExecutors.java +++ b/guava/src/com/google/common/util/concurrent/MoreExecutors.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Lists.newArrayListWithCapacity; import static com.google.common.util.concurrent.Callables.threadRenaming; import static com.google.common.util.concurrent.Internal.toNanosSaturated; import static com.google.common.util.concurrent.SneakyThrows.sneakyThrow; @@ -31,7 +32,6 @@ import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Supplier; -import com.google.common.collect.Lists; import com.google.common.collect.Queues; import com.google.common.util.concurrent.ForwardingListenableFuture.SimpleForwardingListenableFuture; import com.google.errorprone.annotations.CanIgnoreReturnValue; @@ -719,7 +719,7 @@ protected String pendingToString() { checkNotNull(unit); int ntasks = tasks.size(); checkArgument(ntasks > 0); - List> futures = Lists.newArrayListWithCapacity(ntasks); + List> futures = newArrayListWithCapacity(ntasks); BlockingQueue> futureQueue = Queues.newLinkedBlockingQueue(); long timeoutNanos = unit.toNanos(timeout); diff --git a/guava/src/com/google/common/util/concurrent/RateLimiter.java b/guava/src/com/google/common/util/concurrent/RateLimiter.java index 9c719a8a4145..981238746d3c 100644 --- a/guava/src/com/google/common/util/concurrent/RateLimiter.java +++ b/guava/src/com/google/common/util/concurrent/RateLimiter.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.util.concurrent.Internal.toNanosSaturated; +import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly; import static java.lang.Math.max; import static java.util.concurrent.TimeUnit.MICROSECONDS; import static java.util.concurrent.TimeUnit.NANOSECONDS; @@ -484,7 +485,7 @@ protected long readMicros() { @Override protected void sleepMicrosUninterruptibly(long micros) { if (micros > 0) { - Uninterruptibles.sleepUninterruptibly(micros, MICROSECONDS); + sleepUninterruptibly(micros, MICROSECONDS); } } }; diff --git a/guava/src/com/google/common/util/concurrent/ServiceManager.java b/guava/src/com/google/common/util/concurrent/ServiceManager.java index 2568f0171ce3..348762c2a69a 100644 --- a/guava/src/com/google/common/util/concurrent/ServiceManager.java +++ b/guava/src/com/google/common/util/concurrent/ServiceManager.java @@ -21,6 +21,7 @@ import static com.google.common.base.Predicates.in; import static com.google.common.base.Predicates.instanceOf; import static com.google.common.base.Predicates.not; +import static com.google.common.collect.Lists.newArrayListWithCapacity; import static com.google.common.collect.Maps.immutableEntry; import static com.google.common.collect.Multimaps.filterKeys; import static com.google.common.util.concurrent.Internal.toNanosSaturated; @@ -45,7 +46,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSetMultimap; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.MultimapBuilder; import com.google.common.collect.Multiset; @@ -644,7 +644,7 @@ ImmutableMap startupTimes() { List> loadTimes; monitor.enter(); try { - loadTimes = Lists.newArrayListWithCapacity(startupTimers.size()); + loadTimes = newArrayListWithCapacity(startupTimers.size()); // N.B. There will only be an entry in the map if the service has started for (Entry entry : startupTimers.entrySet()) { Service service = entry.getKey();