Use final.

This commit is contained in:
Gary Gregory 2022-03-04 08:49:14 -05:00
parent 2a2a534c02
commit 505722c303
9 changed files with 18 additions and 18 deletions

View File

@ -185,7 +185,7 @@ public class ListUtils {
* @see List#get(int)
* @since 4.5
*/
public static <T> T getFirst(List<T> list) {
public static <T> T getFirst(final List<T> list) {
return Objects.requireNonNull(list, "list").get(0);
}
@ -200,7 +200,7 @@ public class ListUtils {
* @see List#get(int)
* @since 4.5
*/
public static <T> T getLast(List<T> list) {
public static <T> T getLast(final List<T> list) {
return Objects.requireNonNull(list, "list").get(list.size() - 1);
}

View File

@ -50,7 +50,7 @@ public class EnumerationUtilsTest {
assertEquals("one", EnumerationUtils.get(en, 1));
// Enumerator, non-existent entry
Enumeration<String> finalEn = en;
final Enumeration<String> finalEn = en;
assertThrows(IndexOutOfBoundsException.class, () -> EnumerationUtils.get(finalEn, 3));
assertFalse(en.hasMoreElements());

View File

@ -185,7 +185,7 @@ public class TransformerUtilsTest {
assertEquals("A", TransformerUtils.chainedTransformer(b, a).transform(null));
assertEquals("B", TransformerUtils.chainedTransformer(a, b).transform(null));
assertEquals("A", TransformerUtils.chainedTransformer(b, a).transform(null));
Collection<Transformer<Object, Object>> coll = new ArrayList<>();
final Collection<Transformer<Object, Object>> coll = new ArrayList<>();
coll.add(b);
coll.add(a);
assertEquals("A", TransformerUtils.chainedTransformer(coll).transform(null));
@ -203,7 +203,7 @@ public class TransformerUtilsTest {
() -> assertThrows(NullPointerException.class, () -> TransformerUtils.chainedTransformer(null, null)),
() -> assertThrows(NullPointerException.class, () -> {
Collection<Transformer<Object, Object>> coll1 = new ArrayList<>();
final Collection<Transformer<Object, Object>> coll1 = new ArrayList<>();
coll1.add(null);
coll1.add(null);
TransformerUtils.chainedTransformer(coll1);
@ -400,7 +400,7 @@ public class TransformerUtilsTest {
Transformer<Class<?>, Object> trans = TransformerUtils.instantiateTransformer(new Class[] { Long.class }, new Object[] { null });
Transformer<Class<?>, Object> finalTrans = trans;
final Transformer<Class<?>, Object> finalTrans = trans;
assertThrows(FunctorException.class, () -> finalTrans.transform(String.class));
trans = TransformerUtils.instantiateTransformer();

View File

@ -46,7 +46,7 @@ public abstract class AbstractOrderedBidiMapTest<K, V> extends AbstractBidiMapTe
resetEmpty();
OrderedBidiMap<K, V> bidi = getMap();
OrderedBidiMap<K, V> finalBidi = bidi;
final OrderedBidiMap<K, V> finalBidi = bidi;
assertThrows(NoSuchElementException.class, () -> finalBidi.firstKey());
resetFull();
@ -59,7 +59,7 @@ public abstract class AbstractOrderedBidiMapTest<K, V> extends AbstractBidiMapTe
resetEmpty();
OrderedBidiMap<K, V> bidi = getMap();
OrderedBidiMap<K, V> finalBidi = bidi;
final OrderedBidiMap<K, V> finalBidi = bidi;
assertThrows(NoSuchElementException.class, () -> finalBidi.lastKey());
resetFull();
@ -95,7 +95,7 @@ public abstract class AbstractOrderedBidiMapTest<K, V> extends AbstractBidiMapTe
assertNull(bidi.nextKey(confirmedLast));
if (!isAllowNullKey()) {
OrderedBidiMap<K, V> finalBidi = bidi;
final OrderedBidiMap<K, V> finalBidi = bidi;
assertThrows(NullPointerException.class, () -> finalBidi.nextKey(null));
} else {
@ -129,7 +129,7 @@ public abstract class AbstractOrderedBidiMapTest<K, V> extends AbstractBidiMapTe
assertNull(bidi.previousKey(confirmedLast));
if (!isAllowNullKey()) {
OrderedBidiMap<K, V> finalBidi = bidi;
final OrderedBidiMap<K, V> finalBidi = bidi;
assertThrows(NullPointerException.class, () -> finalBidi.previousKey(null));
} else {

View File

@ -156,7 +156,7 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
public void testUnknownObjectBehavior() {
FixedOrderComparator<String> comparator = new FixedOrderComparator<>(topCities);
FixedOrderComparator<String> finalComparator = comparator;
final FixedOrderComparator<String> finalComparator = comparator;
assertThrows(IllegalArgumentException.class, () -> finalComparator.compare("New York", "Minneapolis"),
"Should have thrown a IllegalArgumentException");

View File

@ -71,18 +71,18 @@ public class CatchAndRethrowClosureTest extends AbstractClosureTest {
return Arrays.asList(
dynamicTest("Closure NoException", () -> {
Closure<Integer> closure = generateNoExceptionClosure();
final Closure<Integer> closure = generateNoExceptionClosure();
closure.execute(Integer.valueOf(0));
}),
dynamicTest("Closure IOException", () -> {
Closure<Integer> closure = generateIOExceptionClosure();
final Closure<Integer> closure = generateIOExceptionClosure();
final FunctorException thrown = assertThrows(FunctorException.class, () -> closure.execute(Integer.valueOf(0)));
assertTrue(thrown.getCause() instanceof IOException);
}),
dynamicTest("Closure NullPointerException", () -> {
Closure<Integer> closure = generateNullPointerExceptionClosure();
final Closure<Integer> closure = generateNullPointerExceptionClosure();
assertThrows(NullPointerException.class, () -> closure.execute(Integer.valueOf(0)));
})

View File

@ -105,7 +105,7 @@ public class ArrayListIteratorTest<E> extends ArrayIteratorTest<E> {
// a call to set() before a call to next() or previous() should throw an IllegalStateException
iter = makeArrayListIterator(testArray);
ListIterator<E> finalIter = iter;
final ListIterator<E> finalIter = iter;
assertThrows(IllegalStateException.class, () -> finalIter.set((E) "should fail"), "ListIterator#set should fail if next() or previous() have not yet been called.");
}

View File

@ -102,7 +102,7 @@ public class ObjectArrayListIteratorTest<E> extends ObjectArrayIteratorTest<E> {
// a call to set() before a call to next() or previous() should throw an IllegalStateException
iter = makeArrayListIterator((E[]) testArray);
ListIterator<E> finalIter = iter;
final ListIterator<E> finalIter = iter;
assertThrows(IllegalStateException.class, () -> finalIter.set((E) "should fail"), "ListIterator#set should fail if next() or previous() have not yet been called.");
}

View File

@ -394,13 +394,13 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
public void testUnsafeDeSerialization() throws Exception {
final MultiValueMap map1 = MultiValueMap.multiValueMap(new HashMap(), ArrayList.class);
byte[] bytes = serialize(map1);
Object result = deserialize(bytes);
final Object result = deserialize(bytes);
assertEquals(map1, result);
final MultiValueMap map2 = MultiValueMap.multiValueMap(new HashMap(), (Class) String.class);
bytes = serialize(map2);
byte[] finalBytes = bytes;
final byte[] finalBytes = bytes;
assertThrows(UnsupportedOperationException.class, () -> deserialize(finalBytes));
}