diff --git a/android/guava-tests/benchmark/com/google/common/primitives/UnsignedLongsBenchmark.java b/android/guava-tests/benchmark/com/google/common/primitives/UnsignedLongsBenchmark.java index cf5d3744cf6a..d7531ee71875 100644 --- a/android/guava-tests/benchmark/com/google/common/primitives/UnsignedLongsBenchmark.java +++ b/android/guava-tests/benchmark/com/google/common/primitives/UnsignedLongsBenchmark.java @@ -30,7 +30,7 @@ public class UnsignedLongsBenchmark { private static final int ARRAY_SIZE = 0x10000; private static final int ARRAY_MASK = 0x0ffff; - private static final Random RANDOM_SOURCE = new Random(314159265358979L); + private static final Random randomSource = new Random(314159265358979L); private static final long[] longs = new long[ARRAY_SIZE]; private static final long[] divisors = new long[ARRAY_SIZE]; private static final String[] decimalStrings = new String[ARRAY_SIZE]; @@ -122,7 +122,7 @@ int toString(int reps) { } private static long random() { - return RANDOM_SOURCE.nextLong(); + return randomSource.nextLong(); } // A random value that cannot be 0 and that is unsigned-less-than or equal @@ -131,7 +131,7 @@ private static long random() { // Using remainder here does not give us a uniform distribution but it should // not have a big impact on the measurement. private static long randomDivisor(long dividend) { - long r = RANDOM_SOURCE.nextLong(); + long r = randomSource.nextLong(); if (dividend == -1) { return r; } else { diff --git a/android/guava-tests/test/com/google/common/base/JoinerTest.java b/android/guava-tests/test/com/google/common/base/JoinerTest.java index aea2ab5b1c4e..cdb4206dea25 100644 --- a/android/guava-tests/test/com/google/common/base/JoinerTest.java +++ b/android/guava-tests/test/com/google/common/base/JoinerTest.java @@ -50,17 +50,17 @@ public class JoinerTest extends TestCase { private static final Joiner J = Joiner.on("-"); // needed to prevent warning :( - private static final Iterable ITERABLE_ = Arrays.asList(); - private static final Iterable ITERABLE_1 = Arrays.asList(1); - private static final Iterable ITERABLE_12 = Arrays.asList(1, 2); - private static final Iterable ITERABLE_123 = Arrays.asList(1, 2, 3); - private static final Iterable<@Nullable Integer> ITERABLE_NULL = Arrays.asList((Integer) null); - private static final Iterable<@Nullable Integer> ITERABLE_NULL_NULL = + private static final Iterable iterable = Arrays.asList(); + private static final Iterable iterable1 = Arrays.asList(1); + private static final Iterable iterable12 = Arrays.asList(1, 2); + private static final Iterable iterable123 = Arrays.asList(1, 2, 3); + private static final Iterable<@Nullable Integer> iterableNull = Arrays.asList((Integer) null); + private static final Iterable<@Nullable Integer> iterableNullNull = Arrays.asList((Integer) null, null); - private static final Iterable<@Nullable Integer> ITERABLE_NULL_1 = Arrays.asList(null, 1); - private static final Iterable<@Nullable Integer> ITERABLE_1_NULL = Arrays.asList(1, null); - private static final Iterable<@Nullable Integer> ITERABLE_1_NULL_2 = Arrays.asList(1, null, 2); - private static final Iterable<@Nullable Integer> ITERABLE_FOUR_NULLS = + private static final Iterable<@Nullable Integer> iterableNull1 = Arrays.asList(null, 1); + private static final Iterable<@Nullable Integer> iterable1Null = Arrays.asList(1, null); + private static final Iterable<@Nullable Integer> iterable1Null2 = Arrays.asList(1, null, 2); + private static final Iterable<@Nullable Integer> iterableFourNulls = Arrays.asList((Integer) null, null, null, null); /* @@ -107,60 +107,60 @@ public int size() { @SuppressWarnings("JoinIterableIterator") // explicitly testing iterator overload, too public void testNoSpecialNullBehavior() { - checkNoOutput(J, ITERABLE_); - checkResult(J, ITERABLE_1, "1"); - checkResult(J, ITERABLE_12, "1-2"); - checkResult(J, ITERABLE_123, "1-2-3"); + checkNoOutput(J, iterable); + checkResult(J, iterable1, "1"); + checkResult(J, iterable12, "1-2"); + checkResult(J, iterable123, "1-2-3"); checkResult(J, UNDERREPORTING_SIZE_LIST, "1-2-3"); checkResult(J, OVERREPORTING_SIZE_LIST, "1-2-3"); - assertThrows(NullPointerException.class, () -> J.join(ITERABLE_NULL)); - assertThrows(NullPointerException.class, () -> J.join(ITERABLE_1_NULL_2)); + assertThrows(NullPointerException.class, () -> J.join(iterableNull)); + assertThrows(NullPointerException.class, () -> J.join(iterable1Null2)); - assertThrows(NullPointerException.class, () -> J.join(ITERABLE_NULL.iterator())); - assertThrows(NullPointerException.class, () -> J.join(ITERABLE_1_NULL_2.iterator())); + assertThrows(NullPointerException.class, () -> J.join(iterableNull.iterator())); + assertThrows(NullPointerException.class, () -> J.join(iterable1Null2.iterator())); } public void testOnCharOverride() { Joiner onChar = Joiner.on('-'); - checkNoOutput(onChar, ITERABLE_); - checkResult(onChar, ITERABLE_1, "1"); - checkResult(onChar, ITERABLE_12, "1-2"); - checkResult(onChar, ITERABLE_123, "1-2-3"); + checkNoOutput(onChar, iterable); + checkResult(onChar, iterable1, "1"); + checkResult(onChar, iterable12, "1-2"); + checkResult(onChar, iterable123, "1-2-3"); checkResult(J, UNDERREPORTING_SIZE_LIST, "1-2-3"); checkResult(J, OVERREPORTING_SIZE_LIST, "1-2-3"); } public void testSkipNulls() { Joiner skipNulls = J.skipNulls(); - checkNoOutput(skipNulls, ITERABLE_); - checkNoOutput(skipNulls, ITERABLE_NULL); - checkNoOutput(skipNulls, ITERABLE_NULL_NULL); - checkNoOutput(skipNulls, ITERABLE_FOUR_NULLS); - checkResult(skipNulls, ITERABLE_1, "1"); - checkResult(skipNulls, ITERABLE_12, "1-2"); - checkResult(skipNulls, ITERABLE_123, "1-2-3"); + checkNoOutput(skipNulls, iterable); + checkNoOutput(skipNulls, iterableNull); + checkNoOutput(skipNulls, iterableNullNull); + checkNoOutput(skipNulls, iterableFourNulls); + checkResult(skipNulls, iterable1, "1"); + checkResult(skipNulls, iterable12, "1-2"); + checkResult(skipNulls, iterable123, "1-2-3"); checkResult(J, UNDERREPORTING_SIZE_LIST, "1-2-3"); checkResult(J, OVERREPORTING_SIZE_LIST, "1-2-3"); - checkResult(skipNulls, ITERABLE_NULL_1, "1"); - checkResult(skipNulls, ITERABLE_1_NULL, "1"); - checkResult(skipNulls, ITERABLE_1_NULL_2, "1-2"); + checkResult(skipNulls, iterableNull1, "1"); + checkResult(skipNulls, iterable1Null, "1"); + checkResult(skipNulls, iterable1Null2, "1-2"); } public void testUseForNull() { Joiner zeroForNull = J.useForNull("0"); - checkNoOutput(zeroForNull, ITERABLE_); - checkResult(zeroForNull, ITERABLE_1, "1"); - checkResult(zeroForNull, ITERABLE_12, "1-2"); - checkResult(zeroForNull, ITERABLE_123, "1-2-3"); + checkNoOutput(zeroForNull, iterable); + checkResult(zeroForNull, iterable1, "1"); + checkResult(zeroForNull, iterable12, "1-2"); + checkResult(zeroForNull, iterable123, "1-2-3"); checkResult(J, UNDERREPORTING_SIZE_LIST, "1-2-3"); checkResult(J, OVERREPORTING_SIZE_LIST, "1-2-3"); - checkResult(zeroForNull, ITERABLE_NULL, "0"); - checkResult(zeroForNull, ITERABLE_NULL_NULL, "0-0"); - checkResult(zeroForNull, ITERABLE_NULL_1, "0-1"); - checkResult(zeroForNull, ITERABLE_1_NULL, "1-0"); - checkResult(zeroForNull, ITERABLE_1_NULL_2, "1-0-2"); - checkResult(zeroForNull, ITERABLE_FOUR_NULLS, "0-0-0-0"); + checkResult(zeroForNull, iterableNull, "0"); + checkResult(zeroForNull, iterableNullNull, "0-0"); + checkResult(zeroForNull, iterableNull1, "0-1"); + checkResult(zeroForNull, iterable1Null, "1-0"); + checkResult(zeroForNull, iterable1Null2, "1-0-2"); + checkResult(zeroForNull, iterableFourNulls, "0-0-0-0"); } private static void checkNoOutput(Joiner joiner, Iterable set) { diff --git a/android/guava-tests/test/com/google/common/base/PreconditionsTest.java b/android/guava-tests/test/com/google/common/base/PreconditionsTest.java index 5716598053f0..7e8d8bb55dbd 100644 --- a/android/guava-tests/test/com/google/common/base/PreconditionsTest.java +++ b/android/guava-tests/test/com/google/common/base/PreconditionsTest.java @@ -392,7 +392,7 @@ private Object[] getParametersForSignature( return params; } - private static final ImmutableList> possibleParamTypes = + private static final ImmutableList> POSSIBLE_PARAM_TYPES = ImmutableList.of(char.class, int.class, long.class, Object.class); /** @@ -410,7 +410,7 @@ private static ImmutableList>> allSignatures(Class pre List>> typesLists = new ArrayList<>(); for (int i = 0; i < 2; i++) { - typesLists.add(possibleParamTypes); + typesLists.add(POSSIBLE_PARAM_TYPES); for (List> curr : Lists.cartesianProduct(typesLists)) { allOverloads.add( ImmutableList.>builder() diff --git a/android/guava-tests/test/com/google/common/collect/AbstractImmutableSortedMapMapInterfaceTest.java b/android/guava-tests/test/com/google/common/collect/AbstractImmutableSortedMapMapInterfaceTest.java index 73ac6f385761..30110ad5719e 100644 --- a/android/guava-tests/test/com/google/common/collect/AbstractImmutableSortedMapMapInterfaceTest.java +++ b/android/guava-tests/test/com/google/common/collect/AbstractImmutableSortedMapMapInterfaceTest.java @@ -39,7 +39,7 @@ protected SortedMap makeEmptyMap() { throw new UnsupportedOperationException(); } - private static final Joiner joiner = Joiner.on(", "); + private static final Joiner JOINER = Joiner.on(", "); @Override protected void assertMoreInvariants(Map map) { @@ -48,10 +48,10 @@ protected void assertMoreInvariants(Map map) { assertEquals(entry.getKey() + "=" + entry.getValue(), entry.toString()); } - assertEquals("{" + joiner.join(map.entrySet()) + "}", map.toString()); - assertEquals("[" + joiner.join(map.entrySet()) + "]", map.entrySet().toString()); - assertEquals("[" + joiner.join(map.keySet()) + "]", map.keySet().toString()); - assertEquals("[" + joiner.join(map.values()) + "]", map.values().toString()); + assertEquals("{" + JOINER.join(map.entrySet()) + "}", map.toString()); + assertEquals("[" + JOINER.join(map.entrySet()) + "]", map.entrySet().toString()); + assertEquals("[" + JOINER.join(map.keySet()) + "]", map.keySet().toString()); + assertEquals("[" + JOINER.join(map.values()) + "]", map.values().toString()); assertEquals(newHashSet(map.entrySet()), map.entrySet()); assertEquals(newHashSet(map.keySet()), map.keySet()); diff --git a/android/guava-tests/test/com/google/common/collect/GeneralRangeTest.java b/android/guava-tests/test/com/google/common/collect/GeneralRangeTest.java index 91852de9f9bd..214513297506 100644 --- a/android/guava-tests/test/com/google/common/collect/GeneralRangeTest.java +++ b/android/guava-tests/test/com/google/common/collect/GeneralRangeTest.java @@ -17,13 +17,14 @@ import static com.google.common.collect.BoundType.CLOSED; import static com.google.common.collect.BoundType.OPEN; import static com.google.common.collect.ReflectionFreeAssertThrows.assertThrows; -import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Objects; import com.google.common.testing.NullPointerTester; +import java.util.Arrays; import java.util.List; import junit.framework.TestCase; import org.jspecify.annotations.NullMarked; @@ -40,7 +41,8 @@ public class GeneralRangeTest extends TestCase { private static final Ordering<@Nullable Integer> ORDERING = Ordering.natural().nullsFirst(); - private static final List<@Nullable Integer> IN_ORDER_VALUES = asList(null, 1, 2, 3, 4, 5); + private static final List<@Nullable Integer> IN_ORDER_VALUES = + unmodifiableList(Arrays.<@Nullable Integer>asList(null, 1, 2, 3, 4, 5)); public void testCreateEmptyRangeFails() { for (BoundType lboundType : BoundType.values()) { diff --git a/android/guava-tests/test/com/google/common/graph/PackageSanityTests.java b/android/guava-tests/test/com/google/common/graph/PackageSanityTests.java index 8b241a2ab123..2ddcbc1d5d8d 100644 --- a/android/guava-tests/test/com/google/common/graph/PackageSanityTests.java +++ b/android/guava-tests/test/com/google/common/graph/PackageSanityTests.java @@ -31,9 +31,9 @@ @NullUnmarked public class PackageSanityTests extends AbstractPackageSanityTests { - private static final AbstractGraphBuilder GRAPH_BUILDER_A = + private static final AbstractGraphBuilder graphBuilderA = GraphBuilder.directed().expectedNodeCount(10); - private static final AbstractGraphBuilder GRAPH_BUILDER_B = + private static final AbstractGraphBuilder graphBuilderB = ValueGraphBuilder.directed().allowsSelfLoops(true).expectedNodeCount(16); private static final ImmutableGraph IMMUTABLE_GRAPH_A = @@ -41,9 +41,9 @@ public class PackageSanityTests extends AbstractPackageSanityTests { private static final ImmutableGraph IMMUTABLE_GRAPH_B = GraphBuilder.directed().immutable().addNode("B").build(); - private static final NetworkBuilder NETWORK_BUILDER_A = + private static final NetworkBuilder networkBuilderA = NetworkBuilder.directed().allowsParallelEdges(true).expectedNodeCount(10); - private static final NetworkBuilder NETWORK_BUILDER_B = + private static final NetworkBuilder networkBuilderB = NetworkBuilder.directed().allowsSelfLoops(true).expectedNodeCount(16); private static final ImmutableNetwork IMMUTABLE_NETWORK_A = @@ -57,10 +57,10 @@ public PackageSanityTests() { MutableNetwork mutableNetworkB = NetworkBuilder.directed().build(); mutableNetworkB.addNode("b"); - setDistinctValues(AbstractGraphBuilder.class, GRAPH_BUILDER_A, GRAPH_BUILDER_B); + setDistinctValues(AbstractGraphBuilder.class, graphBuilderA, graphBuilderB); setDistinctValues(Graph.class, IMMUTABLE_GRAPH_A, IMMUTABLE_GRAPH_B); setDistinctValues(MutableNetwork.class, mutableNetworkA, mutableNetworkB); - setDistinctValues(NetworkBuilder.class, NETWORK_BUILDER_A, NETWORK_BUILDER_B); + setDistinctValues(NetworkBuilder.class, networkBuilderA, networkBuilderB); setDistinctValues(Network.class, IMMUTABLE_NETWORK_A, IMMUTABLE_NETWORK_B); setDefault(EndpointPair.class, EndpointPair.ordered("A", "B")); } diff --git a/android/guava-tests/test/com/google/common/hash/Crc32cHashFunctionTest.java b/android/guava-tests/test/com/google/common/hash/Crc32cHashFunctionTest.java index 03a0cf1490cf..2d63f46b20ca 100644 --- a/android/guava-tests/test/com/google/common/hash/Crc32cHashFunctionTest.java +++ b/android/guava-tests/test/com/google/common/hash/Crc32cHashFunctionTest.java @@ -126,7 +126,7 @@ public void testAgainstSimplerImplementation() { private static int referenceCrc(byte[] bytes) { int crc = ~0; for (byte b : bytes) { - crc = (crc >>> 8) ^ Crc32cHashFunction.Crc32cHasher.BYTE_TABLE[(crc ^ b) & 0xFF]; + crc = (crc >>> 8) ^ Crc32cHashFunction.Crc32cHasher.byteTable[(crc ^ b) & 0xFF]; } return ~crc; } @@ -169,7 +169,7 @@ public void testCrc32cByteTable() { expected[i] = crc; } - int[] actual = Crc32cHashFunction.Crc32cHasher.BYTE_TABLE; + int[] actual = Crc32cHashFunction.Crc32cHasher.byteTable; assertTrue( "Expected: \n" + Arrays.toString(expected) + "\nActual:\n" + Arrays.toString(actual), Arrays.equals(expected, actual)); @@ -186,7 +186,7 @@ static int advanceOneBit(int next) { public void testCrc32cStrideTable() { int next = CRC32C_GENERATOR_FLIPPED; for (int i = 0; i < 12; i++) { // for 3 ints = 12 bytes in between each stride window - next = (next >>> 8) ^ Crc32cHashFunction.Crc32cHasher.BYTE_TABLE[next & 0xFF]; + next = (next >>> 8) ^ Crc32cHashFunction.Crc32cHasher.byteTable[next & 0xFF]; } int[][] expected = new int[4][256]; for (int b = 0; b < 4; ++b) { @@ -204,7 +204,7 @@ public void testCrc32cStrideTable() { } } - int[][] actual = Crc32cHashFunction.Crc32cHasher.STRIDE_TABLE; + int[][] actual = Crc32cHashFunction.Crc32cHasher.strideTable; assertTrue( "Expected: \n" + Arrays.deepToString(expected) diff --git a/android/guava-tests/test/com/google/common/io/LineBufferTest.java b/android/guava-tests/test/com/google/common/io/LineBufferTest.java index eea7686917d6..cc1ba24095ae 100644 --- a/android/guava-tests/test/com/google/common/io/LineBufferTest.java +++ b/android/guava-tests/test/com/google/common/io/LineBufferTest.java @@ -20,6 +20,7 @@ import static java.lang.Math.min; import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import java.io.BufferedReader; import java.io.FilterReader; @@ -58,7 +59,8 @@ public void testProcess() throws IOException { bufferHelper("mixed\nline\rendings\r\n", "mixed\n", "line\r", "endings\r\n"); } - private static final int[] CHUNK_SIZES = {1, 2, 3, Integer.MAX_VALUE}; + private static final ImmutableSet CHUNK_SIZES = + ImmutableSet.of(1, 2, 3, Integer.MAX_VALUE); private static void bufferHelper(String input, String... expect) throws IOException { 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 48e72054023f..27f9f481e1b4 100644 --- a/android/guava-tests/test/com/google/common/math/DoubleMathTest.java +++ b/android/guava-tests/test/com/google/common/math/DoubleMathTest.java @@ -51,7 +51,6 @@ import java.math.BigInteger; import java.math.RoundingMode; import java.util.Arrays; -import java.util.List; import junit.framework.TestCase; import org.jspecify.annotations.NullUnmarked; @@ -512,17 +511,20 @@ public void testFactorialNegative() { ImmutableList.of(-0.0, 0.0, 1.0, 100.0, 10000.0, Double.MAX_VALUE); private static final Iterable TOLERANCE_CANDIDATES = - Iterables.concat(FINITE_TOLERANCE_CANDIDATES, ImmutableList.of(Double.POSITIVE_INFINITY)); - - private static final List BAD_TOLERANCE_CANDIDATES = - Doubles.asList( - -Double.MIN_VALUE, - -Double.MIN_NORMAL, - -1, - -20, - Double.NaN, - Double.NEGATIVE_INFINITY, - -0.001); + ImmutableList.copyOf( + Iterables.concat( + FINITE_TOLERANCE_CANDIDATES, ImmutableList.of(Double.POSITIVE_INFINITY))); + + private static final ImmutableList BAD_TOLERANCE_CANDIDATES = + ImmutableList.copyOf( + Doubles.asList( + -Double.MIN_VALUE, + -Double.MIN_NORMAL, + -1, + -20, + Double.NaN, + Double.NEGATIVE_INFINITY, + -0.001)); public void testFuzzyEqualsFinite() { for (double a : FINITE_DOUBLE_CANDIDATES) { diff --git a/android/guava-tests/test/com/google/common/math/QuantilesAlgorithmTest.java b/android/guava-tests/test/com/google/common/math/QuantilesAlgorithmTest.java index cd4179dd3a89..6a913ace1e68 100644 --- a/android/guava-tests/test/com/google/common/math/QuantilesAlgorithmTest.java +++ b/android/guava-tests/test/com/google/common/math/QuantilesAlgorithmTest.java @@ -23,7 +23,6 @@ import com.google.common.collect.Sets; import java.util.Map; import java.util.Random; -import java.util.Set; import junit.framework.TestCase; import org.jspecify.annotations.NullUnmarked; @@ -34,13 +33,15 @@ @NullUnmarked public class QuantilesAlgorithmTest extends TestCase { - private static final Random RNG = new Random(82674067L); + private static final Random rng = new Random(82674067L); private static final int DATASET_SIZE = 1000; private static final double ALLOWED_ERROR = 1.0e-10; private static final QuantilesAlgorithm REFERENCE_ALGORITHM = QuantilesAlgorithm.SORTING; - private static final Set NON_REFERENCE_ALGORITHMS = + private static final ImmutableSet NON_REFERENCE_ALGORITHMS = Sets.difference( - ImmutableSet.copyOf(QuantilesAlgorithm.values()), ImmutableSet.of(REFERENCE_ALGORITHM)); + ImmutableSet.copyOf(QuantilesAlgorithm.values()), + ImmutableSet.of(REFERENCE_ALGORITHM)) + .immutableCopy(); private double[] dataset; @@ -48,7 +49,7 @@ public class QuantilesAlgorithmTest extends TestCase { protected void setUp() { dataset = new double[DATASET_SIZE]; for (int i = 0; i < DATASET_SIZE; i++) { - dataset[i] = RNG.nextDouble(); + dataset[i] = rng.nextDouble(); } } diff --git a/android/guava-tests/test/com/google/common/primitives/ImmutableDoubleArrayTest.java b/android/guava-tests/test/com/google/common/primitives/ImmutableDoubleArrayTest.java index 7cbb29d71fcc..a7ea0cfa968c 100644 --- a/android/guava-tests/test/com/google/common/primitives/ImmutableDoubleArrayTest.java +++ b/android/guava-tests/test/com/google/common/primitives/ImmutableDoubleArrayTest.java @@ -170,7 +170,7 @@ public void testBuilder_presize_negative() { */ public void testBuilder_bruteForce() { for (int i = 0; i < reduceIterationsIfGwt(100); i++) { - ImmutableDoubleArray.Builder builder = ImmutableDoubleArray.builder(RANDOM.nextInt(20)); + ImmutableDoubleArray.Builder builder = ImmutableDoubleArray.builder(random.nextInt(20)); AtomicInteger counter = new AtomicInteger(0); while (counter.get() < 1000) { BuilderOp op = BuilderOp.randomOp(); @@ -193,7 +193,7 @@ void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { ADD_ARRAY { @Override void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { - double[] array = new double[RANDOM.nextInt(10)]; + double[] array = new double[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -204,7 +204,7 @@ void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { @Override void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { List list = new ArrayList<>(); - double num = RANDOM.nextInt(10); + double num = random.nextInt(10); for (int i = 0; i < num; i++) { list.add((double) counter.getAndIncrement()); } @@ -215,7 +215,7 @@ void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { @Override void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { List list = new ArrayList<>(); - double num = RANDOM.nextInt(10); + double num = random.nextInt(10); for (int i = 0; i < num; i++) { list.add((double) counter.getAndIncrement()); } @@ -225,7 +225,7 @@ void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { ADD_STREAM { @Override void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { - double[] array = new double[RANDOM.nextInt(10)]; + double[] array = new double[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -235,7 +235,7 @@ void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { ADD_IIA { @Override void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { - double[] array = new double[RANDOM.nextInt(10)]; + double[] array = new double[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -245,7 +245,7 @@ void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { ADD_LARGER_ARRAY { @Override void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { - double[] array = new double[RANDOM.nextInt(200) + 200]; + double[] array = new double[random.nextInt(200) + 200]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -257,13 +257,13 @@ void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { static final BuilderOp[] values = values(); static BuilderOp randomOp() { - return values[RANDOM.nextInt(values.length)]; + return values[random.nextInt(values.length)]; } abstract void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter); } - private static final Random RANDOM = new Random(42); + private static final Random random = new Random(42); public void testLength() { assertThat(ImmutableDoubleArray.of().length()).isEqualTo(0); diff --git a/android/guava-tests/test/com/google/common/primitives/ImmutableIntArrayTest.java b/android/guava-tests/test/com/google/common/primitives/ImmutableIntArrayTest.java index 184ae1e15206..a614b441d64a 100644 --- a/android/guava-tests/test/com/google/common/primitives/ImmutableIntArrayTest.java +++ b/android/guava-tests/test/com/google/common/primitives/ImmutableIntArrayTest.java @@ -167,7 +167,7 @@ public void testBuilder_presize_negative() { */ public void testBuilder_bruteForce() { for (int i = 0; i < reduceIterationsIfGwt(100); i++) { - ImmutableIntArray.Builder builder = ImmutableIntArray.builder(RANDOM.nextInt(20)); + ImmutableIntArray.Builder builder = ImmutableIntArray.builder(random.nextInt(20)); AtomicInteger counter = new AtomicInteger(0); while (counter.get() < 1000) { BuilderOp op = BuilderOp.randomOp(); @@ -190,7 +190,7 @@ void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { ADD_ARRAY { @Override void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { - int[] array = new int[RANDOM.nextInt(10)]; + int[] array = new int[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -201,7 +201,7 @@ void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { @Override void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { List list = new ArrayList<>(); - int num = RANDOM.nextInt(10); + int num = random.nextInt(10); for (int i = 0; i < num; i++) { list.add(counter.getAndIncrement()); } @@ -212,7 +212,7 @@ void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { @Override void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { List list = new ArrayList<>(); - int num = RANDOM.nextInt(10); + int num = random.nextInt(10); for (int i = 0; i < num; i++) { list.add(counter.getAndIncrement()); } @@ -222,7 +222,7 @@ void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { ADD_STREAM { @Override void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { - int[] array = new int[RANDOM.nextInt(10)]; + int[] array = new int[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -232,7 +232,7 @@ void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { ADD_IIA { @Override void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { - int[] array = new int[RANDOM.nextInt(10)]; + int[] array = new int[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -242,7 +242,7 @@ void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { ADD_LARGER_ARRAY { @Override void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { - int[] array = new int[RANDOM.nextInt(200) + 200]; + int[] array = new int[random.nextInt(200) + 200]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -254,13 +254,13 @@ void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { static final BuilderOp[] values = values(); static BuilderOp randomOp() { - return values[RANDOM.nextInt(values.length)]; + return values[random.nextInt(values.length)]; } abstract void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter); } - private static final Random RANDOM = new Random(42); + private static final Random random = new Random(42); public void testLength() { assertThat(ImmutableIntArray.of().length()).isEqualTo(0); diff --git a/android/guava-tests/test/com/google/common/primitives/ImmutableLongArrayTest.java b/android/guava-tests/test/com/google/common/primitives/ImmutableLongArrayTest.java index f8e32747fbb4..9c279055c518 100644 --- a/android/guava-tests/test/com/google/common/primitives/ImmutableLongArrayTest.java +++ b/android/guava-tests/test/com/google/common/primitives/ImmutableLongArrayTest.java @@ -169,7 +169,7 @@ public void testBuilder_presize_negative() { */ public void testBuilder_bruteForce() { for (int i = 0; i < reduceIterationsIfGwt(100); i++) { - ImmutableLongArray.Builder builder = ImmutableLongArray.builder(RANDOM.nextInt(20)); + ImmutableLongArray.Builder builder = ImmutableLongArray.builder(random.nextInt(20)); AtomicLong counter = new AtomicLong(0); while (counter.get() < 1000) { BuilderOp op = BuilderOp.randomOp(); @@ -192,7 +192,7 @@ void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { ADD_ARRAY { @Override void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { - long[] array = new long[RANDOM.nextInt(10)]; + long[] array = new long[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -203,7 +203,7 @@ void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { @Override void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { List list = new ArrayList<>(); - long num = RANDOM.nextInt(10); + long num = random.nextInt(10); for (int i = 0; i < num; i++) { list.add(counter.getAndIncrement()); } @@ -214,7 +214,7 @@ void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { @Override void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { List list = new ArrayList<>(); - long num = RANDOM.nextInt(10); + long num = random.nextInt(10); for (int i = 0; i < num; i++) { list.add(counter.getAndIncrement()); } @@ -224,7 +224,7 @@ void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { ADD_STREAM { @Override void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { - long[] array = new long[RANDOM.nextInt(10)]; + long[] array = new long[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -234,7 +234,7 @@ void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { ADD_IIA { @Override void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { - long[] array = new long[RANDOM.nextInt(10)]; + long[] array = new long[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -244,7 +244,7 @@ void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { ADD_LARGER_ARRAY { @Override void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { - long[] array = new long[RANDOM.nextInt(200) + 200]; + long[] array = new long[random.nextInt(200) + 200]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -256,13 +256,13 @@ void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { static final BuilderOp[] values = values(); static BuilderOp randomOp() { - return values[RANDOM.nextInt(values.length)]; + return values[random.nextInt(values.length)]; } abstract void doIt(ImmutableLongArray.Builder builder, AtomicLong counter); } - private static final Random RANDOM = new Random(42); + private static final Random random = new Random(42); public void testLength() { assertThat(ImmutableLongArray.of().length()).isEqualTo(0); diff --git a/android/guava/src/com/google/common/cache/Striped64.java b/android/guava/src/com/google/common/cache/Striped64.java index 612cfece5083..8599fea81f35 100644 --- a/android/guava/src/com/google/common/cache/Striped64.java +++ b/android/guava/src/com/google/common/cache/Striped64.java @@ -108,18 +108,18 @@ static final class Cell { } final boolean cas(long cmp, long val) { - return UNSAFE.compareAndSwapLong(this, valueOffset, cmp, val); + return UNSAFE.compareAndSwapLong(this, VALUE_OFFSET, cmp, val); } // Unsafe mechanics private static final Unsafe UNSAFE; - private static final long valueOffset; + private static final long VALUE_OFFSET; static { try { UNSAFE = getUnsafe(); Class ak = Cell.class; - valueOffset = UNSAFE.objectFieldOffset(ak.getDeclaredField("value")); + VALUE_OFFSET = UNSAFE.objectFieldOffset(ak.getDeclaredField("value")); } catch (Exception e) { throw new Error(e); } @@ -156,12 +156,12 @@ final boolean cas(long cmp, long val) { /** CASes the base field. */ final boolean casBase(long cmp, long val) { - return UNSAFE.compareAndSwapLong(this, baseOffset, cmp, val); + return UNSAFE.compareAndSwapLong(this, BASE_OFFSET, cmp, val); } /** CASes the busy field from 0 to 1 to acquire lock. */ final boolean casBusy() { - return UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1); + return UNSAFE.compareAndSwapInt(this, BUSY_OFFSET, 0, 1); } /** @@ -271,15 +271,15 @@ final void internalReset(long initialValue) { // Unsafe mechanics private static final Unsafe UNSAFE; - private static final long baseOffset; - private static final long busyOffset; + private static final long BASE_OFFSET; + private static final long BUSY_OFFSET; static { try { UNSAFE = getUnsafe(); Class sk = Striped64.class; - baseOffset = UNSAFE.objectFieldOffset(sk.getDeclaredField("base")); - busyOffset = UNSAFE.objectFieldOffset(sk.getDeclaredField("busy")); + BASE_OFFSET = UNSAFE.objectFieldOffset(sk.getDeclaredField("base")); + BUSY_OFFSET = UNSAFE.objectFieldOffset(sk.getDeclaredField("busy")); } catch (Exception e) { throw new Error(e); } diff --git a/android/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java b/android/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java index 40253d00e628..c5fa21534e88 100644 --- a/android/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java +++ b/android/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java @@ -33,7 +33,7 @@ @SuppressWarnings("serial") // uses writeReplace, not default serialization @GwtIncompatible final class RegularImmutableSortedMultiset extends ImmutableSortedMultiset { - private static final long[] ZERO_CUMULATIVE_COUNTS = {0}; + private static final long[] zeroCumulativeCounts = {0}; static final ImmutableSortedMultiset NATURAL_EMPTY_MULTISET = new RegularImmutableSortedMultiset<>(Ordering.natural()); @@ -45,7 +45,7 @@ final class RegularImmutableSortedMultiset extends ImmutableSortedMultiset RegularImmutableSortedMultiset(Comparator comparator) { this.elementSet = ImmutableSortedSet.emptySet(comparator); - this.cumulativeCounts = ZERO_CUMULATIVE_COUNTS; + this.cumulativeCounts = zeroCumulativeCounts; this.offset = 0; this.length = 0; } diff --git a/android/guava/src/com/google/common/escape/ArrayBasedEscaperMap.java b/android/guava/src/com/google/common/escape/ArrayBasedEscaperMap.java index d8036839d57f..68515dfa3512 100644 --- a/android/guava/src/com/google/common/escape/ArrayBasedEscaperMap.java +++ b/android/guava/src/com/google/common/escape/ArrayBasedEscaperMap.java @@ -78,5 +78,6 @@ static char[][] createReplacementArray(Map map) { } // Immutable empty array for when there are no replacements. + @SuppressWarnings("ConstantCaseForConstants") // An empty array is a constant. private static final char[][] EMPTY_REPLACEMENT_ARRAY = new char[0][0]; } diff --git a/android/guava/src/com/google/common/hash/Crc32cHashFunction.java b/android/guava/src/com/google/common/hash/Crc32cHashFunction.java index f965178dddef..679c47852062 100644 --- a/android/guava/src/com/google/common/hash/Crc32cHashFunction.java +++ b/android/guava/src/com/google/common/hash/Crc32cHashFunction.java @@ -49,8 +49,8 @@ static final class Crc32cHasher extends AbstractStreamingHasher { * CRC(x ^ y) == CRC(x) ^ CRC(y). The approach we take is to break the message as follows, * with each letter representing a 4-byte word: ABCDABCDABCDABCD... and to calculate * CRC(A000A000A000...), CRC(0B000B000B...), CRC(00C000C000C...), CRC(000D000D000D...) - * and then to XOR them together. The STRIDE_TABLE enables us to hash an int followed by 12 - * zero bytes (3 ints), while the BYTE_TABLE is for advancing one byte at a time. + * and then to XOR them together. The strideTable enables us to hash an int followed by 12 + * zero bytes (3 ints), while the byteTable is for advancing one byte at a time. * This algorithm is due to the paper "Everything we know about CRC but [are] afraid to forget" * by Kadatch and Jenkins, 2010. */ @@ -106,7 +106,7 @@ protected void processRemaining(ByteBuffer bb) { crc0 = combine(crc0, crc2); crc0 = combine(crc0, crc3); while (bb.hasRemaining()) { - crc0 = (crc0 >>> 8) ^ BYTE_TABLE[(bb.get() ^ crc0) & 0xFF]; + crc0 = (crc0 >>> 8) ^ byteTable[(bb.get() ^ crc0) & 0xFF]; } finished = true; } @@ -121,7 +121,7 @@ protected HashCode makeHash() { return HashCode.fromInt(~crc0); } - static final int[] BYTE_TABLE = { + static final int[] byteTable = { 0x00000000, 0xf26b8303, 0xe13b70f7, 0x1350f3f4, 0xc79a971f, 0x35f1141c, 0x26a1e7e8, 0xd4ca64eb, 0x8ad958cf, 0x78b2dbcc, 0x6be22838, 0x9989ab3b, 0x4d43cfd0, 0xbf284cd3, 0xac78bf27, 0x5e133c24, 0x105ec76f, 0xe235446c, @@ -167,7 +167,7 @@ protected HashCode makeHash() { 0xbe2da0a5, 0x4c4623a6, 0x5f16d052, 0xad7d5351 }; - static final int[][] STRIDE_TABLE = { + static final int[][] strideTable = { { 0x00000000, 0x30d23865, 0x61a470ca, 0x517648af, 0xc348e194, 0xf39ad9f1, 0xa2ec915e, 0x923ea93b, 0x837db5d9, 0xb3af8dbc, 0xe2d9c513, 0xd20bfd76, @@ -354,16 +354,16 @@ protected HashCode makeHash() { static final int INVERSE_COMPUTE_FOR_WORD_OF_ALL_1S = 0xeee3ddcd; static int computeForWord(int word) { - return STRIDE_TABLE[3][word & 0xFF] - ^ STRIDE_TABLE[2][(word >>> 8) & 0xFF] - ^ STRIDE_TABLE[1][(word >>> 16) & 0xFF] - ^ STRIDE_TABLE[0][word >>> 24]; + return strideTable[3][word & 0xFF] + ^ strideTable[2][(word >>> 8) & 0xFF] + ^ strideTable[1][(word >>> 16) & 0xFF] + ^ strideTable[0][word >>> 24]; } static int combine(int csum, int crc) { csum ^= crc; for (int i = 0; i < 4; i++) { - csum = (csum >>> 8) ^ BYTE_TABLE[csum & 0xFF]; + csum = (csum >>> 8) ^ byteTable[csum & 0xFF]; } return csum; } diff --git a/android/guava/src/com/google/common/hash/Striped64.java b/android/guava/src/com/google/common/hash/Striped64.java index 516f35917652..6aa6ab0af261 100644 --- a/android/guava/src/com/google/common/hash/Striped64.java +++ b/android/guava/src/com/google/common/hash/Striped64.java @@ -108,18 +108,18 @@ static final class Cell { } final boolean cas(long cmp, long val) { - return UNSAFE.compareAndSwapLong(this, valueOffset, cmp, val); + return UNSAFE.compareAndSwapLong(this, VALUE_OFFSET, cmp, val); } // Unsafe mechanics private static final Unsafe UNSAFE; - private static final long valueOffset; + private static final long VALUE_OFFSET; static { try { UNSAFE = getUnsafe(); Class ak = Cell.class; - valueOffset = UNSAFE.objectFieldOffset(ak.getDeclaredField("value")); + VALUE_OFFSET = UNSAFE.objectFieldOffset(ak.getDeclaredField("value")); } catch (Exception e) { throw new Error(e); } @@ -156,12 +156,12 @@ final boolean cas(long cmp, long val) { /** CASes the base field. */ final boolean casBase(long cmp, long val) { - return UNSAFE.compareAndSwapLong(this, baseOffset, cmp, val); + return UNSAFE.compareAndSwapLong(this, BASE_OFFSET, cmp, val); } /** CASes the busy field from 0 to 1 to acquire lock. */ final boolean casBusy() { - return UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1); + return UNSAFE.compareAndSwapInt(this, BUSY_OFFSET, 0, 1); } /** @@ -271,15 +271,15 @@ final void internalReset(long initialValue) { // Unsafe mechanics private static final Unsafe UNSAFE; - private static final long baseOffset; - private static final long busyOffset; + private static final long BASE_OFFSET; + private static final long BUSY_OFFSET; static { try { UNSAFE = getUnsafe(); Class sk = Striped64.class; - baseOffset = UNSAFE.objectFieldOffset(sk.getDeclaredField("base")); - busyOffset = UNSAFE.objectFieldOffset(sk.getDeclaredField("busy")); + BASE_OFFSET = UNSAFE.objectFieldOffset(sk.getDeclaredField("base")); + BUSY_OFFSET = UNSAFE.objectFieldOffset(sk.getDeclaredField("busy")); } catch (Exception e) { throw new Error(e); } diff --git a/android/guava/src/com/google/common/net/MediaType.java b/android/guava/src/com/google/common/net/MediaType.java index 9ca41230251d..49b10c651330 100644 --- a/android/guava/src/com/google/common/net/MediaType.java +++ b/android/guava/src/com/google/common/net/MediaType.java @@ -102,7 +102,7 @@ public final class MediaType { private static final String WILDCARD = "*"; - private static final Map KNOWN_TYPES = Maps.newHashMap(); + private static final Map knownTypes = Maps.newHashMap(); private static MediaType createConstant(String type, String subtype) { MediaType mediaType = @@ -118,7 +118,7 @@ private static MediaType createConstantUtf8(String type, String subtype) { } private static MediaType addKnownType(MediaType mediaType) { - KNOWN_TYPES.put(mediaType, mediaType); + knownTypes.put(mediaType, mediaType); return mediaType; } @@ -906,7 +906,7 @@ public MediaType withParameters(String attribute, Iterable values) { mediaType.parsedCharset = this.parsedCharset; } // Return one of the constants if the media type is a known type. - return MoreObjects.firstNonNull(KNOWN_TYPES.get(mediaType), mediaType); + return MoreObjects.firstNonNull(knownTypes.get(mediaType), mediaType); } /** @@ -1007,7 +1007,7 @@ private static MediaType create( } MediaType mediaType = new MediaType(normalizedType, normalizedSubtype, builder.build()); // Return one of the constants if the media type is a known type. - return MoreObjects.firstNonNull(KNOWN_TYPES.get(mediaType), mediaType); + return MoreObjects.firstNonNull(knownTypes.get(mediaType), mediaType); } /** diff --git a/android/guava/src/com/google/common/net/PercentEscaper.java b/android/guava/src/com/google/common/net/PercentEscaper.java index 8e9cdc5e6c27..259bc674f14d 100644 --- a/android/guava/src/com/google/common/net/PercentEscaper.java +++ b/android/guava/src/com/google/common/net/PercentEscaper.java @@ -54,10 +54,10 @@ public final class PercentEscaper extends UnicodeEscaper { // In some escapers spaces are escaped to '+' - private static final char[] PLUS_SIGN = {'+'}; + private static final char[] plusSign = {'+'}; // Percent escapers output upper case hex digits (uri escapers require this). - private static final char[] UPPER_HEX_DIGITS = "0123456789ABCDEF".toCharArray(); + private static final char[] upperHexDigits = "0123456789ABCDEF".toCharArray(); /** If true we should convert space to the {@code +} character. */ private final boolean plusForSpace; @@ -161,14 +161,14 @@ public String escape(String s) { if (cp < safeOctets.length && safeOctets[cp]) { return null; } else if (cp == ' ' && plusForSpace) { - return PLUS_SIGN; + return plusSign; } else if (cp <= 0x7F) { // Single byte UTF-8 characters // Start with "%--" and fill in the blanks char[] dest = new char[3]; dest[0] = '%'; - dest[2] = UPPER_HEX_DIGITS[cp & 0xF]; - dest[1] = UPPER_HEX_DIGITS[cp >>> 4]; + dest[2] = upperHexDigits[cp & 0xF]; + dest[1] = upperHexDigits[cp >>> 4]; return dest; } else if (cp <= 0x7ff) { // Two byte UTF-8 characters [cp >= 0x80 && cp <= 0x7ff] @@ -176,13 +176,13 @@ public String escape(String s) { char[] dest = new char[6]; dest[0] = '%'; dest[3] = '%'; - dest[5] = UPPER_HEX_DIGITS[cp & 0xF]; + dest[5] = upperHexDigits[cp & 0xF]; cp >>>= 4; - dest[4] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)]; + dest[4] = upperHexDigits[0x8 | (cp & 0x3)]; cp >>>= 2; - dest[2] = UPPER_HEX_DIGITS[cp & 0xF]; + dest[2] = upperHexDigits[cp & 0xF]; cp >>>= 4; - dest[1] = UPPER_HEX_DIGITS[0xC | cp]; + dest[1] = upperHexDigits[0xC | cp]; return dest; } else if (cp <= 0xffff) { // Three byte UTF-8 characters [cp >= 0x800 && cp <= 0xffff] @@ -192,15 +192,15 @@ public String escape(String s) { dest[1] = 'E'; dest[3] = '%'; dest[6] = '%'; - dest[8] = UPPER_HEX_DIGITS[cp & 0xF]; + dest[8] = upperHexDigits[cp & 0xF]; cp >>>= 4; - dest[7] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)]; + dest[7] = upperHexDigits[0x8 | (cp & 0x3)]; cp >>>= 2; - dest[5] = UPPER_HEX_DIGITS[cp & 0xF]; + dest[5] = upperHexDigits[cp & 0xF]; cp >>>= 4; - dest[4] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)]; + dest[4] = upperHexDigits[0x8 | (cp & 0x3)]; cp >>>= 2; - dest[2] = UPPER_HEX_DIGITS[cp]; + dest[2] = upperHexDigits[cp]; return dest; } else if (cp <= 0x10ffff) { char[] dest = new char[12]; @@ -211,19 +211,19 @@ public String escape(String s) { dest[3] = '%'; dest[6] = '%'; dest[9] = '%'; - dest[11] = UPPER_HEX_DIGITS[cp & 0xF]; + dest[11] = upperHexDigits[cp & 0xF]; cp >>>= 4; - dest[10] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)]; + dest[10] = upperHexDigits[0x8 | (cp & 0x3)]; cp >>>= 2; - dest[8] = UPPER_HEX_DIGITS[cp & 0xF]; + dest[8] = upperHexDigits[cp & 0xF]; cp >>>= 4; - dest[7] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)]; + dest[7] = upperHexDigits[0x8 | (cp & 0x3)]; cp >>>= 2; - dest[5] = UPPER_HEX_DIGITS[cp & 0xF]; + dest[5] = upperHexDigits[cp & 0xF]; cp >>>= 4; - dest[4] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)]; + dest[4] = upperHexDigits[0x8 | (cp & 0x3)]; cp >>>= 2; - dest[2] = UPPER_HEX_DIGITS[cp & 0x7]; + dest[2] = upperHexDigits[cp & 0x7]; return dest; } else { // If this ever happens it is due to bug in UnicodeEscaper, not bad input. diff --git a/android/guava/src/com/google/common/primitives/Primitives.java b/android/guava/src/com/google/common/primitives/Primitives.java index 364f72eef27c..9e2f71093b06 100644 --- a/android/guava/src/com/google/common/primitives/Primitives.java +++ b/android/guava/src/com/google/common/primitives/Primitives.java @@ -34,9 +34,13 @@ public final class Primitives { private Primitives() {} /** A map from primitive types to their corresponding wrapper types. */ + // It's a constant, and we can't use ImmutableMap here without creating a circular dependency. + @SuppressWarnings("ConstantCaseForConstants") private static final Map, Class> PRIMITIVE_TO_WRAPPER_TYPE; /** A map from wrapper types to their corresponding primitive types. */ + // It's a constant, and we can't use ImmutableMap here without creating a circular dependency. + @SuppressWarnings("ConstantCaseForConstants") private static final Map, Class> WRAPPER_TO_PRIMITIVE_TYPE; // Sad that we can't use a BiMap. :( diff --git a/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java b/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java index fd8f6d869224..d4549004c609 100644 --- a/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java +++ b/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java @@ -154,30 +154,28 @@ public void oneArgNullableThrowsNPE(@Nullable String s) { } } - private static final String[] STATIC_ONE_ARG_METHODS_SHOULD_PASS = { - "staticOneArgCorrectlyThrowsNpe", - "staticOneArgCheckForNullCorrectlyDoesNotThrowNPE", - "staticOneArgCheckForNullCorrectlyThrowsOtherThanNPE", - "staticOneArgCheckForNullThrowsNPE", - "staticOneArgNullableCorrectlyDoesNotThrowNPE", - "staticOneArgNullableCorrectlyThrowsOtherThanNPE", - "staticOneArgNullableThrowsNPE", - }; - private static final String[] STATIC_ONE_ARG_METHODS_SHOULD_FAIL = { - "staticOneArgThrowsOtherThanNpe", "staticOneArgShouldThrowNpeButDoesnt", - }; - private static final String[] NONSTATIC_ONE_ARG_METHODS_SHOULD_PASS = { - "oneArgCorrectlyThrowsNpe", - "oneArgCheckForNullCorrectlyDoesNotThrowNPE", - "oneArgCheckForNullCorrectlyThrowsOtherThanNPE", - "oneArgCheckForNullThrowsNPE", - "oneArgNullableCorrectlyDoesNotThrowNPE", - "oneArgNullableCorrectlyThrowsOtherThanNPE", - "oneArgNullableThrowsNPE", - }; - private static final String[] NONSTATIC_ONE_ARG_METHODS_SHOULD_FAIL = { - "oneArgThrowsOtherThanNpe", "oneArgShouldThrowNpeButDoesnt", - }; + private static final ImmutableSet STATIC_ONE_ARG_METHODS_SHOULD_PASS = + ImmutableSet.of( + "staticOneArgCorrectlyThrowsNpe", + "staticOneArgCheckForNullCorrectlyDoesNotThrowNPE", + "staticOneArgCheckForNullCorrectlyThrowsOtherThanNPE", + "staticOneArgCheckForNullThrowsNPE", + "staticOneArgNullableCorrectlyDoesNotThrowNPE", + "staticOneArgNullableCorrectlyThrowsOtherThanNPE", + "staticOneArgNullableThrowsNPE"); + private static final ImmutableSet STATIC_ONE_ARG_METHODS_SHOULD_FAIL = + ImmutableSet.of("staticOneArgThrowsOtherThanNpe", "staticOneArgShouldThrowNpeButDoesnt"); + private static final ImmutableSet NONSTATIC_ONE_ARG_METHODS_SHOULD_PASS = + ImmutableSet.of( + "oneArgCorrectlyThrowsNpe", + "oneArgCheckForNullCorrectlyDoesNotThrowNPE", + "oneArgCheckForNullCorrectlyThrowsOtherThanNPE", + "oneArgCheckForNullThrowsNPE", + "oneArgNullableCorrectlyDoesNotThrowNPE", + "oneArgNullableCorrectlyThrowsOtherThanNPE", + "oneArgNullableThrowsNPE"); + private static final ImmutableSet NONSTATIC_ONE_ARG_METHODS_SHOULD_FAIL = + ImmutableSet.of("oneArgThrowsOtherThanNpe", "oneArgShouldThrowNpeButDoesnt"); private static class ThrowsIae { public static void christenPoodle(String name) { diff --git a/guava-tests/benchmark/com/google/common/primitives/UnsignedLongsBenchmark.java b/guava-tests/benchmark/com/google/common/primitives/UnsignedLongsBenchmark.java index cf5d3744cf6a..d7531ee71875 100644 --- a/guava-tests/benchmark/com/google/common/primitives/UnsignedLongsBenchmark.java +++ b/guava-tests/benchmark/com/google/common/primitives/UnsignedLongsBenchmark.java @@ -30,7 +30,7 @@ public class UnsignedLongsBenchmark { private static final int ARRAY_SIZE = 0x10000; private static final int ARRAY_MASK = 0x0ffff; - private static final Random RANDOM_SOURCE = new Random(314159265358979L); + private static final Random randomSource = new Random(314159265358979L); private static final long[] longs = new long[ARRAY_SIZE]; private static final long[] divisors = new long[ARRAY_SIZE]; private static final String[] decimalStrings = new String[ARRAY_SIZE]; @@ -122,7 +122,7 @@ int toString(int reps) { } private static long random() { - return RANDOM_SOURCE.nextLong(); + return randomSource.nextLong(); } // A random value that cannot be 0 and that is unsigned-less-than or equal @@ -131,7 +131,7 @@ private static long random() { // Using remainder here does not give us a uniform distribution but it should // not have a big impact on the measurement. private static long randomDivisor(long dividend) { - long r = RANDOM_SOURCE.nextLong(); + long r = randomSource.nextLong(); if (dividend == -1) { return r; } else { diff --git a/guava-tests/test/com/google/common/base/JoinerTest.java b/guava-tests/test/com/google/common/base/JoinerTest.java index aea2ab5b1c4e..cdb4206dea25 100644 --- a/guava-tests/test/com/google/common/base/JoinerTest.java +++ b/guava-tests/test/com/google/common/base/JoinerTest.java @@ -50,17 +50,17 @@ public class JoinerTest extends TestCase { private static final Joiner J = Joiner.on("-"); // needed to prevent warning :( - private static final Iterable ITERABLE_ = Arrays.asList(); - private static final Iterable ITERABLE_1 = Arrays.asList(1); - private static final Iterable ITERABLE_12 = Arrays.asList(1, 2); - private static final Iterable ITERABLE_123 = Arrays.asList(1, 2, 3); - private static final Iterable<@Nullable Integer> ITERABLE_NULL = Arrays.asList((Integer) null); - private static final Iterable<@Nullable Integer> ITERABLE_NULL_NULL = + private static final Iterable iterable = Arrays.asList(); + private static final Iterable iterable1 = Arrays.asList(1); + private static final Iterable iterable12 = Arrays.asList(1, 2); + private static final Iterable iterable123 = Arrays.asList(1, 2, 3); + private static final Iterable<@Nullable Integer> iterableNull = Arrays.asList((Integer) null); + private static final Iterable<@Nullable Integer> iterableNullNull = Arrays.asList((Integer) null, null); - private static final Iterable<@Nullable Integer> ITERABLE_NULL_1 = Arrays.asList(null, 1); - private static final Iterable<@Nullable Integer> ITERABLE_1_NULL = Arrays.asList(1, null); - private static final Iterable<@Nullable Integer> ITERABLE_1_NULL_2 = Arrays.asList(1, null, 2); - private static final Iterable<@Nullable Integer> ITERABLE_FOUR_NULLS = + private static final Iterable<@Nullable Integer> iterableNull1 = Arrays.asList(null, 1); + private static final Iterable<@Nullable Integer> iterable1Null = Arrays.asList(1, null); + private static final Iterable<@Nullable Integer> iterable1Null2 = Arrays.asList(1, null, 2); + private static final Iterable<@Nullable Integer> iterableFourNulls = Arrays.asList((Integer) null, null, null, null); /* @@ -107,60 +107,60 @@ public int size() { @SuppressWarnings("JoinIterableIterator") // explicitly testing iterator overload, too public void testNoSpecialNullBehavior() { - checkNoOutput(J, ITERABLE_); - checkResult(J, ITERABLE_1, "1"); - checkResult(J, ITERABLE_12, "1-2"); - checkResult(J, ITERABLE_123, "1-2-3"); + checkNoOutput(J, iterable); + checkResult(J, iterable1, "1"); + checkResult(J, iterable12, "1-2"); + checkResult(J, iterable123, "1-2-3"); checkResult(J, UNDERREPORTING_SIZE_LIST, "1-2-3"); checkResult(J, OVERREPORTING_SIZE_LIST, "1-2-3"); - assertThrows(NullPointerException.class, () -> J.join(ITERABLE_NULL)); - assertThrows(NullPointerException.class, () -> J.join(ITERABLE_1_NULL_2)); + assertThrows(NullPointerException.class, () -> J.join(iterableNull)); + assertThrows(NullPointerException.class, () -> J.join(iterable1Null2)); - assertThrows(NullPointerException.class, () -> J.join(ITERABLE_NULL.iterator())); - assertThrows(NullPointerException.class, () -> J.join(ITERABLE_1_NULL_2.iterator())); + assertThrows(NullPointerException.class, () -> J.join(iterableNull.iterator())); + assertThrows(NullPointerException.class, () -> J.join(iterable1Null2.iterator())); } public void testOnCharOverride() { Joiner onChar = Joiner.on('-'); - checkNoOutput(onChar, ITERABLE_); - checkResult(onChar, ITERABLE_1, "1"); - checkResult(onChar, ITERABLE_12, "1-2"); - checkResult(onChar, ITERABLE_123, "1-2-3"); + checkNoOutput(onChar, iterable); + checkResult(onChar, iterable1, "1"); + checkResult(onChar, iterable12, "1-2"); + checkResult(onChar, iterable123, "1-2-3"); checkResult(J, UNDERREPORTING_SIZE_LIST, "1-2-3"); checkResult(J, OVERREPORTING_SIZE_LIST, "1-2-3"); } public void testSkipNulls() { Joiner skipNulls = J.skipNulls(); - checkNoOutput(skipNulls, ITERABLE_); - checkNoOutput(skipNulls, ITERABLE_NULL); - checkNoOutput(skipNulls, ITERABLE_NULL_NULL); - checkNoOutput(skipNulls, ITERABLE_FOUR_NULLS); - checkResult(skipNulls, ITERABLE_1, "1"); - checkResult(skipNulls, ITERABLE_12, "1-2"); - checkResult(skipNulls, ITERABLE_123, "1-2-3"); + checkNoOutput(skipNulls, iterable); + checkNoOutput(skipNulls, iterableNull); + checkNoOutput(skipNulls, iterableNullNull); + checkNoOutput(skipNulls, iterableFourNulls); + checkResult(skipNulls, iterable1, "1"); + checkResult(skipNulls, iterable12, "1-2"); + checkResult(skipNulls, iterable123, "1-2-3"); checkResult(J, UNDERREPORTING_SIZE_LIST, "1-2-3"); checkResult(J, OVERREPORTING_SIZE_LIST, "1-2-3"); - checkResult(skipNulls, ITERABLE_NULL_1, "1"); - checkResult(skipNulls, ITERABLE_1_NULL, "1"); - checkResult(skipNulls, ITERABLE_1_NULL_2, "1-2"); + checkResult(skipNulls, iterableNull1, "1"); + checkResult(skipNulls, iterable1Null, "1"); + checkResult(skipNulls, iterable1Null2, "1-2"); } public void testUseForNull() { Joiner zeroForNull = J.useForNull("0"); - checkNoOutput(zeroForNull, ITERABLE_); - checkResult(zeroForNull, ITERABLE_1, "1"); - checkResult(zeroForNull, ITERABLE_12, "1-2"); - checkResult(zeroForNull, ITERABLE_123, "1-2-3"); + checkNoOutput(zeroForNull, iterable); + checkResult(zeroForNull, iterable1, "1"); + checkResult(zeroForNull, iterable12, "1-2"); + checkResult(zeroForNull, iterable123, "1-2-3"); checkResult(J, UNDERREPORTING_SIZE_LIST, "1-2-3"); checkResult(J, OVERREPORTING_SIZE_LIST, "1-2-3"); - checkResult(zeroForNull, ITERABLE_NULL, "0"); - checkResult(zeroForNull, ITERABLE_NULL_NULL, "0-0"); - checkResult(zeroForNull, ITERABLE_NULL_1, "0-1"); - checkResult(zeroForNull, ITERABLE_1_NULL, "1-0"); - checkResult(zeroForNull, ITERABLE_1_NULL_2, "1-0-2"); - checkResult(zeroForNull, ITERABLE_FOUR_NULLS, "0-0-0-0"); + checkResult(zeroForNull, iterableNull, "0"); + checkResult(zeroForNull, iterableNullNull, "0-0"); + checkResult(zeroForNull, iterableNull1, "0-1"); + checkResult(zeroForNull, iterable1Null, "1-0"); + checkResult(zeroForNull, iterable1Null2, "1-0-2"); + checkResult(zeroForNull, iterableFourNulls, "0-0-0-0"); } private static void checkNoOutput(Joiner joiner, Iterable set) { diff --git a/guava-tests/test/com/google/common/base/PreconditionsTest.java b/guava-tests/test/com/google/common/base/PreconditionsTest.java index 5716598053f0..7e8d8bb55dbd 100644 --- a/guava-tests/test/com/google/common/base/PreconditionsTest.java +++ b/guava-tests/test/com/google/common/base/PreconditionsTest.java @@ -392,7 +392,7 @@ private Object[] getParametersForSignature( return params; } - private static final ImmutableList> possibleParamTypes = + private static final ImmutableList> POSSIBLE_PARAM_TYPES = ImmutableList.of(char.class, int.class, long.class, Object.class); /** @@ -410,7 +410,7 @@ private static ImmutableList>> allSignatures(Class pre List>> typesLists = new ArrayList<>(); for (int i = 0; i < 2; i++) { - typesLists.add(possibleParamTypes); + typesLists.add(POSSIBLE_PARAM_TYPES); for (List> curr : Lists.cartesianProduct(typesLists)) { allOverloads.add( ImmutableList.>builder() diff --git a/guava-tests/test/com/google/common/collect/AbstractImmutableSortedMapMapInterfaceTest.java b/guava-tests/test/com/google/common/collect/AbstractImmutableSortedMapMapInterfaceTest.java index 73ac6f385761..30110ad5719e 100644 --- a/guava-tests/test/com/google/common/collect/AbstractImmutableSortedMapMapInterfaceTest.java +++ b/guava-tests/test/com/google/common/collect/AbstractImmutableSortedMapMapInterfaceTest.java @@ -39,7 +39,7 @@ protected SortedMap makeEmptyMap() { throw new UnsupportedOperationException(); } - private static final Joiner joiner = Joiner.on(", "); + private static final Joiner JOINER = Joiner.on(", "); @Override protected void assertMoreInvariants(Map map) { @@ -48,10 +48,10 @@ protected void assertMoreInvariants(Map map) { assertEquals(entry.getKey() + "=" + entry.getValue(), entry.toString()); } - assertEquals("{" + joiner.join(map.entrySet()) + "}", map.toString()); - assertEquals("[" + joiner.join(map.entrySet()) + "]", map.entrySet().toString()); - assertEquals("[" + joiner.join(map.keySet()) + "]", map.keySet().toString()); - assertEquals("[" + joiner.join(map.values()) + "]", map.values().toString()); + assertEquals("{" + JOINER.join(map.entrySet()) + "}", map.toString()); + assertEquals("[" + JOINER.join(map.entrySet()) + "]", map.entrySet().toString()); + assertEquals("[" + JOINER.join(map.keySet()) + "]", map.keySet().toString()); + assertEquals("[" + JOINER.join(map.values()) + "]", map.values().toString()); assertEquals(newHashSet(map.entrySet()), map.entrySet()); assertEquals(newHashSet(map.keySet()), map.keySet()); diff --git a/guava-tests/test/com/google/common/collect/GeneralRangeTest.java b/guava-tests/test/com/google/common/collect/GeneralRangeTest.java index 91852de9f9bd..214513297506 100644 --- a/guava-tests/test/com/google/common/collect/GeneralRangeTest.java +++ b/guava-tests/test/com/google/common/collect/GeneralRangeTest.java @@ -17,13 +17,14 @@ import static com.google.common.collect.BoundType.CLOSED; import static com.google.common.collect.BoundType.OPEN; import static com.google.common.collect.ReflectionFreeAssertThrows.assertThrows; -import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Objects; import com.google.common.testing.NullPointerTester; +import java.util.Arrays; import java.util.List; import junit.framework.TestCase; import org.jspecify.annotations.NullMarked; @@ -40,7 +41,8 @@ public class GeneralRangeTest extends TestCase { private static final Ordering<@Nullable Integer> ORDERING = Ordering.natural().nullsFirst(); - private static final List<@Nullable Integer> IN_ORDER_VALUES = asList(null, 1, 2, 3, 4, 5); + private static final List<@Nullable Integer> IN_ORDER_VALUES = + unmodifiableList(Arrays.<@Nullable Integer>asList(null, 1, 2, 3, 4, 5)); public void testCreateEmptyRangeFails() { for (BoundType lboundType : BoundType.values()) { diff --git a/guava-tests/test/com/google/common/graph/PackageSanityTests.java b/guava-tests/test/com/google/common/graph/PackageSanityTests.java index 8b241a2ab123..2ddcbc1d5d8d 100644 --- a/guava-tests/test/com/google/common/graph/PackageSanityTests.java +++ b/guava-tests/test/com/google/common/graph/PackageSanityTests.java @@ -31,9 +31,9 @@ @NullUnmarked public class PackageSanityTests extends AbstractPackageSanityTests { - private static final AbstractGraphBuilder GRAPH_BUILDER_A = + private static final AbstractGraphBuilder graphBuilderA = GraphBuilder.directed().expectedNodeCount(10); - private static final AbstractGraphBuilder GRAPH_BUILDER_B = + private static final AbstractGraphBuilder graphBuilderB = ValueGraphBuilder.directed().allowsSelfLoops(true).expectedNodeCount(16); private static final ImmutableGraph IMMUTABLE_GRAPH_A = @@ -41,9 +41,9 @@ public class PackageSanityTests extends AbstractPackageSanityTests { private static final ImmutableGraph IMMUTABLE_GRAPH_B = GraphBuilder.directed().immutable().addNode("B").build(); - private static final NetworkBuilder NETWORK_BUILDER_A = + private static final NetworkBuilder networkBuilderA = NetworkBuilder.directed().allowsParallelEdges(true).expectedNodeCount(10); - private static final NetworkBuilder NETWORK_BUILDER_B = + private static final NetworkBuilder networkBuilderB = NetworkBuilder.directed().allowsSelfLoops(true).expectedNodeCount(16); private static final ImmutableNetwork IMMUTABLE_NETWORK_A = @@ -57,10 +57,10 @@ public PackageSanityTests() { MutableNetwork mutableNetworkB = NetworkBuilder.directed().build(); mutableNetworkB.addNode("b"); - setDistinctValues(AbstractGraphBuilder.class, GRAPH_BUILDER_A, GRAPH_BUILDER_B); + setDistinctValues(AbstractGraphBuilder.class, graphBuilderA, graphBuilderB); setDistinctValues(Graph.class, IMMUTABLE_GRAPH_A, IMMUTABLE_GRAPH_B); setDistinctValues(MutableNetwork.class, mutableNetworkA, mutableNetworkB); - setDistinctValues(NetworkBuilder.class, NETWORK_BUILDER_A, NETWORK_BUILDER_B); + setDistinctValues(NetworkBuilder.class, networkBuilderA, networkBuilderB); setDistinctValues(Network.class, IMMUTABLE_NETWORK_A, IMMUTABLE_NETWORK_B); setDefault(EndpointPair.class, EndpointPair.ordered("A", "B")); } diff --git a/guava-tests/test/com/google/common/hash/Crc32cHashFunctionTest.java b/guava-tests/test/com/google/common/hash/Crc32cHashFunctionTest.java index 03a0cf1490cf..2d63f46b20ca 100644 --- a/guava-tests/test/com/google/common/hash/Crc32cHashFunctionTest.java +++ b/guava-tests/test/com/google/common/hash/Crc32cHashFunctionTest.java @@ -126,7 +126,7 @@ public void testAgainstSimplerImplementation() { private static int referenceCrc(byte[] bytes) { int crc = ~0; for (byte b : bytes) { - crc = (crc >>> 8) ^ Crc32cHashFunction.Crc32cHasher.BYTE_TABLE[(crc ^ b) & 0xFF]; + crc = (crc >>> 8) ^ Crc32cHashFunction.Crc32cHasher.byteTable[(crc ^ b) & 0xFF]; } return ~crc; } @@ -169,7 +169,7 @@ public void testCrc32cByteTable() { expected[i] = crc; } - int[] actual = Crc32cHashFunction.Crc32cHasher.BYTE_TABLE; + int[] actual = Crc32cHashFunction.Crc32cHasher.byteTable; assertTrue( "Expected: \n" + Arrays.toString(expected) + "\nActual:\n" + Arrays.toString(actual), Arrays.equals(expected, actual)); @@ -186,7 +186,7 @@ static int advanceOneBit(int next) { public void testCrc32cStrideTable() { int next = CRC32C_GENERATOR_FLIPPED; for (int i = 0; i < 12; i++) { // for 3 ints = 12 bytes in between each stride window - next = (next >>> 8) ^ Crc32cHashFunction.Crc32cHasher.BYTE_TABLE[next & 0xFF]; + next = (next >>> 8) ^ Crc32cHashFunction.Crc32cHasher.byteTable[next & 0xFF]; } int[][] expected = new int[4][256]; for (int b = 0; b < 4; ++b) { @@ -204,7 +204,7 @@ public void testCrc32cStrideTable() { } } - int[][] actual = Crc32cHashFunction.Crc32cHasher.STRIDE_TABLE; + int[][] actual = Crc32cHashFunction.Crc32cHasher.strideTable; assertTrue( "Expected: \n" + Arrays.deepToString(expected) diff --git a/guava-tests/test/com/google/common/io/LineBufferTest.java b/guava-tests/test/com/google/common/io/LineBufferTest.java index eea7686917d6..cc1ba24095ae 100644 --- a/guava-tests/test/com/google/common/io/LineBufferTest.java +++ b/guava-tests/test/com/google/common/io/LineBufferTest.java @@ -20,6 +20,7 @@ import static java.lang.Math.min; import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import java.io.BufferedReader; import java.io.FilterReader; @@ -58,7 +59,8 @@ public void testProcess() throws IOException { bufferHelper("mixed\nline\rendings\r\n", "mixed\n", "line\r", "endings\r\n"); } - private static final int[] CHUNK_SIZES = {1, 2, 3, Integer.MAX_VALUE}; + private static final ImmutableSet CHUNK_SIZES = + ImmutableSet.of(1, 2, 3, Integer.MAX_VALUE); private static void bufferHelper(String input, String... expect) throws IOException { diff --git a/guava-tests/test/com/google/common/math/DoubleMathTest.java b/guava-tests/test/com/google/common/math/DoubleMathTest.java index 48e72054023f..27f9f481e1b4 100644 --- a/guava-tests/test/com/google/common/math/DoubleMathTest.java +++ b/guava-tests/test/com/google/common/math/DoubleMathTest.java @@ -51,7 +51,6 @@ import java.math.BigInteger; import java.math.RoundingMode; import java.util.Arrays; -import java.util.List; import junit.framework.TestCase; import org.jspecify.annotations.NullUnmarked; @@ -512,17 +511,20 @@ public void testFactorialNegative() { ImmutableList.of(-0.0, 0.0, 1.0, 100.0, 10000.0, Double.MAX_VALUE); private static final Iterable TOLERANCE_CANDIDATES = - Iterables.concat(FINITE_TOLERANCE_CANDIDATES, ImmutableList.of(Double.POSITIVE_INFINITY)); - - private static final List BAD_TOLERANCE_CANDIDATES = - Doubles.asList( - -Double.MIN_VALUE, - -Double.MIN_NORMAL, - -1, - -20, - Double.NaN, - Double.NEGATIVE_INFINITY, - -0.001); + ImmutableList.copyOf( + Iterables.concat( + FINITE_TOLERANCE_CANDIDATES, ImmutableList.of(Double.POSITIVE_INFINITY))); + + private static final ImmutableList BAD_TOLERANCE_CANDIDATES = + ImmutableList.copyOf( + Doubles.asList( + -Double.MIN_VALUE, + -Double.MIN_NORMAL, + -1, + -20, + Double.NaN, + Double.NEGATIVE_INFINITY, + -0.001)); public void testFuzzyEqualsFinite() { for (double a : FINITE_DOUBLE_CANDIDATES) { diff --git a/guava-tests/test/com/google/common/math/QuantilesAlgorithmTest.java b/guava-tests/test/com/google/common/math/QuantilesAlgorithmTest.java index cd4179dd3a89..6a913ace1e68 100644 --- a/guava-tests/test/com/google/common/math/QuantilesAlgorithmTest.java +++ b/guava-tests/test/com/google/common/math/QuantilesAlgorithmTest.java @@ -23,7 +23,6 @@ import com.google.common.collect.Sets; import java.util.Map; import java.util.Random; -import java.util.Set; import junit.framework.TestCase; import org.jspecify.annotations.NullUnmarked; @@ -34,13 +33,15 @@ @NullUnmarked public class QuantilesAlgorithmTest extends TestCase { - private static final Random RNG = new Random(82674067L); + private static final Random rng = new Random(82674067L); private static final int DATASET_SIZE = 1000; private static final double ALLOWED_ERROR = 1.0e-10; private static final QuantilesAlgorithm REFERENCE_ALGORITHM = QuantilesAlgorithm.SORTING; - private static final Set NON_REFERENCE_ALGORITHMS = + private static final ImmutableSet NON_REFERENCE_ALGORITHMS = Sets.difference( - ImmutableSet.copyOf(QuantilesAlgorithm.values()), ImmutableSet.of(REFERENCE_ALGORITHM)); + ImmutableSet.copyOf(QuantilesAlgorithm.values()), + ImmutableSet.of(REFERENCE_ALGORITHM)) + .immutableCopy(); private double[] dataset; @@ -48,7 +49,7 @@ public class QuantilesAlgorithmTest extends TestCase { protected void setUp() { dataset = new double[DATASET_SIZE]; for (int i = 0; i < DATASET_SIZE; i++) { - dataset[i] = RNG.nextDouble(); + dataset[i] = rng.nextDouble(); } } diff --git a/guava-tests/test/com/google/common/primitives/ImmutableDoubleArrayTest.java b/guava-tests/test/com/google/common/primitives/ImmutableDoubleArrayTest.java index 7cbb29d71fcc..a7ea0cfa968c 100644 --- a/guava-tests/test/com/google/common/primitives/ImmutableDoubleArrayTest.java +++ b/guava-tests/test/com/google/common/primitives/ImmutableDoubleArrayTest.java @@ -170,7 +170,7 @@ public void testBuilder_presize_negative() { */ public void testBuilder_bruteForce() { for (int i = 0; i < reduceIterationsIfGwt(100); i++) { - ImmutableDoubleArray.Builder builder = ImmutableDoubleArray.builder(RANDOM.nextInt(20)); + ImmutableDoubleArray.Builder builder = ImmutableDoubleArray.builder(random.nextInt(20)); AtomicInteger counter = new AtomicInteger(0); while (counter.get() < 1000) { BuilderOp op = BuilderOp.randomOp(); @@ -193,7 +193,7 @@ void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { ADD_ARRAY { @Override void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { - double[] array = new double[RANDOM.nextInt(10)]; + double[] array = new double[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -204,7 +204,7 @@ void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { @Override void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { List list = new ArrayList<>(); - double num = RANDOM.nextInt(10); + double num = random.nextInt(10); for (int i = 0; i < num; i++) { list.add((double) counter.getAndIncrement()); } @@ -215,7 +215,7 @@ void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { @Override void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { List list = new ArrayList<>(); - double num = RANDOM.nextInt(10); + double num = random.nextInt(10); for (int i = 0; i < num; i++) { list.add((double) counter.getAndIncrement()); } @@ -225,7 +225,7 @@ void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { ADD_STREAM { @Override void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { - double[] array = new double[RANDOM.nextInt(10)]; + double[] array = new double[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -235,7 +235,7 @@ void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { ADD_IIA { @Override void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { - double[] array = new double[RANDOM.nextInt(10)]; + double[] array = new double[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -245,7 +245,7 @@ void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { ADD_LARGER_ARRAY { @Override void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { - double[] array = new double[RANDOM.nextInt(200) + 200]; + double[] array = new double[random.nextInt(200) + 200]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -257,13 +257,13 @@ void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter) { static final BuilderOp[] values = values(); static BuilderOp randomOp() { - return values[RANDOM.nextInt(values.length)]; + return values[random.nextInt(values.length)]; } abstract void doIt(ImmutableDoubleArray.Builder builder, AtomicInteger counter); } - private static final Random RANDOM = new Random(42); + private static final Random random = new Random(42); public void testLength() { assertThat(ImmutableDoubleArray.of().length()).isEqualTo(0); diff --git a/guava-tests/test/com/google/common/primitives/ImmutableIntArrayTest.java b/guava-tests/test/com/google/common/primitives/ImmutableIntArrayTest.java index 184ae1e15206..a614b441d64a 100644 --- a/guava-tests/test/com/google/common/primitives/ImmutableIntArrayTest.java +++ b/guava-tests/test/com/google/common/primitives/ImmutableIntArrayTest.java @@ -167,7 +167,7 @@ public void testBuilder_presize_negative() { */ public void testBuilder_bruteForce() { for (int i = 0; i < reduceIterationsIfGwt(100); i++) { - ImmutableIntArray.Builder builder = ImmutableIntArray.builder(RANDOM.nextInt(20)); + ImmutableIntArray.Builder builder = ImmutableIntArray.builder(random.nextInt(20)); AtomicInteger counter = new AtomicInteger(0); while (counter.get() < 1000) { BuilderOp op = BuilderOp.randomOp(); @@ -190,7 +190,7 @@ void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { ADD_ARRAY { @Override void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { - int[] array = new int[RANDOM.nextInt(10)]; + int[] array = new int[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -201,7 +201,7 @@ void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { @Override void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { List list = new ArrayList<>(); - int num = RANDOM.nextInt(10); + int num = random.nextInt(10); for (int i = 0; i < num; i++) { list.add(counter.getAndIncrement()); } @@ -212,7 +212,7 @@ void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { @Override void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { List list = new ArrayList<>(); - int num = RANDOM.nextInt(10); + int num = random.nextInt(10); for (int i = 0; i < num; i++) { list.add(counter.getAndIncrement()); } @@ -222,7 +222,7 @@ void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { ADD_STREAM { @Override void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { - int[] array = new int[RANDOM.nextInt(10)]; + int[] array = new int[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -232,7 +232,7 @@ void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { ADD_IIA { @Override void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { - int[] array = new int[RANDOM.nextInt(10)]; + int[] array = new int[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -242,7 +242,7 @@ void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { ADD_LARGER_ARRAY { @Override void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { - int[] array = new int[RANDOM.nextInt(200) + 200]; + int[] array = new int[random.nextInt(200) + 200]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -254,13 +254,13 @@ void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter) { static final BuilderOp[] values = values(); static BuilderOp randomOp() { - return values[RANDOM.nextInt(values.length)]; + return values[random.nextInt(values.length)]; } abstract void doIt(ImmutableIntArray.Builder builder, AtomicInteger counter); } - private static final Random RANDOM = new Random(42); + private static final Random random = new Random(42); public void testLength() { assertThat(ImmutableIntArray.of().length()).isEqualTo(0); diff --git a/guava-tests/test/com/google/common/primitives/ImmutableLongArrayTest.java b/guava-tests/test/com/google/common/primitives/ImmutableLongArrayTest.java index f8e32747fbb4..9c279055c518 100644 --- a/guava-tests/test/com/google/common/primitives/ImmutableLongArrayTest.java +++ b/guava-tests/test/com/google/common/primitives/ImmutableLongArrayTest.java @@ -169,7 +169,7 @@ public void testBuilder_presize_negative() { */ public void testBuilder_bruteForce() { for (int i = 0; i < reduceIterationsIfGwt(100); i++) { - ImmutableLongArray.Builder builder = ImmutableLongArray.builder(RANDOM.nextInt(20)); + ImmutableLongArray.Builder builder = ImmutableLongArray.builder(random.nextInt(20)); AtomicLong counter = new AtomicLong(0); while (counter.get() < 1000) { BuilderOp op = BuilderOp.randomOp(); @@ -192,7 +192,7 @@ void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { ADD_ARRAY { @Override void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { - long[] array = new long[RANDOM.nextInt(10)]; + long[] array = new long[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -203,7 +203,7 @@ void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { @Override void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { List list = new ArrayList<>(); - long num = RANDOM.nextInt(10); + long num = random.nextInt(10); for (int i = 0; i < num; i++) { list.add(counter.getAndIncrement()); } @@ -214,7 +214,7 @@ void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { @Override void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { List list = new ArrayList<>(); - long num = RANDOM.nextInt(10); + long num = random.nextInt(10); for (int i = 0; i < num; i++) { list.add(counter.getAndIncrement()); } @@ -224,7 +224,7 @@ void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { ADD_STREAM { @Override void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { - long[] array = new long[RANDOM.nextInt(10)]; + long[] array = new long[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -234,7 +234,7 @@ void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { ADD_IIA { @Override void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { - long[] array = new long[RANDOM.nextInt(10)]; + long[] array = new long[random.nextInt(10)]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -244,7 +244,7 @@ void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { ADD_LARGER_ARRAY { @Override void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { - long[] array = new long[RANDOM.nextInt(200) + 200]; + long[] array = new long[random.nextInt(200) + 200]; for (int i = 0; i < array.length; i++) { array[i] = counter.getAndIncrement(); } @@ -256,13 +256,13 @@ void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { static final BuilderOp[] values = values(); static BuilderOp randomOp() { - return values[RANDOM.nextInt(values.length)]; + return values[random.nextInt(values.length)]; } abstract void doIt(ImmutableLongArray.Builder builder, AtomicLong counter); } - private static final Random RANDOM = new Random(42); + private static final Random random = new Random(42); public void testLength() { assertThat(ImmutableLongArray.of().length()).isEqualTo(0); diff --git a/guava/src/com/google/common/cache/Striped64.java b/guava/src/com/google/common/cache/Striped64.java index 612cfece5083..8599fea81f35 100644 --- a/guava/src/com/google/common/cache/Striped64.java +++ b/guava/src/com/google/common/cache/Striped64.java @@ -108,18 +108,18 @@ static final class Cell { } final boolean cas(long cmp, long val) { - return UNSAFE.compareAndSwapLong(this, valueOffset, cmp, val); + return UNSAFE.compareAndSwapLong(this, VALUE_OFFSET, cmp, val); } // Unsafe mechanics private static final Unsafe UNSAFE; - private static final long valueOffset; + private static final long VALUE_OFFSET; static { try { UNSAFE = getUnsafe(); Class ak = Cell.class; - valueOffset = UNSAFE.objectFieldOffset(ak.getDeclaredField("value")); + VALUE_OFFSET = UNSAFE.objectFieldOffset(ak.getDeclaredField("value")); } catch (Exception e) { throw new Error(e); } @@ -156,12 +156,12 @@ final boolean cas(long cmp, long val) { /** CASes the base field. */ final boolean casBase(long cmp, long val) { - return UNSAFE.compareAndSwapLong(this, baseOffset, cmp, val); + return UNSAFE.compareAndSwapLong(this, BASE_OFFSET, cmp, val); } /** CASes the busy field from 0 to 1 to acquire lock. */ final boolean casBusy() { - return UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1); + return UNSAFE.compareAndSwapInt(this, BUSY_OFFSET, 0, 1); } /** @@ -271,15 +271,15 @@ final void internalReset(long initialValue) { // Unsafe mechanics private static final Unsafe UNSAFE; - private static final long baseOffset; - private static final long busyOffset; + private static final long BASE_OFFSET; + private static final long BUSY_OFFSET; static { try { UNSAFE = getUnsafe(); Class sk = Striped64.class; - baseOffset = UNSAFE.objectFieldOffset(sk.getDeclaredField("base")); - busyOffset = UNSAFE.objectFieldOffset(sk.getDeclaredField("busy")); + BASE_OFFSET = UNSAFE.objectFieldOffset(sk.getDeclaredField("base")); + BUSY_OFFSET = UNSAFE.objectFieldOffset(sk.getDeclaredField("busy")); } catch (Exception e) { throw new Error(e); } diff --git a/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java b/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java index 7055c525ea5b..7b381b889aa7 100644 --- a/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java +++ b/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java @@ -34,7 +34,7 @@ @SuppressWarnings("serial") // uses writeReplace, not default serialization @GwtIncompatible final class RegularImmutableSortedMultiset extends ImmutableSortedMultiset { - private static final long[] ZERO_CUMULATIVE_COUNTS = {0}; + private static final long[] zeroCumulativeCounts = {0}; static final ImmutableSortedMultiset NATURAL_EMPTY_MULTISET = new RegularImmutableSortedMultiset<>(Ordering.natural()); @@ -46,7 +46,7 @@ final class RegularImmutableSortedMultiset extends ImmutableSortedMultiset RegularImmutableSortedMultiset(Comparator comparator) { this.elementSet = ImmutableSortedSet.emptySet(comparator); - this.cumulativeCounts = ZERO_CUMULATIVE_COUNTS; + this.cumulativeCounts = zeroCumulativeCounts; this.offset = 0; this.length = 0; } diff --git a/guava/src/com/google/common/escape/ArrayBasedEscaperMap.java b/guava/src/com/google/common/escape/ArrayBasedEscaperMap.java index d8036839d57f..68515dfa3512 100644 --- a/guava/src/com/google/common/escape/ArrayBasedEscaperMap.java +++ b/guava/src/com/google/common/escape/ArrayBasedEscaperMap.java @@ -78,5 +78,6 @@ static char[][] createReplacementArray(Map map) { } // Immutable empty array for when there are no replacements. + @SuppressWarnings("ConstantCaseForConstants") // An empty array is a constant. private static final char[][] EMPTY_REPLACEMENT_ARRAY = new char[0][0]; } diff --git a/guava/src/com/google/common/hash/Crc32cHashFunction.java b/guava/src/com/google/common/hash/Crc32cHashFunction.java index f965178dddef..679c47852062 100644 --- a/guava/src/com/google/common/hash/Crc32cHashFunction.java +++ b/guava/src/com/google/common/hash/Crc32cHashFunction.java @@ -49,8 +49,8 @@ static final class Crc32cHasher extends AbstractStreamingHasher { * CRC(x ^ y) == CRC(x) ^ CRC(y). The approach we take is to break the message as follows, * with each letter representing a 4-byte word: ABCDABCDABCDABCD... and to calculate * CRC(A000A000A000...), CRC(0B000B000B...), CRC(00C000C000C...), CRC(000D000D000D...) - * and then to XOR them together. The STRIDE_TABLE enables us to hash an int followed by 12 - * zero bytes (3 ints), while the BYTE_TABLE is for advancing one byte at a time. + * and then to XOR them together. The strideTable enables us to hash an int followed by 12 + * zero bytes (3 ints), while the byteTable is for advancing one byte at a time. * This algorithm is due to the paper "Everything we know about CRC but [are] afraid to forget" * by Kadatch and Jenkins, 2010. */ @@ -106,7 +106,7 @@ protected void processRemaining(ByteBuffer bb) { crc0 = combine(crc0, crc2); crc0 = combine(crc0, crc3); while (bb.hasRemaining()) { - crc0 = (crc0 >>> 8) ^ BYTE_TABLE[(bb.get() ^ crc0) & 0xFF]; + crc0 = (crc0 >>> 8) ^ byteTable[(bb.get() ^ crc0) & 0xFF]; } finished = true; } @@ -121,7 +121,7 @@ protected HashCode makeHash() { return HashCode.fromInt(~crc0); } - static final int[] BYTE_TABLE = { + static final int[] byteTable = { 0x00000000, 0xf26b8303, 0xe13b70f7, 0x1350f3f4, 0xc79a971f, 0x35f1141c, 0x26a1e7e8, 0xd4ca64eb, 0x8ad958cf, 0x78b2dbcc, 0x6be22838, 0x9989ab3b, 0x4d43cfd0, 0xbf284cd3, 0xac78bf27, 0x5e133c24, 0x105ec76f, 0xe235446c, @@ -167,7 +167,7 @@ protected HashCode makeHash() { 0xbe2da0a5, 0x4c4623a6, 0x5f16d052, 0xad7d5351 }; - static final int[][] STRIDE_TABLE = { + static final int[][] strideTable = { { 0x00000000, 0x30d23865, 0x61a470ca, 0x517648af, 0xc348e194, 0xf39ad9f1, 0xa2ec915e, 0x923ea93b, 0x837db5d9, 0xb3af8dbc, 0xe2d9c513, 0xd20bfd76, @@ -354,16 +354,16 @@ protected HashCode makeHash() { static final int INVERSE_COMPUTE_FOR_WORD_OF_ALL_1S = 0xeee3ddcd; static int computeForWord(int word) { - return STRIDE_TABLE[3][word & 0xFF] - ^ STRIDE_TABLE[2][(word >>> 8) & 0xFF] - ^ STRIDE_TABLE[1][(word >>> 16) & 0xFF] - ^ STRIDE_TABLE[0][word >>> 24]; + return strideTable[3][word & 0xFF] + ^ strideTable[2][(word >>> 8) & 0xFF] + ^ strideTable[1][(word >>> 16) & 0xFF] + ^ strideTable[0][word >>> 24]; } static int combine(int csum, int crc) { csum ^= crc; for (int i = 0; i < 4; i++) { - csum = (csum >>> 8) ^ BYTE_TABLE[csum & 0xFF]; + csum = (csum >>> 8) ^ byteTable[csum & 0xFF]; } return csum; } diff --git a/guava/src/com/google/common/hash/Striped64.java b/guava/src/com/google/common/hash/Striped64.java index 516f35917652..6aa6ab0af261 100644 --- a/guava/src/com/google/common/hash/Striped64.java +++ b/guava/src/com/google/common/hash/Striped64.java @@ -108,18 +108,18 @@ static final class Cell { } final boolean cas(long cmp, long val) { - return UNSAFE.compareAndSwapLong(this, valueOffset, cmp, val); + return UNSAFE.compareAndSwapLong(this, VALUE_OFFSET, cmp, val); } // Unsafe mechanics private static final Unsafe UNSAFE; - private static final long valueOffset; + private static final long VALUE_OFFSET; static { try { UNSAFE = getUnsafe(); Class ak = Cell.class; - valueOffset = UNSAFE.objectFieldOffset(ak.getDeclaredField("value")); + VALUE_OFFSET = UNSAFE.objectFieldOffset(ak.getDeclaredField("value")); } catch (Exception e) { throw new Error(e); } @@ -156,12 +156,12 @@ final boolean cas(long cmp, long val) { /** CASes the base field. */ final boolean casBase(long cmp, long val) { - return UNSAFE.compareAndSwapLong(this, baseOffset, cmp, val); + return UNSAFE.compareAndSwapLong(this, BASE_OFFSET, cmp, val); } /** CASes the busy field from 0 to 1 to acquire lock. */ final boolean casBusy() { - return UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1); + return UNSAFE.compareAndSwapInt(this, BUSY_OFFSET, 0, 1); } /** @@ -271,15 +271,15 @@ final void internalReset(long initialValue) { // Unsafe mechanics private static final Unsafe UNSAFE; - private static final long baseOffset; - private static final long busyOffset; + private static final long BASE_OFFSET; + private static final long BUSY_OFFSET; static { try { UNSAFE = getUnsafe(); Class sk = Striped64.class; - baseOffset = UNSAFE.objectFieldOffset(sk.getDeclaredField("base")); - busyOffset = UNSAFE.objectFieldOffset(sk.getDeclaredField("busy")); + BASE_OFFSET = UNSAFE.objectFieldOffset(sk.getDeclaredField("base")); + BUSY_OFFSET = UNSAFE.objectFieldOffset(sk.getDeclaredField("busy")); } catch (Exception e) { throw new Error(e); } diff --git a/guava/src/com/google/common/net/MediaType.java b/guava/src/com/google/common/net/MediaType.java index 9ca41230251d..49b10c651330 100644 --- a/guava/src/com/google/common/net/MediaType.java +++ b/guava/src/com/google/common/net/MediaType.java @@ -102,7 +102,7 @@ public final class MediaType { private static final String WILDCARD = "*"; - private static final Map KNOWN_TYPES = Maps.newHashMap(); + private static final Map knownTypes = Maps.newHashMap(); private static MediaType createConstant(String type, String subtype) { MediaType mediaType = @@ -118,7 +118,7 @@ private static MediaType createConstantUtf8(String type, String subtype) { } private static MediaType addKnownType(MediaType mediaType) { - KNOWN_TYPES.put(mediaType, mediaType); + knownTypes.put(mediaType, mediaType); return mediaType; } @@ -906,7 +906,7 @@ public MediaType withParameters(String attribute, Iterable values) { mediaType.parsedCharset = this.parsedCharset; } // Return one of the constants if the media type is a known type. - return MoreObjects.firstNonNull(KNOWN_TYPES.get(mediaType), mediaType); + return MoreObjects.firstNonNull(knownTypes.get(mediaType), mediaType); } /** @@ -1007,7 +1007,7 @@ private static MediaType create( } MediaType mediaType = new MediaType(normalizedType, normalizedSubtype, builder.build()); // Return one of the constants if the media type is a known type. - return MoreObjects.firstNonNull(KNOWN_TYPES.get(mediaType), mediaType); + return MoreObjects.firstNonNull(knownTypes.get(mediaType), mediaType); } /** diff --git a/guava/src/com/google/common/net/PercentEscaper.java b/guava/src/com/google/common/net/PercentEscaper.java index 8e9cdc5e6c27..259bc674f14d 100644 --- a/guava/src/com/google/common/net/PercentEscaper.java +++ b/guava/src/com/google/common/net/PercentEscaper.java @@ -54,10 +54,10 @@ public final class PercentEscaper extends UnicodeEscaper { // In some escapers spaces are escaped to '+' - private static final char[] PLUS_SIGN = {'+'}; + private static final char[] plusSign = {'+'}; // Percent escapers output upper case hex digits (uri escapers require this). - private static final char[] UPPER_HEX_DIGITS = "0123456789ABCDEF".toCharArray(); + private static final char[] upperHexDigits = "0123456789ABCDEF".toCharArray(); /** If true we should convert space to the {@code +} character. */ private final boolean plusForSpace; @@ -161,14 +161,14 @@ public String escape(String s) { if (cp < safeOctets.length && safeOctets[cp]) { return null; } else if (cp == ' ' && plusForSpace) { - return PLUS_SIGN; + return plusSign; } else if (cp <= 0x7F) { // Single byte UTF-8 characters // Start with "%--" and fill in the blanks char[] dest = new char[3]; dest[0] = '%'; - dest[2] = UPPER_HEX_DIGITS[cp & 0xF]; - dest[1] = UPPER_HEX_DIGITS[cp >>> 4]; + dest[2] = upperHexDigits[cp & 0xF]; + dest[1] = upperHexDigits[cp >>> 4]; return dest; } else if (cp <= 0x7ff) { // Two byte UTF-8 characters [cp >= 0x80 && cp <= 0x7ff] @@ -176,13 +176,13 @@ public String escape(String s) { char[] dest = new char[6]; dest[0] = '%'; dest[3] = '%'; - dest[5] = UPPER_HEX_DIGITS[cp & 0xF]; + dest[5] = upperHexDigits[cp & 0xF]; cp >>>= 4; - dest[4] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)]; + dest[4] = upperHexDigits[0x8 | (cp & 0x3)]; cp >>>= 2; - dest[2] = UPPER_HEX_DIGITS[cp & 0xF]; + dest[2] = upperHexDigits[cp & 0xF]; cp >>>= 4; - dest[1] = UPPER_HEX_DIGITS[0xC | cp]; + dest[1] = upperHexDigits[0xC | cp]; return dest; } else if (cp <= 0xffff) { // Three byte UTF-8 characters [cp >= 0x800 && cp <= 0xffff] @@ -192,15 +192,15 @@ public String escape(String s) { dest[1] = 'E'; dest[3] = '%'; dest[6] = '%'; - dest[8] = UPPER_HEX_DIGITS[cp & 0xF]; + dest[8] = upperHexDigits[cp & 0xF]; cp >>>= 4; - dest[7] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)]; + dest[7] = upperHexDigits[0x8 | (cp & 0x3)]; cp >>>= 2; - dest[5] = UPPER_HEX_DIGITS[cp & 0xF]; + dest[5] = upperHexDigits[cp & 0xF]; cp >>>= 4; - dest[4] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)]; + dest[4] = upperHexDigits[0x8 | (cp & 0x3)]; cp >>>= 2; - dest[2] = UPPER_HEX_DIGITS[cp]; + dest[2] = upperHexDigits[cp]; return dest; } else if (cp <= 0x10ffff) { char[] dest = new char[12]; @@ -211,19 +211,19 @@ public String escape(String s) { dest[3] = '%'; dest[6] = '%'; dest[9] = '%'; - dest[11] = UPPER_HEX_DIGITS[cp & 0xF]; + dest[11] = upperHexDigits[cp & 0xF]; cp >>>= 4; - dest[10] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)]; + dest[10] = upperHexDigits[0x8 | (cp & 0x3)]; cp >>>= 2; - dest[8] = UPPER_HEX_DIGITS[cp & 0xF]; + dest[8] = upperHexDigits[cp & 0xF]; cp >>>= 4; - dest[7] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)]; + dest[7] = upperHexDigits[0x8 | (cp & 0x3)]; cp >>>= 2; - dest[5] = UPPER_HEX_DIGITS[cp & 0xF]; + dest[5] = upperHexDigits[cp & 0xF]; cp >>>= 4; - dest[4] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)]; + dest[4] = upperHexDigits[0x8 | (cp & 0x3)]; cp >>>= 2; - dest[2] = UPPER_HEX_DIGITS[cp & 0x7]; + dest[2] = upperHexDigits[cp & 0x7]; return dest; } else { // If this ever happens it is due to bug in UnicodeEscaper, not bad input. diff --git a/guava/src/com/google/common/primitives/Primitives.java b/guava/src/com/google/common/primitives/Primitives.java index 364f72eef27c..9e2f71093b06 100644 --- a/guava/src/com/google/common/primitives/Primitives.java +++ b/guava/src/com/google/common/primitives/Primitives.java @@ -34,9 +34,13 @@ public final class Primitives { private Primitives() {} /** A map from primitive types to their corresponding wrapper types. */ + // It's a constant, and we can't use ImmutableMap here without creating a circular dependency. + @SuppressWarnings("ConstantCaseForConstants") private static final Map, Class> PRIMITIVE_TO_WRAPPER_TYPE; /** A map from wrapper types to their corresponding primitive types. */ + // It's a constant, and we can't use ImmutableMap here without creating a circular dependency. + @SuppressWarnings("ConstantCaseForConstants") private static final Map, Class> WRAPPER_TO_PRIMITIVE_TYPE; // Sad that we can't use a BiMap. :(