Use final.
This commit is contained in:
parent
2a2a534c02
commit
505722c303
|
@ -185,7 +185,7 @@ public class ListUtils {
|
||||||
* @see List#get(int)
|
* @see List#get(int)
|
||||||
* @since 4.5
|
* @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);
|
return Objects.requireNonNull(list, "list").get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ public class ListUtils {
|
||||||
* @see List#get(int)
|
* @see List#get(int)
|
||||||
* @since 4.5
|
* @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);
|
return Objects.requireNonNull(list, "list").get(list.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class EnumerationUtilsTest {
|
||||||
assertEquals("one", EnumerationUtils.get(en, 1));
|
assertEquals("one", EnumerationUtils.get(en, 1));
|
||||||
|
|
||||||
// Enumerator, non-existent entry
|
// Enumerator, non-existent entry
|
||||||
Enumeration<String> finalEn = en;
|
final Enumeration<String> finalEn = en;
|
||||||
assertThrows(IndexOutOfBoundsException.class, () -> EnumerationUtils.get(finalEn, 3));
|
assertThrows(IndexOutOfBoundsException.class, () -> EnumerationUtils.get(finalEn, 3));
|
||||||
|
|
||||||
assertFalse(en.hasMoreElements());
|
assertFalse(en.hasMoreElements());
|
||||||
|
|
|
@ -185,7 +185,7 @@ public class TransformerUtilsTest {
|
||||||
assertEquals("A", TransformerUtils.chainedTransformer(b, a).transform(null));
|
assertEquals("A", TransformerUtils.chainedTransformer(b, a).transform(null));
|
||||||
assertEquals("B", TransformerUtils.chainedTransformer(a, b).transform(null));
|
assertEquals("B", TransformerUtils.chainedTransformer(a, b).transform(null));
|
||||||
assertEquals("A", TransformerUtils.chainedTransformer(b, a).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(b);
|
||||||
coll.add(a);
|
coll.add(a);
|
||||||
assertEquals("A", TransformerUtils.chainedTransformer(coll).transform(null));
|
assertEquals("A", TransformerUtils.chainedTransformer(coll).transform(null));
|
||||||
|
@ -203,7 +203,7 @@ public class TransformerUtilsTest {
|
||||||
() -> assertThrows(NullPointerException.class, () -> TransformerUtils.chainedTransformer(null, null)),
|
() -> assertThrows(NullPointerException.class, () -> TransformerUtils.chainedTransformer(null, null)),
|
||||||
|
|
||||||
() -> assertThrows(NullPointerException.class, () -> {
|
() -> assertThrows(NullPointerException.class, () -> {
|
||||||
Collection<Transformer<Object, Object>> coll1 = new ArrayList<>();
|
final Collection<Transformer<Object, Object>> coll1 = new ArrayList<>();
|
||||||
coll1.add(null);
|
coll1.add(null);
|
||||||
coll1.add(null);
|
coll1.add(null);
|
||||||
TransformerUtils.chainedTransformer(coll1);
|
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> 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));
|
assertThrows(FunctorException.class, () -> finalTrans.transform(String.class));
|
||||||
|
|
||||||
trans = TransformerUtils.instantiateTransformer();
|
trans = TransformerUtils.instantiateTransformer();
|
||||||
|
|
|
@ -46,7 +46,7 @@ public abstract class AbstractOrderedBidiMapTest<K, V> extends AbstractBidiMapTe
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
OrderedBidiMap<K, V> bidi = getMap();
|
OrderedBidiMap<K, V> bidi = getMap();
|
||||||
|
|
||||||
OrderedBidiMap<K, V> finalBidi = bidi;
|
final OrderedBidiMap<K, V> finalBidi = bidi;
|
||||||
assertThrows(NoSuchElementException.class, () -> finalBidi.firstKey());
|
assertThrows(NoSuchElementException.class, () -> finalBidi.firstKey());
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
|
@ -59,7 +59,7 @@ public abstract class AbstractOrderedBidiMapTest<K, V> extends AbstractBidiMapTe
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
OrderedBidiMap<K, V> bidi = getMap();
|
OrderedBidiMap<K, V> bidi = getMap();
|
||||||
|
|
||||||
OrderedBidiMap<K, V> finalBidi = bidi;
|
final OrderedBidiMap<K, V> finalBidi = bidi;
|
||||||
assertThrows(NoSuchElementException.class, () -> finalBidi.lastKey());
|
assertThrows(NoSuchElementException.class, () -> finalBidi.lastKey());
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
|
@ -95,7 +95,7 @@ public abstract class AbstractOrderedBidiMapTest<K, V> extends AbstractBidiMapTe
|
||||||
assertNull(bidi.nextKey(confirmedLast));
|
assertNull(bidi.nextKey(confirmedLast));
|
||||||
|
|
||||||
if (!isAllowNullKey()) {
|
if (!isAllowNullKey()) {
|
||||||
OrderedBidiMap<K, V> finalBidi = bidi;
|
final OrderedBidiMap<K, V> finalBidi = bidi;
|
||||||
assertThrows(NullPointerException.class, () -> finalBidi.nextKey(null));
|
assertThrows(NullPointerException.class, () -> finalBidi.nextKey(null));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -129,7 +129,7 @@ public abstract class AbstractOrderedBidiMapTest<K, V> extends AbstractBidiMapTe
|
||||||
assertNull(bidi.previousKey(confirmedLast));
|
assertNull(bidi.previousKey(confirmedLast));
|
||||||
|
|
||||||
if (!isAllowNullKey()) {
|
if (!isAllowNullKey()) {
|
||||||
OrderedBidiMap<K, V> finalBidi = bidi;
|
final OrderedBidiMap<K, V> finalBidi = bidi;
|
||||||
assertThrows(NullPointerException.class, () -> finalBidi.previousKey(null));
|
assertThrows(NullPointerException.class, () -> finalBidi.previousKey(null));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -156,7 +156,7 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
|
||||||
public void testUnknownObjectBehavior() {
|
public void testUnknownObjectBehavior() {
|
||||||
FixedOrderComparator<String> comparator = new FixedOrderComparator<>(topCities);
|
FixedOrderComparator<String> comparator = new FixedOrderComparator<>(topCities);
|
||||||
|
|
||||||
FixedOrderComparator<String> finalComparator = comparator;
|
final FixedOrderComparator<String> finalComparator = comparator;
|
||||||
assertThrows(IllegalArgumentException.class, () -> finalComparator.compare("New York", "Minneapolis"),
|
assertThrows(IllegalArgumentException.class, () -> finalComparator.compare("New York", "Minneapolis"),
|
||||||
"Should have thrown a IllegalArgumentException");
|
"Should have thrown a IllegalArgumentException");
|
||||||
|
|
||||||
|
|
|
@ -71,18 +71,18 @@ public class CatchAndRethrowClosureTest extends AbstractClosureTest {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
|
|
||||||
dynamicTest("Closure NoException", () -> {
|
dynamicTest("Closure NoException", () -> {
|
||||||
Closure<Integer> closure = generateNoExceptionClosure();
|
final Closure<Integer> closure = generateNoExceptionClosure();
|
||||||
closure.execute(Integer.valueOf(0));
|
closure.execute(Integer.valueOf(0));
|
||||||
}),
|
}),
|
||||||
|
|
||||||
dynamicTest("Closure IOException", () -> {
|
dynamicTest("Closure IOException", () -> {
|
||||||
Closure<Integer> closure = generateIOExceptionClosure();
|
final Closure<Integer> closure = generateIOExceptionClosure();
|
||||||
final FunctorException thrown = assertThrows(FunctorException.class, () -> closure.execute(Integer.valueOf(0)));
|
final FunctorException thrown = assertThrows(FunctorException.class, () -> closure.execute(Integer.valueOf(0)));
|
||||||
assertTrue(thrown.getCause() instanceof IOException);
|
assertTrue(thrown.getCause() instanceof IOException);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
dynamicTest("Closure NullPointerException", () -> {
|
dynamicTest("Closure NullPointerException", () -> {
|
||||||
Closure<Integer> closure = generateNullPointerExceptionClosure();
|
final Closure<Integer> closure = generateNullPointerExceptionClosure();
|
||||||
assertThrows(NullPointerException.class, () -> closure.execute(Integer.valueOf(0)));
|
assertThrows(NullPointerException.class, () -> closure.execute(Integer.valueOf(0)));
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -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
|
// a call to set() before a call to next() or previous() should throw an IllegalStateException
|
||||||
iter = makeArrayListIterator(testArray);
|
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.");
|
assertThrows(IllegalStateException.class, () -> finalIter.set((E) "should fail"), "ListIterator#set should fail if next() or previous() have not yet been called.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
// a call to set() before a call to next() or previous() should throw an IllegalStateException
|
||||||
iter = makeArrayListIterator((E[]) testArray);
|
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.");
|
assertThrows(IllegalStateException.class, () -> finalIter.set((E) "should fail"), "ListIterator#set should fail if next() or previous() have not yet been called.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -394,13 +394,13 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
|
||||||
public void testUnsafeDeSerialization() throws Exception {
|
public void testUnsafeDeSerialization() throws Exception {
|
||||||
final MultiValueMap map1 = MultiValueMap.multiValueMap(new HashMap(), ArrayList.class);
|
final MultiValueMap map1 = MultiValueMap.multiValueMap(new HashMap(), ArrayList.class);
|
||||||
byte[] bytes = serialize(map1);
|
byte[] bytes = serialize(map1);
|
||||||
Object result = deserialize(bytes);
|
final Object result = deserialize(bytes);
|
||||||
assertEquals(map1, result);
|
assertEquals(map1, result);
|
||||||
|
|
||||||
final MultiValueMap map2 = MultiValueMap.multiValueMap(new HashMap(), (Class) String.class);
|
final MultiValueMap map2 = MultiValueMap.multiValueMap(new HashMap(), (Class) String.class);
|
||||||
bytes = serialize(map2);
|
bytes = serialize(map2);
|
||||||
|
|
||||||
byte[] finalBytes = bytes;
|
final byte[] finalBytes = bytes;
|
||||||
assertThrows(UnsupportedOperationException.class, () -> deserialize(finalBytes));
|
assertThrows(UnsupportedOperationException.class, () -> deserialize(finalBytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue