Skip to content

Commit 89ca0ef

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
Use some static imports.
RELNOTES=n/a PiperOrigin-RevId: 687471414
1 parent 8bbbefd commit 89ca0ef

File tree

62 files changed

+216
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+216
-172
lines changed

android/guava-testlib/src/com/google/common/testing/ArbitraryInstances.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.common.base.Preconditions.checkArgument;
2020
import static java.nio.charset.StandardCharsets.UTF_8;
2121
import static java.util.Objects.requireNonNull;
22+
import static java.util.concurrent.TimeUnit.SECONDS;
2223

2324
import com.google.common.annotations.GwtIncompatible;
2425
import com.google.common.annotations.J2ktIncompatible;
@@ -205,7 +206,7 @@ private static MatchResult createMatchResult() {
205206
.put(String.class, "")
206207
.put(Pattern.class, Pattern.compile(""))
207208
.put(MatchResult.class, createMatchResult())
208-
.put(TimeUnit.class, TimeUnit.SECONDS)
209+
.put(TimeUnit.class, SECONDS)
209210
.put(Charset.class, UTF_8)
210211
.put(Currency.class, Currency.getInstance(Locale.US))
211212
.put(Locale.class, Locale.US)

android/guava-testlib/src/com/google/common/testing/FakeTicker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.common.testing;
1818

1919
import static com.google.common.base.Preconditions.checkArgument;
20+
import static java.util.concurrent.TimeUnit.NANOSECONDS;
2021

2122
import com.google.common.annotations.Beta;
2223
import com.google.common.annotations.GwtCompatible;
@@ -107,7 +108,7 @@ public FakeTicker setAutoIncrementStep(long autoIncrementStep, TimeUnit timeUnit
107108
@IgnoreJRERequirement // TODO: b/288085449 - Remove this once we use library-desugaring scents.
108109
@Beta // TODO: b/288085449 - Remove @Beta after we're sure that Java 8 APIs are safe for Android
109110
public FakeTicker setAutoIncrementStep(Duration autoIncrementStep) {
110-
return setAutoIncrementStep(autoIncrementStep.toNanos(), TimeUnit.NANOSECONDS);
111+
return setAutoIncrementStep(autoIncrementStep.toNanos(), NANOSECONDS);
111112
}
112113

113114
@Override

android/guava-testlib/src/com/google/common/testing/GcFinalization.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.common.testing;
1818

19+
import static java.lang.Math.max;
1920
import static java.util.concurrent.TimeUnit.SECONDS;
2021

2122
import com.google.common.annotations.GwtIncompatible;
@@ -126,7 +127,7 @@ private static long timeoutSeconds() {
126127
//
127128
// TODO(user): Consider scaling by number of mutator threads,
128129
// e.g. using Thread#activeCount()
129-
return Math.max(10L, Runtime.getRuntime().totalMemory() / (32L * 1024L * 1024L));
130+
return max(10L, Runtime.getRuntime().totalMemory() / (32L * 1024L * 1024L));
130131
}
131132

132133
/**

android/guava-testlib/test/com/google/common/testing/ArbitraryInstancesTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static com.google.common.truth.Truth.assertThat;
2020
import static java.nio.charset.StandardCharsets.UTF_8;
21+
import static java.util.concurrent.TimeUnit.SECONDS;
2122
import static org.junit.Assert.assertThrows;
2223

2324
import com.google.common.base.CharMatcher;
@@ -162,7 +163,7 @@ public void testGet_primitives() {
162163
assertEquals(0, ArbitraryInstances.get(BigInteger.class).intValue());
163164
assertEquals("", ArbitraryInstances.get(String.class));
164165
assertEquals("", ArbitraryInstances.get(CharSequence.class));
165-
assertEquals(TimeUnit.SECONDS, ArbitraryInstances.get(TimeUnit.class));
166+
assertEquals(SECONDS, ArbitraryInstances.get(TimeUnit.class));
166167
assertNotNull(ArbitraryInstances.get(Object.class));
167168
assertEquals(0, ArbitraryInstances.get(Number.class));
168169
assertEquals(UTF_8, ArbitraryInstances.get(Charset.class));

android/guava-testlib/test/com/google/common/testing/FakeTickerTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
package com.google.common.testing;
1818

1919
import static com.google.common.testing.ReflectionFreeAssertThrows.assertThrows;
20+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
21+
import static java.util.concurrent.TimeUnit.NANOSECONDS;
22+
import static java.util.concurrent.TimeUnit.SECONDS;
2023

2124
import com.google.common.annotations.GwtCompatible;
2225
import com.google.common.annotations.GwtIncompatible;
@@ -54,33 +57,33 @@ public void testAdvance() {
5457
assertEquals(0, ticker.read());
5558
assertSame(ticker, ticker.advance(10));
5659
assertEquals(10, ticker.read());
57-
ticker.advance(1, TimeUnit.MILLISECONDS);
60+
ticker.advance(1, MILLISECONDS);
5861
assertEquals(1000010L, ticker.read());
5962
ticker.advance(Duration.ofMillis(1));
6063
assertEquals(2000010L, ticker.read());
6164
}
6265

6366
public void testAutoIncrementStep_returnsSameInstance() {
6467
FakeTicker ticker = new FakeTicker();
65-
assertSame(ticker, ticker.setAutoIncrementStep(10, TimeUnit.NANOSECONDS));
68+
assertSame(ticker, ticker.setAutoIncrementStep(10, NANOSECONDS));
6669
}
6770

6871
public void testAutoIncrementStep_nanos() {
69-
FakeTicker ticker = new FakeTicker().setAutoIncrementStep(10, TimeUnit.NANOSECONDS);
72+
FakeTicker ticker = new FakeTicker().setAutoIncrementStep(10, NANOSECONDS);
7073
assertEquals(0, ticker.read());
7174
assertEquals(10, ticker.read());
7275
assertEquals(20, ticker.read());
7376
}
7477

7578
public void testAutoIncrementStep_millis() {
76-
FakeTicker ticker = new FakeTicker().setAutoIncrementStep(1, TimeUnit.MILLISECONDS);
79+
FakeTicker ticker = new FakeTicker().setAutoIncrementStep(1, MILLISECONDS);
7780
assertEquals(0, ticker.read());
7881
assertEquals(1000000, ticker.read());
7982
assertEquals(2000000, ticker.read());
8083
}
8184

8285
public void testAutoIncrementStep_seconds() {
83-
FakeTicker ticker = new FakeTicker().setAutoIncrementStep(3, TimeUnit.SECONDS);
86+
FakeTicker ticker = new FakeTicker().setAutoIncrementStep(3, SECONDS);
8487
assertEquals(0, ticker.read());
8588
assertEquals(3000000000L, ticker.read());
8689
assertEquals(6000000000L, ticker.read());
@@ -96,7 +99,7 @@ public void testAutoIncrementStep_duration() {
9699
}
97100

98101
public void testAutoIncrementStep_resetToZero() {
99-
FakeTicker ticker = new FakeTicker().setAutoIncrementStep(10, TimeUnit.NANOSECONDS);
102+
FakeTicker ticker = new FakeTicker().setAutoIncrementStep(10, NANOSECONDS);
100103
assertEquals(0, ticker.read());
101104
assertEquals(10, ticker.read());
102105
assertEquals(20, ticker.read());
@@ -113,8 +116,7 @@ public void testAutoIncrementStep_resetToZero() {
113116
public void testAutoIncrement_negative() {
114117
FakeTicker ticker = new FakeTicker();
115118
assertThrows(
116-
IllegalArgumentException.class,
117-
() -> ticker.setAutoIncrementStep(-1, TimeUnit.NANOSECONDS));
119+
IllegalArgumentException.class, () -> ticker.setAutoIncrementStep(-1, NANOSECONDS));
118120
}
119121

120122
@GwtIncompatible // concurrency
@@ -143,8 +145,7 @@ public void testConcurrentAdvance() throws Exception {
143145

144146
public void testConcurrentAutoIncrementStep() throws Exception {
145147
int incrementByNanos = 3;
146-
final FakeTicker ticker =
147-
new FakeTicker().setAutoIncrementStep(incrementByNanos, TimeUnit.NANOSECONDS);
148+
final FakeTicker ticker = new FakeTicker().setAutoIncrementStep(incrementByNanos, NANOSECONDS);
148149

149150
int numberOfThreads = 64;
150151
runConcurrentTest(

android/guava-tests/benchmark/com/google/common/base/StopwatchBenchmark.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616

1717
package com.google.common.base;
1818

19+
import static java.util.concurrent.TimeUnit.NANOSECONDS;
20+
1921
import com.google.caliper.Benchmark;
20-
import java.util.concurrent.TimeUnit;
2122

2223
/**
2324
* Simple benchmark: create, start, read. This does not currently report the most useful result
@@ -32,7 +33,7 @@ long stopwatch(int reps) {
3233
for (int i = 0; i < reps; i++) {
3334
Stopwatch s = Stopwatch.createStarted();
3435
// here is where you would do something
35-
total += s.elapsed(TimeUnit.NANOSECONDS);
36+
total += s.elapsed(NANOSECONDS);
3637
}
3738
return total;
3839
}

android/guava-tests/benchmark/com/google/common/hash/HashStringBenchmark.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616

1717
package com.google.common.hash;
1818

19+
import static java.nio.charset.StandardCharsets.UTF_8;
20+
1921
import com.google.caliper.BeforeExperiment;
2022
import com.google.caliper.Benchmark;
2123
import com.google.caliper.Param;
22-
import java.nio.charset.StandardCharsets;
2324
import java.util.Random;
2425

2526
/** Benchmarks for the hashing of UTF-8 strings. */
@@ -118,9 +119,7 @@ int hashUtf8(int reps) {
118119
for (int i = 0; i < reps; i++) {
119120
res +=
120121
System.identityHashCode(
121-
hashFunctionEnum
122-
.getHashFunction()
123-
.hashString(strings[i & SAMPLE_MASK], StandardCharsets.UTF_8));
122+
hashFunctionEnum.getHashFunction().hashString(strings[i & SAMPLE_MASK], UTF_8));
124123
}
125124
return res;
126125
}
@@ -134,7 +133,7 @@ int hashUtf8Hasher(int reps) {
134133
hashFunctionEnum
135134
.getHashFunction()
136135
.newHasher()
137-
.putString(strings[i & SAMPLE_MASK], StandardCharsets.UTF_8)
136+
.putString(strings[i & SAMPLE_MASK], UTF_8)
138137
.hash());
139138
}
140139
return res;
@@ -148,7 +147,7 @@ int hashUtf8GetBytes(int reps) {
148147
System.identityHashCode(
149148
hashFunctionEnum
150149
.getHashFunction()
151-
.hashBytes(strings[i & SAMPLE_MASK].getBytes(StandardCharsets.UTF_8)));
150+
.hashBytes(strings[i & SAMPLE_MASK].getBytes(UTF_8)));
152151
}
153152
return res;
154153
}
@@ -162,7 +161,7 @@ int hashUtf8GetBytesHasher(int reps) {
162161
hashFunctionEnum
163162
.getHashFunction()
164163
.newHasher()
165-
.putBytes(strings[i & SAMPLE_MASK].getBytes(StandardCharsets.UTF_8))
164+
.putBytes(strings[i & SAMPLE_MASK].getBytes(UTF_8))
166165
.hash());
167166
}
168167
return res;

android/guava-tests/test/com/google/common/base/FinalizableReferenceQueueClassLoaderUnloadingTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.common.base.StandardSystemProperty.JAVA_CLASS_PATH;
2020
import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION;
2121
import static com.google.common.base.StandardSystemProperty.PATH_SEPARATOR;
22+
import static java.util.concurrent.TimeUnit.SECONDS;
2223

2324
import com.google.common.collect.ImmutableList;
2425
import com.google.common.testing.GcFinalization;
@@ -35,7 +36,6 @@
3536
import java.security.ProtectionDomain;
3637
import java.util.concurrent.Callable;
3738
import java.util.concurrent.Semaphore;
38-
import java.util.concurrent.TimeUnit;
3939
import java.util.concurrent.atomic.AtomicReference;
4040
import junit.framework.TestCase;
4141

@@ -249,7 +249,7 @@ private WeakReference<ClassLoader> doTestUnloadableInStaticFieldIfClosed() throw
249249

250250
Field sepFrqUserFinalizedF = sepFrqUserC.getField("finalized");
251251
Semaphore finalizeCount = (Semaphore) sepFrqUserFinalizedF.get(null);
252-
boolean finalized = finalizeCount.tryAcquire(5, TimeUnit.SECONDS);
252+
boolean finalized = finalizeCount.tryAcquire(5, SECONDS);
253253
assertTrue(finalized);
254254

255255
Field sepFrqUserFrqF = sepFrqUserC.getField("frq");

android/guava-tests/test/com/google/common/base/SuppliersTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import static com.google.common.base.ReflectionFreeAssertThrows.assertThrows;
2020
import static com.google.common.testing.SerializableTester.reserialize;
2121
import static com.google.common.truth.Truth.assertThat;
22+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
23+
import static java.util.concurrent.TimeUnit.NANOSECONDS;
24+
import static java.util.concurrent.TimeUnit.SECONDS;
2225

2326
import com.google.common.annotations.GwtCompatible;
2427
import com.google.common.annotations.GwtIncompatible;
@@ -31,7 +34,6 @@
3134
import java.time.Duration;
3235
import java.util.ArrayList;
3336
import java.util.List;
34-
import java.util.concurrent.TimeUnit;
3537
import java.util.concurrent.TimeoutException;
3638
import java.util.concurrent.atomic.AtomicInteger;
3739
import java.util.concurrent.atomic.AtomicReference;
@@ -224,7 +226,7 @@ public void testMemoizeWithExpiration_longTimeUnit() throws InterruptedException
224226
CountingSupplier countingSupplier = new CountingSupplier();
225227

226228
Supplier<Integer> memoizedSupplier =
227-
Suppliers.memoizeWithExpiration(countingSupplier, 75, TimeUnit.MILLISECONDS);
229+
Suppliers.memoizeWithExpiration(countingSupplier, 75, MILLISECONDS);
228230

229231
checkExpiration(countingSupplier, memoizedSupplier);
230232
}
@@ -244,11 +246,11 @@ public void testMemoizeWithExpiration_duration() throws InterruptedException {
244246
public void testMemoizeWithExpiration_longTimeUnitNegative() throws InterruptedException {
245247
assertThrows(
246248
IllegalArgumentException.class,
247-
() -> Suppliers.memoizeWithExpiration(() -> "", 0, TimeUnit.MILLISECONDS));
249+
() -> Suppliers.memoizeWithExpiration(() -> "", 0, MILLISECONDS));
248250

249251
assertThrows(
250252
IllegalArgumentException.class,
251-
() -> Suppliers.memoizeWithExpiration(() -> "", -1, TimeUnit.MILLISECONDS));
253+
() -> Suppliers.memoizeWithExpiration(() -> "", -1, MILLISECONDS));
252254
}
253255

254256
@J2ktIncompatible // Duration
@@ -270,7 +272,7 @@ public void testMemoizeWithExpirationSerialized() throws InterruptedException {
270272
SerializableCountingSupplier countingSupplier = new SerializableCountingSupplier();
271273

272274
Supplier<Integer> memoizedSupplier =
273-
Suppliers.memoizeWithExpiration(countingSupplier, 75, TimeUnit.MILLISECONDS);
275+
Suppliers.memoizeWithExpiration(countingSupplier, 75, MILLISECONDS);
274276
// Calls to the original memoized supplier shouldn't affect its copy.
275277
Object unused = memoizedSupplier.get();
276278

@@ -329,7 +331,7 @@ public void testExpiringMemoizedSupplierThreadSafe() throws Throwable {
329331
new Function<Supplier<Boolean>, Supplier<Boolean>>() {
330332
@Override
331333
public Supplier<Boolean> apply(Supplier<Boolean> supplier) {
332-
return Suppliers.memoizeWithExpiration(supplier, Long.MAX_VALUE, TimeUnit.NANOSECONDS);
334+
return Suppliers.memoizeWithExpiration(supplier, Long.MAX_VALUE, NANOSECONDS);
333335
}
334336
};
335337
testSupplierThreadSafe(memoizer);
@@ -356,7 +358,7 @@ private void testSupplierThreadSafe(Function<Supplier<Boolean>, Supplier<Boolean
356358
final AtomicReference<Throwable> thrown = new AtomicReference<>(null);
357359
final int numThreads = 3;
358360
final Thread[] threads = new Thread[numThreads];
359-
final long timeout = TimeUnit.SECONDS.toNanos(60);
361+
final long timeout = SECONDS.toNanos(60);
360362

361363
final Supplier<Boolean> supplier =
362364
new Supplier<Boolean>() {
@@ -485,8 +487,7 @@ public void testSerialization() {
485487
assertEquals(Integer.valueOf(5), reserialize(Suppliers.memoize(Suppliers.ofInstance(5))).get());
486488
assertEquals(
487489
Integer.valueOf(5),
488-
reserialize(Suppliers.memoizeWithExpiration(Suppliers.ofInstance(5), 30, TimeUnit.SECONDS))
489-
.get());
490+
reserialize(Suppliers.memoizeWithExpiration(Suppliers.ofInstance(5), 30, SECONDS)).get());
490491
assertEquals(
491492
Integer.valueOf(5),
492493
reserialize(Suppliers.synchronizedSupplier(Suppliers.ofInstance(5))).get());

android/guava-tests/test/com/google/common/hash/BloomFilterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static com.google.common.truth.Truth.assertThat;
2020
import static java.nio.charset.StandardCharsets.UTF_8;
21+
import static java.util.concurrent.TimeUnit.SECONDS;
2122
import static org.junit.Assert.assertThrows;
2223

2324
import com.google.common.base.Stopwatch;
@@ -36,7 +37,6 @@
3637
import java.util.ArrayList;
3738
import java.util.List;
3839
import java.util.Random;
39-
import java.util.concurrent.TimeUnit;
4040
import junit.framework.TestCase;
4141
import org.checkerframework.checker.nullness.qual.Nullable;
4242

@@ -557,7 +557,7 @@ public void run() {
557557
// Don't forget, the bloom filter slowly saturates over time and the
558558
// expected false positive probability goes up!
559559
assertThat(bloomFilter.expectedFpp()).isLessThan(safetyFalsePositiveRate);
560-
} while (stopwatch.elapsed(TimeUnit.SECONDS) < 1);
560+
} while (stopwatch.elapsed(SECONDS) < 1);
561561
}
562562
};
563563

0 commit comments

Comments
 (0)