Use final.

This commit is contained in:
Gary Gregory 2020-11-20 22:12:25 -05:00
parent d5196e7fe4
commit 764b9bba52
8 changed files with 27 additions and 27 deletions

View File

@ -7869,7 +7869,7 @@ public static void shuffle(final short[] array, final Random random) {
* @see Arrays#sort(Object[])
* @since 3.12
*/
public static <T> T[] sort(T[] array) {
public static <T> T[] sort(final T[] array) {
Arrays.sort(array);
return array;
}
@ -7885,7 +7885,7 @@ public static <T> T[] sort(T[] array) {
* @see Arrays#sort(Object[])
* @since 3.12
*/
public static <T> T[] sort(T[] array, Comparator<? super T> comparator) {
public static <T> T[] sort(final T[] array, final Comparator<? super T> comparator) {
Arrays.sort(array, comparator);
return array;
}

View File

@ -166,7 +166,7 @@ public static long nextLong() {
* @return a random {@code long} value between 0 (inclusive) and {@code n}
* (exclusive).
*/
private static long nextLong(long n) {
private static long nextLong(final long n) {
// Extracted from o.a.c.rng.core.BaseProvider.nextLong(long)
long bits;
long val;

View File

@ -118,7 +118,7 @@ public static class LockVisitor<O, L> {
* @param readLockSupplier Supplies the read lock, usually from the lock object.
* @param writeLockSupplier Supplies the write lock, usually from the lock object.
*/
protected LockVisitor(final O object, L lock, Supplier<Lock> readLockSupplier, Supplier<Lock> writeLockSupplier) {
protected LockVisitor(final O object, final L lock, final Supplier<Lock> readLockSupplier, final Supplier<Lock> writeLockSupplier) {
this.object = Objects.requireNonNull(object, "object");
this.lock = Objects.requireNonNull(lock, "lock");
this.readLockSupplier = Objects.requireNonNull(readLockSupplier, "readLockSupplier");
@ -143,7 +143,7 @@ protected LockVisitor(final O object, L lock, Supplier<Lock> readLockSupplier, S
* @see #acceptWriteLocked(FailableConsumer)
* @see #applyReadLocked(FailableFunction)
*/
public void acceptReadLocked(FailableConsumer<O, ?> consumer) {
public void acceptReadLocked(final FailableConsumer<O, ?> consumer) {
lockAcceptUnlock(readLockSupplier, consumer);
}
@ -205,7 +205,7 @@ public void acceptWriteLocked(final FailableConsumer<O, ?> consumer) {
* @see #acceptReadLocked(FailableConsumer)
* @see #applyWriteLocked(FailableFunction)
*/
public <T> T applyReadLocked(FailableFunction<O, T, ?> function) {
public <T> T applyReadLocked(final FailableFunction<O, T, ?> function) {
return lockApplyUnlock(readLockSupplier, function);
}
@ -271,7 +271,7 @@ protected void lockAcceptUnlock(final Supplier<Lock> lockSupplier, final Failabl
lock.lock();
try {
consumer.accept(object);
} catch (Throwable t) {
} catch (final Throwable t) {
throw Failable.rethrow(t);
} finally {
lock.unlock();
@ -298,7 +298,7 @@ protected <T> T lockApplyUnlock(final Supplier<Lock> lockSupplier, final Failabl
lock.lock();
try {
return function.apply(object);
} catch (Throwable t) {
} catch (final Throwable t) {
throw Failable.rethrow(t);
} finally {
lock.unlock();
@ -348,7 +348,7 @@ public static class StampedLockVisitor<O> extends LockVisitor<O, StampedLock> {
* @param object The locked (hidden) object. The caller is supposed to drop all references to the locked object.
* @param stampedLock the lock to use.
*/
protected StampedLockVisitor(final O object, StampedLock stampedLock) {
protected StampedLockVisitor(final O object, final StampedLock stampedLock) {
super(object, stampedLock, stampedLock::asReadLock, stampedLock::asWriteLock);
}
}

View File

@ -59,8 +59,8 @@ public interface TriFunction<T, U, V, R> {
* @return a composed function that first applies this function and then applies the {@code after} function
* @throws NullPointerException if after is null
*/
default <W> TriFunction<T, U, V, W> andThen(Function<? super R, ? extends W> after) {
default <W> TriFunction<T, U, V, W> andThen(final Function<? super R, ? extends W> after) {
Objects.requireNonNull(after);
return (T t, U u, V v) -> after.apply(apply(t, u, v));
return (final T t, final U u, final V v) -> after.apply(apply(t, u, v));
}
}

View File

@ -278,7 +278,7 @@ public void testContainsDouble() {
@Test
public void testContainsDoubleNaN() {
double[] a = new double[] { Double.NEGATIVE_INFINITY, Double.NaN, Double.POSITIVE_INFINITY };
final double[] a = new double[] { Double.NEGATIVE_INFINITY, Double.NaN, Double.POSITIVE_INFINITY };
assertTrue(ArrayUtils.contains(a, Double.POSITIVE_INFINITY));
assertTrue(ArrayUtils.contains(a, Double.NEGATIVE_INFINITY));
assertTrue(ArrayUtils.contains(a, Double.NaN));
@ -311,7 +311,7 @@ public void testContainsFloat() {
@Test
public void testContainsFloatNaN() {
float[] array = new float[] { Float.NEGATIVE_INFINITY, Float.NaN, Float.POSITIVE_INFINITY };
final float[] array = new float[] { Float.NEGATIVE_INFINITY, Float.NaN, Float.POSITIVE_INFINITY };
assertTrue(ArrayUtils.contains(array, Float.POSITIVE_INFINITY));
assertTrue(ArrayUtils.contains(array, Float.NEGATIVE_INFINITY));
assertTrue(ArrayUtils.contains(array, Float.NaN));
@ -1062,7 +1062,7 @@ public void testIndexOfDouble() {
@Test
public void testIndexOfDoubleNaN() {
double[] array = new double[] { Double.NEGATIVE_INFINITY, Double.NaN, Double.POSITIVE_INFINITY, Double.NaN };
final double[] array = new double[] { Double.NEGATIVE_INFINITY, Double.NaN, Double.POSITIVE_INFINITY, Double.NaN };
assertEquals(0, ArrayUtils.indexOf(array, Double.NEGATIVE_INFINITY));
assertEquals(1, ArrayUtils.indexOf(array, Double.NaN));
assertEquals(2, ArrayUtils.indexOf(array, Double.POSITIVE_INFINITY));
@ -1134,7 +1134,7 @@ public void testIndexOfFloat() {
@Test
public void testIndexOfFloatNaN() {
float[] array = new float[] { Float.NEGATIVE_INFINITY, Float.NaN, Float.POSITIVE_INFINITY, Float.NaN };
final float[] array = new float[] { Float.NEGATIVE_INFINITY, Float.NaN, Float.POSITIVE_INFINITY, Float.NaN };
assertEquals(0, ArrayUtils.indexOf(array, Float.NEGATIVE_INFINITY));
assertEquals(1, ArrayUtils.indexOf(array, Float.NaN));
assertEquals(2, ArrayUtils.indexOf(array, Float.POSITIVE_INFINITY));

View File

@ -268,8 +268,8 @@ public void testNewLastIndexOf() {
@ParameterizedTest
@MethodSource("lastIndexWithStandardCharSequence")
public void testLastIndexOfWithDifferentCharSequences(CharSequence cs, CharSequence search, int start,
int expected) {
public void testLastIndexOfWithDifferentCharSequences(final CharSequence cs, final CharSequence search, final int start,
final int expected) {
assertEquals(expected, CharSequenceUtils.lastIndexOf(cs, search, start));
}

View File

@ -181,7 +181,7 @@ public void testGetAllFields() {
assertEquals(expected, allFields.length, Arrays.toString(allFields));
}
private Field[] sort(Field[] fields) {
private Field[] sort(final Field[] fields) {
// Field does not implement Comparable, so we use a KISS solution here.
return ArrayUtils.sort(fields, ObjectToStringComparator.INSTANCE);
}

View File

@ -739,18 +739,18 @@ public void testIsAssignable() throws SecurityException, NoSuchMethodException,
assertTrue(TypeUtils.isAssignable(fClassType, eClassType));
}
private void testIsAssignable(Class testUnassignableClass) {
private void testIsAssignable(final Class testUnassignableClass) {
final Class<Constructor> rawClass = Constructor.class;
final Class<Insets> typeArgClass = Insets.class;
// Builds a ParameterizedType for Constructor<Insets>
ParameterizedType paramType = TypeUtils.parameterize(rawClass, typeArgClass);
final ParameterizedType paramType = TypeUtils.parameterize(rawClass, typeArgClass);
assertEquals(rawClass, paramType.getRawType());
assertEquals(typeArgClass, paramType.getActualTypeArguments()[0]);
assertFalse(testUnassignableClass.isAssignableFrom(paramType.getClass()));
assertFalse(paramType.getClass().isAssignableFrom(testUnassignableClass));
GenericArrayType arrayType = TypeUtils.genericArrayType(paramType);
final GenericArrayType arrayType = TypeUtils.genericArrayType(paramType);
assertFalse(TypeUtils.isAssignable(arrayType, paramType),
() -> String.format("TypeUtils.isAssignable(%s, %s)", arrayType, paramType));
assertFalse(TypeUtils.isAssignable(paramType, arrayType),
@ -762,14 +762,14 @@ public void testIsAssignableGenericArrayTypeToParameterizedType() {
final Class<Constructor> rawClass = Constructor.class;
final Class<Insets> typeArgClass = Insets.class;
// Builds a ParameterizedType for Constructor<Insets>
ParameterizedType paramType = TypeUtils.parameterize(rawClass, typeArgClass);
final ParameterizedType paramType = TypeUtils.parameterize(rawClass, typeArgClass);
assertEquals(rawClass, paramType.getRawType());
assertEquals(typeArgClass, paramType.getActualTypeArguments()[0]);
assertFalse(GenericArrayType.class.isAssignableFrom(paramType.getClass()));
assertFalse(paramType.getClass().isAssignableFrom(GenericArrayType.class));
GenericArrayType testType = TypeUtils.genericArrayType(paramType);
final GenericArrayType testType = TypeUtils.genericArrayType(paramType);
assertFalse(TypeUtils.isAssignable(paramType, testType),
() -> String.format("TypeUtils.isAssignable(%s, %s)", paramType, testType));
assertFalse(TypeUtils.isAssignable(testType, paramType),
@ -782,14 +782,14 @@ public void testIsAssignableGenericArrayTypeToWildercardType() {
final Class<Constructor> rawClass = Constructor.class;
final Class<Insets> typeArgClass = Insets.class;
// Builds a ParameterizedType for Constructor<Insets>
ParameterizedType paramType = TypeUtils.parameterize(rawClass, typeArgClass);
final ParameterizedType paramType = TypeUtils.parameterize(rawClass, typeArgClass);
assertEquals(rawClass, paramType.getRawType());
assertEquals(typeArgClass, paramType.getActualTypeArguments()[0]);
assertFalse(WildcardType.class.isAssignableFrom(paramType.getClass()));
assertFalse(paramType.getClass().isAssignableFrom(WildcardType.class));
WildcardType testType = TypeUtils.WILDCARD_ALL;
final WildcardType testType = TypeUtils.WILDCARD_ALL;
// TODO This test returns true unlike the test above.
// Is this a bug in this test or in the main code?
assertFalse(TypeUtils.isAssignable(paramType, testType),
@ -803,14 +803,14 @@ public void testIsAssignableGenericArrayTypeToObject() {
final Class<Constructor> rawClass = Constructor.class;
final Class<Insets> typeArgClass = Insets.class;
// Builds a ParameterizedType for Constructor<Insets>
ParameterizedType paramType = TypeUtils.parameterize(rawClass, typeArgClass);
final ParameterizedType paramType = TypeUtils.parameterize(rawClass, typeArgClass);
assertEquals(rawClass, paramType.getRawType());
assertEquals(typeArgClass, paramType.getActualTypeArguments()[0]);
assertTrue(Object.class.isAssignableFrom(paramType.getClass()));
assertFalse(paramType.getClass().isAssignableFrom(Object.class));
Type testType = Object.class;
final Type testType = Object.class;
assertTrue(TypeUtils.isAssignable(paramType, testType),
() -> String.format("TypeUtils.isAssignable(%s, %s)", paramType, testType));
assertFalse(TypeUtils.isAssignable(testType, paramType),