From 505722c303e78e4f6bdd36f55940cd4659d3219c Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 4 Mar 2022 08:49:14 -0500 Subject: [PATCH] Use final. --- .../java/org/apache/commons/collections4/ListUtils.java | 4 ++-- .../apache/commons/collections4/EnumerationUtilsTest.java | 2 +- .../apache/commons/collections4/TransformerUtilsTest.java | 6 +++--- .../collections4/bidimap/AbstractOrderedBidiMapTest.java | 8 ++++---- .../comparators/FixedOrderComparatorTest.java | 2 +- .../collections4/functors/CatchAndRethrowClosureTest.java | 6 +++--- .../collections4/iterators/ArrayListIteratorTest.java | 2 +- .../iterators/ObjectArrayListIteratorTest.java | 2 +- .../commons/collections4/map/MultiValueMapTest.java | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/apache/commons/collections4/ListUtils.java b/src/main/java/org/apache/commons/collections4/ListUtils.java index 53dea6889..6b518d246 100644 --- a/src/main/java/org/apache/commons/collections4/ListUtils.java +++ b/src/main/java/org/apache/commons/collections4/ListUtils.java @@ -185,7 +185,7 @@ public class ListUtils { * @see List#get(int) * @since 4.5 */ - public static T getFirst(List list) { + public static T getFirst(final List 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 getLast(List list) { + public static T getLast(final List list) { return Objects.requireNonNull(list, "list").get(list.size() - 1); } diff --git a/src/test/java/org/apache/commons/collections4/EnumerationUtilsTest.java b/src/test/java/org/apache/commons/collections4/EnumerationUtilsTest.java index 9c8dca49d..c70816771 100644 --- a/src/test/java/org/apache/commons/collections4/EnumerationUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/EnumerationUtilsTest.java @@ -50,7 +50,7 @@ public class EnumerationUtilsTest { assertEquals("one", EnumerationUtils.get(en, 1)); // Enumerator, non-existent entry - Enumeration finalEn = en; + final Enumeration finalEn = en; assertThrows(IndexOutOfBoundsException.class, () -> EnumerationUtils.get(finalEn, 3)); assertFalse(en.hasMoreElements()); diff --git a/src/test/java/org/apache/commons/collections4/TransformerUtilsTest.java b/src/test/java/org/apache/commons/collections4/TransformerUtilsTest.java index 3d303ca03..3bac7fd45 100644 --- a/src/test/java/org/apache/commons/collections4/TransformerUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/TransformerUtilsTest.java @@ -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> coll = new ArrayList<>(); + final Collection> 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> coll1 = new ArrayList<>(); + final Collection> coll1 = new ArrayList<>(); coll1.add(null); coll1.add(null); TransformerUtils.chainedTransformer(coll1); @@ -400,7 +400,7 @@ public class TransformerUtilsTest { Transformer, Object> trans = TransformerUtils.instantiateTransformer(new Class[] { Long.class }, new Object[] { null }); - Transformer, Object> finalTrans = trans; + final Transformer, Object> finalTrans = trans; assertThrows(FunctorException.class, () -> finalTrans.transform(String.class)); trans = TransformerUtils.instantiateTransformer(); diff --git a/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java b/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java index bab1837a9..69dfce43c 100644 --- a/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java +++ b/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java @@ -46,7 +46,7 @@ public abstract class AbstractOrderedBidiMapTest extends AbstractBidiMapTe resetEmpty(); OrderedBidiMap bidi = getMap(); - OrderedBidiMap finalBidi = bidi; + final OrderedBidiMap finalBidi = bidi; assertThrows(NoSuchElementException.class, () -> finalBidi.firstKey()); resetFull(); @@ -59,7 +59,7 @@ public abstract class AbstractOrderedBidiMapTest extends AbstractBidiMapTe resetEmpty(); OrderedBidiMap bidi = getMap(); - OrderedBidiMap finalBidi = bidi; + final OrderedBidiMap finalBidi = bidi; assertThrows(NoSuchElementException.class, () -> finalBidi.lastKey()); resetFull(); @@ -95,7 +95,7 @@ public abstract class AbstractOrderedBidiMapTest extends AbstractBidiMapTe assertNull(bidi.nextKey(confirmedLast)); if (!isAllowNullKey()) { - OrderedBidiMap finalBidi = bidi; + final OrderedBidiMap finalBidi = bidi; assertThrows(NullPointerException.class, () -> finalBidi.nextKey(null)); } else { @@ -129,7 +129,7 @@ public abstract class AbstractOrderedBidiMapTest extends AbstractBidiMapTe assertNull(bidi.previousKey(confirmedLast)); if (!isAllowNullKey()) { - OrderedBidiMap finalBidi = bidi; + final OrderedBidiMap finalBidi = bidi; assertThrows(NullPointerException.class, () -> finalBidi.previousKey(null)); } else { diff --git a/src/test/java/org/apache/commons/collections4/comparators/FixedOrderComparatorTest.java b/src/test/java/org/apache/commons/collections4/comparators/FixedOrderComparatorTest.java index db24b1ba0..06fc35287 100644 --- a/src/test/java/org/apache/commons/collections4/comparators/FixedOrderComparatorTest.java +++ b/src/test/java/org/apache/commons/collections4/comparators/FixedOrderComparatorTest.java @@ -156,7 +156,7 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest { public void testUnknownObjectBehavior() { FixedOrderComparator comparator = new FixedOrderComparator<>(topCities); - FixedOrderComparator finalComparator = comparator; + final FixedOrderComparator finalComparator = comparator; assertThrows(IllegalArgumentException.class, () -> finalComparator.compare("New York", "Minneapolis"), "Should have thrown a IllegalArgumentException"); diff --git a/src/test/java/org/apache/commons/collections4/functors/CatchAndRethrowClosureTest.java b/src/test/java/org/apache/commons/collections4/functors/CatchAndRethrowClosureTest.java index dd35e7e3b..96381aebe 100644 --- a/src/test/java/org/apache/commons/collections4/functors/CatchAndRethrowClosureTest.java +++ b/src/test/java/org/apache/commons/collections4/functors/CatchAndRethrowClosureTest.java @@ -71,18 +71,18 @@ public class CatchAndRethrowClosureTest extends AbstractClosureTest { return Arrays.asList( dynamicTest("Closure NoException", () -> { - Closure closure = generateNoExceptionClosure(); + final Closure closure = generateNoExceptionClosure(); closure.execute(Integer.valueOf(0)); }), dynamicTest("Closure IOException", () -> { - Closure closure = generateIOExceptionClosure(); + final Closure closure = generateIOExceptionClosure(); final FunctorException thrown = assertThrows(FunctorException.class, () -> closure.execute(Integer.valueOf(0))); assertTrue(thrown.getCause() instanceof IOException); }), dynamicTest("Closure NullPointerException", () -> { - Closure closure = generateNullPointerExceptionClosure(); + final Closure closure = generateNullPointerExceptionClosure(); assertThrows(NullPointerException.class, () -> closure.execute(Integer.valueOf(0))); }) diff --git a/src/test/java/org/apache/commons/collections4/iterators/ArrayListIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/ArrayListIteratorTest.java index 2f5a7143a..5ba352bd9 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/ArrayListIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/ArrayListIteratorTest.java @@ -105,7 +105,7 @@ public class ArrayListIteratorTest extends ArrayIteratorTest { // a call to set() before a call to next() or previous() should throw an IllegalStateException iter = makeArrayListIterator(testArray); - ListIterator finalIter = iter; + final ListIterator finalIter = iter; assertThrows(IllegalStateException.class, () -> finalIter.set((E) "should fail"), "ListIterator#set should fail if next() or previous() have not yet been called."); } diff --git a/src/test/java/org/apache/commons/collections4/iterators/ObjectArrayListIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/ObjectArrayListIteratorTest.java index 500ac9085..2875db057 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/ObjectArrayListIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/ObjectArrayListIteratorTest.java @@ -102,7 +102,7 @@ public class ObjectArrayListIteratorTest extends ObjectArrayIteratorTest { // a call to set() before a call to next() or previous() should throw an IllegalStateException iter = makeArrayListIterator((E[]) testArray); - ListIterator finalIter = iter; + final ListIterator finalIter = iter; assertThrows(IllegalStateException.class, () -> finalIter.set((E) "should fail"), "ListIterator#set should fail if next() or previous() have not yet been called."); } diff --git a/src/test/java/org/apache/commons/collections4/map/MultiValueMapTest.java b/src/test/java/org/apache/commons/collections4/map/MultiValueMapTest.java index 3fbda3e5e..35fa6e51a 100644 --- a/src/test/java/org/apache/commons/collections4/map/MultiValueMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/MultiValueMapTest.java @@ -394,13 +394,13 @@ public class MultiValueMapTest 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)); }