This commit is contained in:
Jochen Wiedmann 2020-02-14 22:32:54 +01:00
commit ee87df8472
53 changed files with 326 additions and 305 deletions

View File

@ -1,5 +1,5 @@
Apache Commons Lang
Copyright 2001-2019 The Apache Software Foundation
Copyright 2001-2020 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).

View File

@ -516,13 +516,13 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.5.2</version>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit-pioneer</groupId>
<artifactId>junit-pioneer</artifactId>
<version>0.4.2</version>
<version>0.5.3</version>
<scope>test</scope>
</dependency>
<dependency>
@ -535,7 +535,7 @@
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>4.1</version>
<version>4.2</version>
<scope>test</scope>
</dependency>
@ -764,7 +764,7 @@
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>4.0.0-beta4</version>
<version>4.0.0-RC3</version>
</dependency>
</dependencies>
<configuration>

View File

@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove.
<body>
<release version="3.10" date="YYYY-MM-DD" description="New features and bug fixes. Requires Java 8, supports Java 9, 10, 11.">
<action issue="LANG-1514" type="fix" dev="kinow" due-to="contextshuffling">Make test more stable by wrapping assertions in hashset.</action>
<action issue="LANG-1450" type="fix" dev="chtompki">Generate Javadoc jar on build.</action>
<action issue="LANG-1457" type="add" dev="ggregory">Add ExceptionUtils.throwableOfType(Throwable, Class) and friends.</action>
<action issue="LANG-1458" type="add" dev="ggregory">Add EMPTY_ARRAY constants to classes in org.apache.commons.lang3.tuple.</action>
@ -96,6 +97,9 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="LANG-1512" type="add" dev="ggregory" due-to="Gary Gregory">Add IS_JAVA_14 and IS_JAVA_15 to org.apache.commons.lang3.SystemUtils.</action>
<action issue="LANG-1513" type="add" dev="ggregory" due-to="Bernhard Bonigl, Gary Gregory">ObjectUtils: Get first non-null supplier value.</action>
<action type="add" dev="jochen">Added the Streams class, and Functions.stream() as an accessor thereof.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">org.easymock:easymock 4.1 -> 4.2.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">org.junit-pioneer:junit-pioneer 0.4.2 -> 0.5.3.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">org.junit.jupiter:junit-jupiter 5.5.2 -> 5.6.0.</action>
</release>
<release version="3.9" date="2019-04-09" description="New features and bug fixes. Requires Java 8, supports Java 9, 10, 11.">

View File

@ -1727,7 +1727,7 @@ public static BitSet indexesOf(final boolean[] array, final boolean valueToFind)
* @since 3.10
*/
public static BitSet indexesOf(final boolean[] array, final boolean valueToFind, int startIndex) {
BitSet bitSet = new BitSet();
final BitSet bitSet = new BitSet();
if (array == null) {
return bitSet;
@ -1778,7 +1778,7 @@ public static BitSet indexesOf(final byte[] array, final byte valueToFind) {
* @since 3.10
*/
public static BitSet indexesOf(final byte[] array, final byte valueToFind, int startIndex) {
BitSet bitSet = new BitSet();
final BitSet bitSet = new BitSet();
if (array == null) {
return bitSet;
@ -1829,7 +1829,7 @@ public static BitSet indexesOf(final char[] array, final char valueToFind) {
* @since 3.10
*/
public static BitSet indexesOf(final char[] array, final char valueToFind, int startIndex) {
BitSet bitSet = new BitSet();
final BitSet bitSet = new BitSet();
if (array == null) {
return bitSet;
@ -1901,7 +1901,7 @@ public static BitSet indexesOf(final double[] array, final double valueToFind, f
* @since 3.10
*/
public static BitSet indexesOf(final double[] array, final double valueToFind, int startIndex) {
BitSet bitSet = new BitSet();
final BitSet bitSet = new BitSet();
if (array == null) {
return bitSet;
@ -1943,7 +1943,7 @@ public static BitSet indexesOf(final double[] array, final double valueToFind, i
* @since 3.10
*/
public static BitSet indexesOf(final double[] array, final double valueToFind, int startIndex, final double tolerance) {
BitSet bitSet = new BitSet();
final BitSet bitSet = new BitSet();
if (array == null) {
return bitSet;
@ -1994,7 +1994,7 @@ public static BitSet indexesOf(final float[] array, final float valueToFind) {
* @since 3.10
*/
public static BitSet indexesOf(final float[] array, final float valueToFind, int startIndex) {
BitSet bitSet = new BitSet();
final BitSet bitSet = new BitSet();
if (array == null) {
return bitSet;
@ -2045,7 +2045,7 @@ public static BitSet indexesOf(final int[] array, final int valueToFind) {
* @since 3.10
*/
public static BitSet indexesOf(final int[] array, final int valueToFind, int startIndex) {
BitSet bitSet = new BitSet();
final BitSet bitSet = new BitSet();
if (array == null) {
return bitSet;
@ -2096,7 +2096,7 @@ public static BitSet indexesOf(final long[] array, final long valueToFind) {
* @since 3.10
*/
public static BitSet indexesOf(final long[] array, final long valueToFind, int startIndex) {
BitSet bitSet = new BitSet();
final BitSet bitSet = new BitSet();
if (array == null) {
return bitSet;
@ -2147,7 +2147,7 @@ public static BitSet indexesOf(final Object[] array, final Object objectToFind)
* @since 3.10
*/
public static BitSet indexesOf(final Object[] array, final Object objectToFind, int startIndex) {
BitSet bitSet = new BitSet();
final BitSet bitSet = new BitSet();
if (array == null) {
return bitSet;
@ -2198,7 +2198,7 @@ public static BitSet indexesOf(final short[] array, final short valueToFind) {
* @since 3.10
*/
public static BitSet indexesOf(final short[] array, final short valueToFind, int startIndex) {
BitSet bitSet = new BitSet();
final BitSet bitSet = new BitSet();
if (array == null) {
return bitSet;
@ -3084,7 +3084,7 @@ public static <T> T[] insert(final int index, final T[] array, final T... values
* @return Whether the given index is safely-accessible in the given array
* @since 3.8
*/
public static <T> boolean isArrayIndexValid(T[] array, int index) {
public static <T> boolean isArrayIndexValid(final T[] array, final int index) {
if (getLength(array) == 0 || array.length <= index) {
return false;
}

View File

@ -271,7 +271,7 @@ private static class CharacterIterator implements Iterator<Character> {
private boolean hasNext;
/**
* Construct a new iterator for the character range.
* Constructs a new iterator for the character range.
*
* @param r The character range
*/
@ -296,7 +296,7 @@ private CharacterIterator(final CharRange r) {
}
/**
* Prepare the next character in the range.
* Prepares the next character in the range.
*/
private void prepareNext() {
if (range.negated) {
@ -329,7 +329,7 @@ public boolean hasNext() {
}
/**
* Return the next character in the iteration
* Returns the next character in the iteration
*
* @return {@code Character} for the next character
*/
@ -346,7 +346,7 @@ public Character next() {
/**
* Always throws UnsupportedOperationException.
*
* @throws UnsupportedOperationException
* @throws UnsupportedOperationException Always thrown.
* @see java.util.Iterator#remove()
*/
@Override

View File

@ -50,7 +50,12 @@ public class ClassUtils {
* @since 3.2
*/
public enum Interfaces {
INCLUDE, EXCLUDE
/** Includes interfaces. */
INCLUDE,
/** Excludes interfaces. */
EXCLUDE
}
/**
@ -277,7 +282,7 @@ public static String getSimpleName(final Class<?> cls) {
* @since 3.0
* @see Class#getSimpleName()
*/
public static String getSimpleName(final Class<?> cls, String valueIfNull) {
public static String getSimpleName(final Class<?> cls, final String valueIfNull) {
return cls == null ? valueIfNull : cls.getSimpleName();
}
@ -598,7 +603,7 @@ public static List<Class<?>> getAllInterfaces(final Class<?> cls) {
}
/**
* Get the interfaces for the specified class.
* Gets the interfaces for the specified class.
*
* @param cls the class to look up, may be {@code null}
* @param interfacesFound the {@code Set} of interfaces for the class
@ -1468,7 +1473,7 @@ private static String getCanonicalName(String className) {
}
/**
* Get an {@link Iterable} that can iterate over a class hierarchy in ascending (subclass to superclass) order,
* Gets an {@link Iterable} that can iterate over a class hierarchy in ascending (subclass to superclass) order,
* excluding interfaces.
*
* @param type the type to get the class hierarchy from
@ -1480,7 +1485,7 @@ public static Iterable<Class<?>> hierarchy(final Class<?> type) {
}
/**
* Get an {@link Iterable} that can iterate over a class hierarchy in ascending (subclass to superclass) order.
* Gets an {@link Iterable} that can iterate over a class hierarchy in ascending (subclass to superclass) order.
*
* @param type the type to get the class hierarchy from
* @param interfacesBehavior switch indicating whether to include or exclude interfaces

View File

@ -162,7 +162,7 @@ public interface FailableSupplier<O, T extends Throwable> {
* @param pRunnable a {@code FailableRunnable}
* @return a standard {@code Runnable}
*/
public static Runnable asRunnable(FailableRunnable<?> pRunnable) {
public static Runnable asRunnable(final FailableRunnable<?> pRunnable) {
return () -> run(pRunnable);
}
@ -173,7 +173,7 @@ public static Runnable asRunnable(FailableRunnable<?> pRunnable) {
* @param pConsumer a {@code FailableConsumer}
* @return a standard {@code Consumer}
*/
public static <I> Consumer<I> asConsumer(FailableConsumer<I, ?> pConsumer) {
public static <I> Consumer<I> asConsumer(final FailableConsumer<I, ?> pConsumer) {
return (pInput) -> accept(pConsumer, pInput);
}
@ -184,7 +184,7 @@ public static <I> Consumer<I> asConsumer(FailableConsumer<I, ?> pConsumer) {
* @param pCallable a {@code FailableCallable}
* @return a standard {@code Callable}
*/
public static <O> Callable<O> asCallable(FailableCallable<O, ?> pCallable) {
public static <O> Callable<O> asCallable(final FailableCallable<O, ?> pCallable) {
return () -> call(pCallable);
}
@ -196,7 +196,7 @@ public static <O> Callable<O> asCallable(FailableCallable<O, ?> pCallable) {
* @param pConsumer a failable {@code BiConsumer}
* @return a standard {@code BiConsumer}
*/
public static <I1, I2> BiConsumer<I1, I2> asBiConsumer(FailableBiConsumer<I1, I2, ?> pConsumer) {
public static <I1, I2> BiConsumer<I1, I2> asBiConsumer(final FailableBiConsumer<I1, I2, ?> pConsumer) {
return (pInput1, pInput2) -> accept(pConsumer, pInput1, pInput2);
}
@ -208,7 +208,7 @@ public static <I1, I2> BiConsumer<I1, I2> asBiConsumer(FailableBiConsumer<I1, I2
* @param pFunction a {code FailableFunction}
* @return a standard {@code Function}
*/
public static <I, O> Function<I, O> asFunction(FailableFunction<I, O, ?> pFunction) {
public static <I, O> Function<I, O> asFunction(final FailableFunction<I, O, ?> pFunction) {
return (pInput) -> apply(pFunction, pInput);
}
@ -221,7 +221,7 @@ public static <I, O> Function<I, O> asFunction(FailableFunction<I, O, ?> pFuncti
* @param pFunction a {@code FailableBiFunction}
* @return a standard {@code BiFunction}
*/
public static <I1, I2, O> BiFunction<I1, I2, O> asBiFunction(FailableBiFunction<I1, I2, O, ?> pFunction) {
public static <I1, I2, O> BiFunction<I1, I2, O> asBiFunction(final FailableBiFunction<I1, I2, O, ?> pFunction) {
return (pInput1, pInput2) -> apply(pFunction, pInput1, pInput2);
}
@ -232,7 +232,7 @@ public static <I1, I2, O> BiFunction<I1, I2, O> asBiFunction(FailableBiFunction<
* @param pPredicate a {@code FailablePredicate}
* @return a standard {@code Predicate}
*/
public static <I> Predicate<I> asPredicate(FailablePredicate<I, ?> pPredicate) {
public static <I> Predicate<I> asPredicate(final FailablePredicate<I, ?> pPredicate) {
return (pInput) -> test(pPredicate, pInput);
}
@ -244,7 +244,7 @@ public static <I> Predicate<I> asPredicate(FailablePredicate<I, ?> pPredicate) {
* @param pPredicate a {@code FailableBiPredicate}
* @return a standard {@code BiPredicate}
*/
public static <I1, I2> BiPredicate<I1, I2> asBiPredicate(FailableBiPredicate<I1, I2, ?> pPredicate) {
public static <I1, I2> BiPredicate<I1, I2> asBiPredicate(final FailableBiPredicate<I1, I2, ?> pPredicate) {
return (pInput1, pInput2) -> test(pPredicate, pInput1, pInput2);
}
@ -255,7 +255,7 @@ public static <I1, I2> BiPredicate<I1, I2> asBiPredicate(FailableBiPredicate<I1,
* @param pSupplier a {@code FailableSupplier}
* @return a standard {@code Supplier}
*/
public static <O> Supplier<O> asSupplier(FailableSupplier<O, ?> pSupplier) {
public static <O> Supplier<O> asSupplier(final FailableSupplier<O, ?> pSupplier) {
return () -> get(pSupplier);
}
@ -264,10 +264,10 @@ public static <O> Supplier<O> asSupplier(FailableSupplier<O, ?> pSupplier) {
* @param pRunnable The runnable to run
* @param <T> the type of checked exception the runnable may throw
*/
public static <T extends Throwable> void run(FailableRunnable<T> pRunnable) {
public static <T extends Throwable> void run(final FailableRunnable<T> pRunnable) {
try {
pRunnable.run();
} catch (Throwable t) {
} catch (final Throwable t) {
throw rethrow(t);
}
}
@ -279,10 +279,10 @@ public static <T extends Throwable> void run(FailableRunnable<T> pRunnable) {
* @param <T> the type of checked exception the callable may throw
* @return the value returned from the callable
*/
public static <O, T extends Throwable> O call(FailableCallable<O, T> pCallable) {
public static <O, T extends Throwable> O call(final FailableCallable<O, T> pCallable) {
try {
return pCallable.call();
} catch (Throwable t) {
} catch (final Throwable t) {
throw rethrow(t);
}
}
@ -294,10 +294,10 @@ public static <O, T extends Throwable> O call(FailableCallable<O, T> pCallable)
* @param <O> the type the consumer accepts
* @param <T> the type of checked exception the consumer may throw
*/
public static <O, T extends Throwable> void accept(FailableConsumer<O, T> pConsumer, O pObject) {
public static <O, T extends Throwable> void accept(final FailableConsumer<O, T> pConsumer, final O pObject) {
try {
pConsumer.accept(pObject);
} catch (Throwable t) {
} catch (final Throwable t) {
throw rethrow(t);
}
}
@ -311,10 +311,10 @@ public static <O, T extends Throwable> void accept(FailableConsumer<O, T> pConsu
* @param <O2> the type of the second argument the consumer accepts
* @param <T> the type of checked exception the consumer may throw
*/
public static <O1, O2, T extends Throwable> void accept(FailableBiConsumer<O1, O2, T> pConsumer, O1 pObject1, O2 pObject2) {
public static <O1, O2, T extends Throwable> void accept(final FailableBiConsumer<O1, O2, T> pConsumer, final O1 pObject1, final O2 pObject2) {
try {
pConsumer.accept(pObject1, pObject2);
} catch (Throwable t) {
} catch (final Throwable t) {
throw rethrow(t);
}
}
@ -328,10 +328,10 @@ public static <O1, O2, T extends Throwable> void accept(FailableBiConsumer<O1, O
* @param <T> the type of checked exception the function may throw
* @return the value returned from the function
*/
public static <I, O, T extends Throwable> O apply(FailableFunction<I, O, T> pFunction, I pInput) {
public static <I, O, T extends Throwable> O apply(final FailableFunction<I, O, T> pFunction, final I pInput) {
try {
return pFunction.apply(pInput);
} catch (Throwable t) {
} catch (final Throwable t) {
throw rethrow(t);
}
}
@ -347,10 +347,10 @@ public static <I, O, T extends Throwable> O apply(FailableFunction<I, O, T> pFun
* @param <T> the type of checked exception the function may throw
* @return the value returned from the function
*/
public static <I1, I2, O, T extends Throwable> O apply(FailableBiFunction<I1, I2, O, T> pFunction, I1 pInput1, I2 pInput2) {
public static <I1, I2, O, T extends Throwable> O apply(final FailableBiFunction<I1, I2, O, T> pFunction, final I1 pInput1, final I2 pInput2) {
try {
return pFunction.apply(pInput1, pInput2);
} catch (Throwable t) {
} catch (final Throwable t) {
throw rethrow(t);
}
}
@ -363,10 +363,10 @@ public static <I1, I2, O, T extends Throwable> O apply(FailableBiFunction<I1, I2
* @param <T> the type of checked exception the predicate may throw
* @return the boolean value returned by the predicate
*/
public static <O, T extends Throwable> boolean test(FailablePredicate<O, T> pPredicate, O pObject) {
public static <O, T extends Throwable> boolean test(final FailablePredicate<O, T> pPredicate, final O pObject) {
try {
return pPredicate.test(pObject);
} catch (Throwable t) {
} catch (final Throwable t) {
throw rethrow(t);
}
}
@ -381,10 +381,10 @@ public static <O, T extends Throwable> boolean test(FailablePredicate<O, T> pPre
* @param <T> the type of checked exception the predicate may throw
* @return the boolean value returned by the predicate
*/
public static <O1, O2, T extends Throwable> boolean test(FailableBiPredicate<O1, O2, T> pPredicate, O1 pObject1, O2 pObject2) {
public static <O1, O2, T extends Throwable> boolean test(final FailableBiPredicate<O1, O2, T> pPredicate, final O1 pObject1, final O2 pObject2) {
try {
return pPredicate.test(pObject1, pObject2);
} catch (Throwable t) {
} catch (final Throwable t) {
throw rethrow(t);
}
}
@ -396,10 +396,10 @@ public static <O1, O2, T extends Throwable> boolean test(FailableBiPredicate<O1,
* @param <T> The type of checked exception, which the supplier can throw.
* @return The object, which has been created by the supplier
*/
public static <O, T extends Throwable> O get(FailableSupplier<O, T> pSupplier) {
public static <O, T extends Throwable> O get(final FailableSupplier<O, T> pSupplier) {
try {
return pSupplier.get();
} catch (Throwable t) {
} catch (final Throwable t) {
throw rethrow(t);
}
}
@ -416,8 +416,8 @@ public static <O, T extends Throwable> O get(FailableSupplier<O, T> pSupplier) {
* @param <O> The streams element type.
* @return The created {@link FailableStream}.
*/
public static <O> FailableStream<O> stream(Stream<O> pStream) {
return new FailableStream<O>(pStream);
public static <O> FailableStream<O> stream(final Stream<O> pStream) {
return new FailableStream<>(pStream);
}
/**
@ -433,8 +433,8 @@ public static <O> FailableStream<O> stream(Stream<O> pStream) {
* streams element type.)
* @return The created {@link FailableStream}.
*/
public static <O> FailableStream<O> stream(Collection<O> pCollection) {
return new FailableStream<O>(pCollection.stream());
public static <O> FailableStream<O> stream(final Collection<O> pCollection) {
return new FailableStream<>(pCollection.stream());
}
@ -461,9 +461,9 @@ public static <O> FailableStream<O> stream(Collection<O> pCollection) {
* @see #tryWithResources(FailableRunnable, FailableRunnable...)
*/
@SafeVarargs
public static void tryWithResources(FailableRunnable<? extends Throwable> pAction,
FailableConsumer<Throwable, ? extends Throwable> pErrorHandler,
FailableRunnable<? extends Throwable>... pResources) {
public static void tryWithResources(final FailableRunnable<? extends Throwable> pAction,
final FailableConsumer<Throwable, ? extends Throwable> pErrorHandler,
final FailableRunnable<? extends Throwable>... pResources) {
final FailableConsumer<Throwable, ? extends Throwable> errorHandler;
if (pErrorHandler == null) {
errorHandler = (t) -> rethrow(t);
@ -471,21 +471,21 @@ public static void tryWithResources(FailableRunnable<? extends Throwable> pActio
errorHandler = pErrorHandler;
}
if (pResources != null) {
for (FailableRunnable<? extends Throwable> failableRunnable : pResources) {
for (final FailableRunnable<? extends Throwable> failableRunnable : pResources) {
Objects.requireNonNull(failableRunnable, "runnable");
}
}
Throwable th = null;
try {
pAction.run();
} catch (Throwable t) {
} catch (final Throwable t) {
th = t;
}
if (pResources != null) {
for (FailableRunnable<? extends Object> runnable : pResources) {
for (final FailableRunnable<? extends Object> runnable : pResources) {
try {
runnable.run();
} catch (Throwable t) {
} catch (final Throwable t) {
if (th == null) {
th = t;
}
@ -495,7 +495,7 @@ public static void tryWithResources(FailableRunnable<? extends Throwable> pActio
if (th != null) {
try {
errorHandler.accept(th);
} catch (Throwable t) {
} catch (final Throwable t) {
throw rethrow(t);
}
}
@ -521,8 +521,8 @@ public static void tryWithResources(FailableRunnable<? extends Throwable> pActio
* @see #tryWithResources(FailableRunnable, FailableConsumer, FailableRunnable...)
*/
@SafeVarargs
public static void tryWithResources(FailableRunnable<? extends Throwable> pAction,
FailableRunnable<? extends Throwable>... pResources) {
public static void tryWithResources(final FailableRunnable<? extends Throwable> pAction,
final FailableRunnable<? extends Throwable>... pResources) {
tryWithResources(pAction, null, pResources);
}
@ -549,7 +549,7 @@ public static void tryWithResources(FailableRunnable<? extends Throwable> pActio
* @param pThrowable The throwable to rethrow possibly wrapped into an unchecked exception
* @return Never returns anything, this method never terminates normally.
*/
public static RuntimeException rethrow(Throwable pThrowable) {
public static RuntimeException rethrow(final Throwable pThrowable) {
Objects.requireNonNull(pThrowable, "pThrowable");
if (pThrowable instanceof RuntimeException) {
throw (RuntimeException) pThrowable;

View File

@ -238,7 +238,7 @@ public static <T> T getFirstNonNull(final Supplier<T>... suppliers) {
if (suppliers != null) {
for (final Supplier<T> supplier : suppliers) {
if (supplier != null) {
T value = supplier.get();
final T value = supplier.get();
if (value != null) {
return value;
}

View File

@ -37,10 +37,10 @@
import org.apache.commons.lang3.Functions.FailablePredicate;
/**
* This class provides utility functions, and classes for working with the
* java.util.stream package, or more generally, with Java 8 lambdas. More
* Provides utility functions, and classes for working with the
* {@code java.util.stream} package, or more generally, with Java 8 lambdas. More
* specifically, it attempts to address the fact that lambdas are supposed
* not to throw Exceptions, at least not checked Exceptions, aka instances
* not to throw Exceptions, at least not checked Exceptions, AKA instances
* of {@link Exception}. This enforces the use of constructs like
* <pre>
* Consumer&lt;java.lang.reflect.Method&gt; consumer = (m) -&gt; {
@ -58,20 +58,29 @@
* </pre>
* Obviously, the second version is much more concise and the spirit of
* Lambda expressions is met better than in the first version.
*
* @see Stream
* @see Functions
* @since 3.10
*/
public class Streams {
/** A reduced, and simplified version of a {@link Stream} with
* failable method signatures.
* @param <O> The streams element type.
*/
/**
* A reduced, and simplified version of a {@link Stream} with
* failable method signatures.
* @param <O> The streams element type.
*/
public static class FailableStream<O extends Object> {
private Stream<O> stream;
private boolean terminated;
public FailableStream(Stream<O> pStream) {
stream = pStream;
/**
* Constructs a new instance with the given {@code stream}.
* @param stream The stream.
*/
public FailableStream(final Stream<O> stream) {
this.stream = stream;
}
protected void assertNotTerminated() {
@ -91,13 +100,13 @@ protected void makeTerminated() {
*
* <p>This is an intermediate operation.
*
* @param pPredicate a non-interfering, stateless predicate to apply to each
* @param predicate a non-interfering, stateless predicate to apply to each
* element to determine if it should be included.
* @return the new stream
*/
public FailableStream<O> filter(FailablePredicate<O, ?> pPredicate){
public FailableStream<O> filter(final FailablePredicate<O, ?> predicate){
assertNotTerminated();
stream = stream.filter(Functions.asPredicate(pPredicate));
stream = stream.filter(Functions.asPredicate(predicate));
return this;
}
@ -114,11 +123,11 @@ public FailableStream<O> filter(FailablePredicate<O, ?> pPredicate){
* library chooses. If the action accesses shared state, it is
* responsible for providing the required synchronization.
*
* @param pAction a non-interfering action to perform on the elements
* @param action a non-interfering action to perform on the elements
*/
public void forEach(FailableConsumer<O, ?> pAction) {
public void forEach(final FailableConsumer<O, ?> action) {
makeTerminated();
stream().forEach(Functions.asConsumer(pAction));
stream().forEach(Functions.asConsumer(action));
}
/**
@ -164,14 +173,14 @@ public void forEach(FailableConsumer<O, ?> pAction) {
*
* @param <R> the type of the result
* @param <A> the intermediate accumulation type of the {@code Collector}
* @param pCollector the {@code Collector} describing the reduction
* @param collector the {@code Collector} describing the reduction
* @return the result of the reduction
* @see #collect(Supplier, BiConsumer, BiConsumer)
* @see Collectors
*/
public <A, R> R collect(Collector<? super O, A, R> pCollector) {
public <A, R> R collect(final Collector<? super O, A, R> collector) {
makeTerminated();
return stream().collect(pCollector);
return stream().collect(collector);
}
/**
@ -209,19 +218,19 @@ public <A, R> R collect(Collector<? super O, A, R> pCollector) {
*
* @param <R> type of the result
* @param <A> Type of the accumulator.
* @param pSupplier a function that creates a new result container. For a
* @param pupplier a function that creates a new result container. For a
* parallel execution, this function may be called
* multiple times and must return a fresh value each time.
* @param pAccumulator An associative, non-interfering, stateless function for
* @param accumulator An associative, non-interfering, stateless function for
* incorporating an additional element into a result
* @param pCombiner An associative, non-interfering, stateless
* @param combiner An associative, non-interfering, stateless
* function for combining two values, which must be compatible with the
* accumulator function
* @return The result of the reduction
*/
public <A, R> R collect(Supplier<R> pSupplier, BiConsumer<R, ? super O> pAccumulator, BiConsumer<R, R> pCombiner) {
public <A, R> R collect(final Supplier<R> pupplier, final BiConsumer<R, ? super O> accumulator, final BiConsumer<R, R> combiner) {
makeTerminated();
return stream().collect(pSupplier, pAccumulator, pCombiner);
return stream().collect(pupplier, accumulator, combiner);
}
/**
@ -262,14 +271,14 @@ public <A, R> R collect(Supplier<R> pSupplier, BiConsumer<R, ? super O> pAccumul
* operations parallelize more gracefully, without needing additional
* synchronization and with greatly reduced risk of data races.
*
* @param pIdentity the identity value for the accumulating function
* @param pAccumulator an associative, non-interfering, stateless
* @param identity the identity value for the accumulating function
* @param accumulator an associative, non-interfering, stateless
* function for combining two values
* @return the result of the reduction
*/
public O reduce(O pIdentity, BinaryOperator<O> pAccumulator) {
public O reduce(final O identity, final BinaryOperator<O> accumulator) {
makeTerminated();
return stream().reduce(pIdentity, pAccumulator);
return stream().reduce(identity, accumulator);
}
/**
@ -279,12 +288,12 @@ public O reduce(O pIdentity, BinaryOperator<O> pAccumulator) {
* <p>This is an intermediate operation.
*
* @param <R> The element type of the new stream
* @param pMapper A non-interfering, stateless function to apply to each element
* @param mapper A non-interfering, stateless function to apply to each element
* @return the new stream
*/
public <R> FailableStream<R> map(FailableFunction<O, R, ?> pMapper) {
public <R> FailableStream<R> map(final FailableFunction<O, R, ?> mapper) {
assertNotTerminated();
return new FailableStream<R>(stream.map(Functions.asFunction(pMapper)));
return new FailableStream<>(stream.map(Functions.asFunction(mapper)));
}
/**
@ -309,14 +318,14 @@ public Stream<O> stream() {
* stream is empty, the quantification is said to be <em>vacuously
* satisfied</em> and is always {@code true} (regardless of P(x)).
*
* @param pPredicate A non-interfering, stateless predicate to apply to
* @param predicate A non-interfering, stateless predicate to apply to
* elements of this stream
* @return {@code true} If either all elements of the stream match the
* provided predicate or the stream is empty, otherwise {@code false}.
*/
public boolean allMatch(FailablePredicate<O, ?> pPredicate) {
public boolean allMatch(final FailablePredicate<O, ?> predicate) {
assertNotTerminated();
return stream().allMatch(Functions.asPredicate(pPredicate));
return stream().allMatch(Functions.asPredicate(predicate));
}
/**
@ -331,14 +340,14 @@ public boolean allMatch(FailablePredicate<O, ?> pPredicate) {
* This method evaluates the <em>existential quantification</em> of the
* predicate over the elements of the stream (for some x P(x)).
*
* @param pPredicate A non-interfering, stateless predicate to apply to
* @param predicate A non-interfering, stateless predicate to apply to
* elements of this stream
* @return {@code true} if any elements of the stream match the provided
* predicate, otherwise {@code false}
*/
public boolean anyMatch(FailablePredicate<O, ?> pPredicate) {
public boolean anyMatch(final FailablePredicate<O, ?> predicate) {
assertNotTerminated();
return stream().anyMatch(Functions.asPredicate(pPredicate));
return stream().anyMatch(Functions.asPredicate(predicate));
}
}
@ -376,12 +385,12 @@ public boolean anyMatch(FailablePredicate<O, ?> pPredicate) {
* concise, and readable, and meets the spirit of Lambdas better
* than the first version.
* @param <O> The streams element type.
* @param pStream The stream, which is being converted.
* @param stream The stream, which is being converted.
* @return The {@link FailableStream}, which has been created by
* converting the stream.
*/
public static <O> FailableStream<O> stream(Stream<O> pStream) {
return new FailableStream<O>(pStream);
public static <O> FailableStream<O> stream(final Stream<O> stream) {
return new FailableStream<>(stream);
}
/**
@ -418,12 +427,12 @@ public static <O> FailableStream<O> stream(Stream<O> pStream) {
* concise, and readable, and meets the spirit of Lambdas better
* than the first version.
* @param <O> The streams element type.
* @param pStream The stream, which is being converted.
* @param stream The stream, which is being converted.
* @return The {@link FailableStream}, which has been created by
* converting the stream.
*/
public static <O> FailableStream<O> stream(Collection<O> pStream) {
return stream(pStream.stream());
public static <O> FailableStream<O> stream(final Collection<O> stream) {
return stream(stream.stream());
}
public static class ArrayCollector<O> implements Collector<O, List<O>, O[]> {

View File

@ -535,7 +535,7 @@ public static String appendIfMissingIgnoreCase(final String str, final CharSeque
* @since 2.0
*/
public static String capitalize(final String str) {
int strLen = length(str);
final int strLen = length(str);
if (strLen == 0) {
return str;
}
@ -3546,7 +3546,7 @@ public static boolean isAsciiPrintable(final CharSequence cs) {
* @since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence)
*/
public static boolean isBlank(final CharSequence cs) {
int strLen = length(cs);
final int strLen = length(cs);
if (strLen == 0) {
return true;
}
@ -8355,7 +8355,7 @@ public static String stripEnd(final String str, final String stripChars) {
* @return the stripped String, {@code null} if null String input
*/
public static String stripStart(final String str, final String stripChars) {
int strLen = length(str);
final int strLen = length(str);
if (strLen == 0) {
return str;
}
@ -9203,7 +9203,7 @@ public static String truncate(final String str, final int offset, final int maxW
* @since 2.0
*/
public static String uncapitalize(final String str) {
int strLen = length(str);
final int strLen = length(str);
if (strLen == 0) {
return str;
}

View File

@ -36,7 +36,7 @@
public class ThreadUtils {
/**
* Return the active thread with the specified id if it belongs to the specified thread group.
* Finds the active thread with the specified id if it belongs to the specified thread group.
*
* @param threadId The thread id
* @param threadGroup The thread group
@ -59,7 +59,7 @@ public static Thread findThreadById(final long threadId, final ThreadGroup threa
}
/**
* Return the active thread with the specified id if it belongs to a thread group with the specified group name.
* Finds the active thread with the specified id if it belongs to a thread group with the specified group name.
*
* @param threadId The thread id
* @param threadGroupName The thread group name
@ -82,7 +82,7 @@ public static Thread findThreadById(final long threadId, final String threadGrou
}
/**
* Return active threads with the specified name if they belong to a specified thread group.
* Finds active threads with the specified name if they belong to a specified thread group.
*
* @param threadName The thread name
* @param threadGroup The thread group
@ -100,7 +100,7 @@ public static Collection<Thread> findThreadsByName(final String threadName, fina
}
/**
* Return active threads with the specified name if they belong to a thread group with the specified group name.
* Finds active threads with the specified name if they belong to a thread group with the specified group name.
*
* @param threadName The thread name
* @param threadGroupName The thread group name
@ -132,7 +132,7 @@ public static Collection<Thread> findThreadsByName(final String threadName, fina
}
/**
* Return active thread groups with the specified group name.
* Finds active thread groups with the specified group name.
*
* @param threadGroupName The thread group name
* @return the thread groups with the specified group name or an empty collection if no such thread group exists. The collection returned is always unmodifiable.
@ -148,7 +148,7 @@ public static Collection<ThreadGroup> findThreadGroupsByName(final String thread
}
/**
* Return all active thread groups excluding the system thread group (A thread group is active if it has been not destroyed).
* Gets all active thread groups excluding the system thread group (A thread group is active if it has been not destroyed).
*
* @return all thread groups excluding the system thread group. The collection returned is always unmodifiable.
* @throws SecurityException
@ -162,7 +162,7 @@ public static Collection<ThreadGroup> getAllThreadGroups() {
}
/**
* Return the system thread group (sometimes also referred as "root thread group").
* Gets the system thread group (sometimes also referred as "root thread group").
*
* @return the system thread group
* @throws SecurityException if the current thread cannot modify
@ -177,7 +177,7 @@ public static ThreadGroup getSystemThreadGroup() {
}
/**
* Return all active threads (A thread is active if it has been started and has not yet died).
* Gets all active threads (A thread is active if it has been started and has not yet died).
*
* @return all active threads. The collection returned is always unmodifiable.
* @throws SecurityException
@ -191,7 +191,7 @@ public static Collection<Thread> getAllThreads() {
}
/**
* Return active threads with the specified name.
* Finds active threads with the specified name.
*
* @param threadName The thread name
* @return The threads with the specified name or an empty collection if no such thread exists. The collection returned is always unmodifiable.
@ -207,7 +207,7 @@ public static Collection<Thread> findThreadsByName(final String threadName) {
}
/**
* Return the active thread with the specified id.
* Finds the active thread with the specified id.
*
* @param threadId The thread id
* @return The thread with the specified id or {@code null} if no such thread exists

View File

@ -267,7 +267,7 @@ public EqualsBuilder setTestRecursive(final boolean testRecursive) {
* @return EqualsBuilder - used to chain calls.
* @since 3.8
*/
public EqualsBuilder setBypassReflectionClasses(List<Class<?>> bypassReflectionClasses) {
public EqualsBuilder setBypassReflectionClasses(final List<Class<?>> bypassReflectionClasses) {
this.bypassReflectionClasses = bypassReflectionClasses;
return this;
}

View File

@ -959,7 +959,7 @@ public HashCodeBuilder appendSuper(final int superHashCode) {
/**
* <p>
* Return the computed {@code hashCode}.
* Returns the computed {@code hashCode}.
* </p>
*
* @return {@code hashCode} based on the fields appended

View File

@ -31,6 +31,8 @@ public class ComparableUtils {
/**
* Provides access to the available methods
*
* @param <A> the type of objects that this object may be compared against.
*/
public static class ComparableCheckBuilder<A extends Comparable<A>> {

View File

@ -62,7 +62,7 @@ public abstract class AtomicSafeInitializer<T> implements
private final AtomicReference<T> reference = new AtomicReference<>();
/**
* Get (and initialize, if not initialized yet) the required object
* Gets (and initialize, if not initialized yet) the required object
*
* @return lazily initialized object
* @throws ConcurrentException if the initialization of the object causes an

View File

@ -225,7 +225,7 @@ public void removeListener(final L listener) {
}
/**
* Get an array containing the currently registered listeners.
* Gets an array containing the currently registered listeners.
* Modification to this array's elements will have no effect on the
* {@link EventListenerSupport} instance.
* @return L[]

View File

@ -785,7 +785,7 @@ private static int distance(final Class<?>[] classArray, final Class<?>[] toClas
}
/**
* Get the hierarchy of overridden methods down to {@code result} respecting generics.
* Gets the hierarchy of overridden methods down to {@code result} respecting generics.
* @param method lowest to consider
* @param interfacesBehavior whether to search interfaces, {@code null} {@code implies} false
* @return Set&lt;Method&gt; in ascending order from sub- to superclass

View File

@ -1338,7 +1338,7 @@ public static boolean isArrayType(final Type type) {
}
/**
* Get the array component type of {@code type}.
* Gets the array component type of {@code type}.
* @param type the type to be checked
* @return component type or null if type is not an array type
*/
@ -1354,7 +1354,7 @@ public static Type getArrayComponentType(final Type type) {
}
/**
* Get a type representing {@code type} with variable assignments "unrolled."
* Gets a type representing {@code type} with variable assignments "unrolled."
*
* @param typeArguments as from {@link TypeUtils#getTypeArguments(Type, Class)}
* @param type the type to unroll variable assignments for
@ -1540,7 +1540,7 @@ private static Type[] extractTypeArgumentsFrom(final Map<TypeVariable<?>, Type>
}
/**
* Get a {@link WildcardTypeBuilder}.
* Gets a {@link WildcardTypeBuilder}.
* @return {@link WildcardTypeBuilder}
* @since 3.2
*/

View File

@ -295,7 +295,7 @@ public int hashCode() {
}
/**
* Get a custom format from a format description.
* Gets a custom format from a format description.
*
* @param desc String
* @return Format

View File

@ -59,7 +59,7 @@ public FormattableUtils() {
//-----------------------------------------------------------------------
/**
* Get the default formatted representation of the specified
* Gets the default formatted representation of the specified
* {@code Formattable}.
*
* @param formattable the instance to convert to a string, not null

View File

@ -1821,7 +1821,7 @@ public boolean hasNext() {
}
/**
* Return the next calendar in the iteration
* Returns the next calendar in the iteration
*
* @return Object calendar for the next date
*/

View File

@ -451,7 +451,7 @@ private static StringBuilder simpleQuote(final StringBuilder sb, final String va
}
/**
* Get the short and long values displayed for a field
* Gets the short and long values displayed for a field
* @param cal The calendar to obtain the short and long values
* @param locale The locale of display names
* @param field The field of interest
@ -606,7 +606,7 @@ private Strategy getStrategy(final char f, final int width, final Calendar defin
private static final ConcurrentMap<Locale, Strategy>[] caches = new ConcurrentMap[Calendar.FIELD_COUNT];
/**
* Get a cache of Strategies for a particular field
* Gets a cache of Strategies for a particular field
* @param field The Calendar field
* @return a cache of Locale to Strategy
*/
@ -620,7 +620,7 @@ private static ConcurrentMap<Locale, Strategy> getCache(final int field) {
}
/**
* Construct a Strategy that parses a Text field
* Constructs a Strategy that parses a Text field
* @param field The Calendar field
* @param definingCalendar The calendar to obtain the short and long values
* @return a TextStrategy for the field and Locale
@ -648,7 +648,7 @@ private static class CopyQuotedStrategy extends Strategy {
private final String formatField;
/**
* Construct a Strategy that ensures the formatField has literal text
* Constructs a Strategy that ensures the formatField has literal text
* @param formatField The literal text to match
*/
CopyQuotedStrategy(final String formatField) {
@ -690,7 +690,7 @@ private static class CaseInsensitiveTextStrategy extends PatternStrategy {
private final Map<String, Integer> lKeyValues;
/**
* Construct a Strategy that parses a Text field
* Constructs a Strategy that parses a Text field
* @param field The Calendar field
* @param definingCalendar The Calendar to use
* @param locale The Locale to use
@ -730,7 +730,7 @@ private static class NumberStrategy extends Strategy {
private final int field;
/**
* Construct a Strategy that parses a Number field
* Constructs a Strategy that parses a Number field
* @param field The Calendar field
*/
NumberStrategy(final int field) {
@ -833,7 +833,7 @@ private static class TzInfo {
private static final int ID = 0;
/**
* Construct a Strategy that parses a TimeZone
* Constructs a Strategy that parses a TimeZone
* @param locale The Locale
*/
TimeZoneStrategy(final Locale locale) {
@ -912,7 +912,7 @@ private static class ISO8601TimeZoneStrategy extends PatternStrategy {
// Z, +hh, -hh, +hhmm, -hhmm, +hh:mm or -hh:mm
/**
* Construct a Strategy that parses a TimeZone
* Constructs a Strategy that parses a TimeZone
* @param pattern The Pattern
*/
ISO8601TimeZoneStrategy(final String pattern) {

View File

@ -55,7 +55,7 @@ public R getRight() {
}
@Override
public R setValue(R value) {
public R setValue(final R value) {
return null;
}

View File

@ -98,7 +98,7 @@ public void testArch() {
@Test
public void testArchLabels() {
for (Arch arch : Arch.values()) {
for (final Arch arch : Arch.values()) {
// Only test label presence.
assertFalse(arch.getLabel().isEmpty());
}

View File

@ -3146,8 +3146,8 @@ public void testIndexOfWithStartIndex() {
@Test
public void testIndexesOf() {
final Object[] array = new Object[]{"0", "1", "2", "3", null, "0"};
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf((Object[]) null, null));
assertEquals(emptySet, ArrayUtils.indexesOf(new Object[0], "0"));
testSet.set(5);
@ -3168,8 +3168,8 @@ public void testIndexesOf() {
@Test
public void testIndexesOfWithStartIndex() {
final Object[] array = new Object[]{"0", "1", "2", "3", "2", "3", "1", null, "0"};
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(null, null, 2));
assertEquals(emptySet, ArrayUtils.indexesOf(new Object[0], "0", 0));
assertEquals(emptySet, ArrayUtils.indexesOf(null, "0", 2));
@ -3288,8 +3288,8 @@ public void testIndexOfLongWithStartIndex() {
@Test
public void testIndexesOfLong() {
final long[] array = new long[]{0, 1, 2, 3};
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf((long[]) null, 0));
assertEquals(emptySet, ArrayUtils.indexesOf(array, 4));
testSet.set(0);
@ -3308,8 +3308,8 @@ public void testIndexesOfLong() {
@Test
public void testIndexesOfLongWithStartIndex() {
final long[] array = new long[]{0, 1, 2, 3, 2, 1, 0, 1};
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf((long[]) null, 0, 0));
assertEquals(emptySet, ArrayUtils.indexesOf(array, 4, 0));
testSet.set(6);
@ -3399,8 +3399,8 @@ public void testIndexOfIntWithStartIndex() {
@Test
public void textIndexesOfInt() {
int[] array = null;
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(array, 0));
array = new int[]{0, 1, 2, 3, 0};
testSet.set(0);
@ -3421,8 +3421,8 @@ public void textIndexesOfInt() {
@Test
public void testIndexesOfIntWithStartIndex() {
int[] array = null;
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(array, 0, 2));
array = new int[]{0, 1, 2, 3, 0};
testSet.set(4);
@ -3510,8 +3510,8 @@ public void testIndexOfShortWithStartIndex() {
@Test
public void testIndexesOfShort() {
short[] array = null;
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(array, (short) 0));
array = new short[]{0, 1, 2, 3, 0};
testSet.set(0);
@ -3532,8 +3532,8 @@ public void testIndexesOfShort() {
@Test
public void testIndexesOfShortWithStartIndex() {
short[] array = null;
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(array, (short) 0, 2));
array = new short[]{0, 1, 2, 3, 0};
testSet.set(4);
@ -3621,8 +3621,8 @@ public void testIndexOfCharWithStartIndex() {
@Test
public void testIndexesOfChar() {
char[] array = null;
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(array, 'a'));
array = new char[]{'a', 'b', 'c', 'd', 'a'};
testSet.set(0);
@ -3643,8 +3643,8 @@ public void testIndexesOfChar() {
@Test
public void testIndexesOfCharWithStartIndex() {
char[] array = null;
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(array, 'a', 0));
array = new char[]{'a', 'b', 'c', 'd', 'a'};
testSet.set(4);
@ -3733,8 +3733,8 @@ public void testIndexOfByteWithStartIndex() {
@Test
public void testIndexesOfByte() {
byte[] array = null;
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(array, (byte) 0));
array = new byte[]{0, 1, 2, 3, 0};
testSet.set(0);
@ -3755,8 +3755,8 @@ public void testIndexesOfByte() {
@Test
public void testIndexesOfByteWithStartIndex() {
byte[] array = null;
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(array, (byte) 0, 2));
array = new byte[]{0, 1, 2, 3, 0};
testSet.set(4);
@ -3883,8 +3883,8 @@ public void testIndexOfDoubleWithStartIndexTolerance() {
@Test
public void testIndexesOfDouble() {
double[] array = null;
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(array, 0));
array = new double[]{0, 1, 2, 3, 0};
testSet.set(0);
@ -3906,8 +3906,8 @@ public void testIndexesOfDouble() {
@Test
public void testIndexesOfDoubleWithStartIndex() {
double[] array = null;
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(array, 0, 2));
array = new double[]{0, 1, 2, 3, 0};
testSet.set(4);
@ -3931,8 +3931,8 @@ public void testIndexesOfDoubleWithStartIndex() {
@Test
public void testIndexesOfDoubleTolerance() {
double[] array = null;
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(array, (double) 0, (double) 0));
array = new double[0];
assertEquals(emptySet, ArrayUtils.indexesOf(array, (double) 0, (double) 0));
@ -3952,8 +3952,8 @@ public void testIndexesOfDoubleTolerance() {
@Test
public void testIndexesOfDoubleWithStartIndexTolerance() {
double[] array = null;
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(array, (double) 0, 0, (double) 0));
array = new double[0];
assertEquals(emptySet, ArrayUtils.indexesOf(array, (double) 0, 0, (double) 0));
@ -4102,8 +4102,8 @@ public void testIndexOfFloatWithStartIndex() {
@Test
public void testIndexesOfFloat() {
float[] array = null;
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(array, 0));
array = new float[]{0, 1, 2, 3, 0};
testSet.set(0);
@ -4125,8 +4125,8 @@ public void testIndexesOfFloat() {
@Test
public void testIndexesOfFloatWithStartIndex() {
float[] array = null;
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(array, 0, 2));
array = new float[]{0, 1, 2, 3, 0};
testSet.set(4);
@ -4224,8 +4224,8 @@ public void testIndexOfBooleanWithStartIndex() {
@Test
public void testIndexesOfBoolean() {
boolean[] array = null;
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(array, true));
array = new boolean[0];
assertEquals(emptySet, ArrayUtils.indexesOf(array, true));
@ -4243,8 +4243,8 @@ public void testIndexesOfBoolean() {
@Test
public void testIndexesOfBooleanWithStartIndex() {
boolean[] array = null;
BitSet emptySet = new BitSet();
BitSet testSet = new BitSet();
final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(array, true, 0));
array = new boolean[0];
assertEquals(emptySet, ArrayUtils.indexesOf(array, true, 0));
@ -5160,7 +5160,7 @@ public void testShuffleDouble() {
@Test
public void testIsArrayIndexValid() {
assertFalse(ArrayUtils.isArrayIndexValid(null, 0));
String[] array = new String[1];
final String[] array = new String[1];
//too big
assertFalse(ArrayUtils.isArrayIndexValid(array, 1));

View File

@ -311,7 +311,7 @@ public void testContains_Charrange() {
@Test
public void testContainsNullArg() {
final CharRange range = CharRange.is('a');
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> range.contains(null));
final IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> range.contains(null));
assertEquals("The Range must not be null", e.getMessage());
}

View File

@ -49,11 +49,11 @@ public static class SomeException extends Exception {
private Throwable t;
SomeException(String pMsg) {
SomeException(final String pMsg) {
super(pMsg);
}
public void setThrowable(Throwable pThrowable) {
public void setThrowable(final Throwable pThrowable) {
t = pThrowable;
}
@ -66,11 +66,11 @@ public void test() throws Throwable {
public static class Testable {
private Throwable t;
Testable(Throwable pTh) {
Testable(final Throwable pTh) {
t = pTh;
}
public void setThrowable(Throwable pThrowable) {
public void setThrowable(final Throwable pThrowable) {
t = pThrowable;
}
@ -78,7 +78,7 @@ public void test() throws Throwable {
test(t);
}
public void test(Throwable pThrowable) throws Throwable {
public void test(final Throwable pThrowable) throws Throwable {
if (pThrowable != null) {
throw pThrowable;
}
@ -88,7 +88,7 @@ public Integer testInt() throws Throwable {
return testInt(t);
}
public Integer testInt(Throwable pThrowable) throws Throwable {
public Integer testInt(final Throwable pThrowable) throws Throwable {
if (pThrowable != null) {
throw pThrowable;
}
@ -117,7 +117,7 @@ static boolean failingBool() throws SomeException {
public static class CloseableObject {
private boolean closed;
public void run(Throwable pTh) throws Throwable {
public void run(final Throwable pTh) throws Throwable {
if (pTh != null) {
throw pTh;
}
@ -139,7 +139,7 @@ public boolean isClosed() {
@Test
void testRunnable() {
FailureOnOddInvocations.invocation = 0;
UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> Functions.run(FailureOnOddInvocations::new));
final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> Functions.run(FailureOnOddInvocations::new));
final Throwable cause = e.getCause();
assertNotNull(cause);
assertTrue(cause instanceof SomeException);
@ -152,8 +152,8 @@ void testRunnable() {
@Test
void testAsRunnable() {
FailureOnOddInvocations.invocation = 0;
Runnable runnable = Functions.asRunnable(() -> new FailureOnOddInvocations());
UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> runnable.run());
final Runnable runnable = Functions.asRunnable(() -> new FailureOnOddInvocations());
final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> runnable.run());
final Throwable cause = e.getCause();
assertNotNull(cause);
assertTrue(cause instanceof SomeException);
@ -166,7 +166,7 @@ void testAsRunnable() {
@Test
void testCallable() {
FailureOnOddInvocations.invocation = 0;
UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> Functions.run(FailureOnOddInvocations::new));
final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> Functions.run(FailureOnOddInvocations::new));
final Throwable cause = e.getCause();
assertNotNull(cause);
assertTrue(cause instanceof SomeException);
@ -182,7 +182,7 @@ void testAsCallable() {
return new FailureOnOddInvocations();
};
final Callable<FailureOnOddInvocations> callable = Functions.asCallable(failableCallable);
UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> callable.call());
final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> callable.call());
final Throwable cause = e.getCause();
assertNotNull(cause);
assertTrue(cause instanceof SomeException);
@ -190,7 +190,7 @@ void testAsCallable() {
final FailureOnOddInvocations instance;
try {
instance = callable.call();
} catch (Exception ex) {
} catch (final Exception ex) {
throw Functions.rethrow(ex);
}
assertNotNull(instance);
@ -394,7 +394,7 @@ public void testAsBiFunction() {
@Test
public void testGetFromSupplier() {
FailureOnOddInvocations.invocation = 0;
UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> Functions.run(FailureOnOddInvocations::new));
final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> Functions.run(FailureOnOddInvocations::new));
final Throwable cause = e.getCause();
assertNotNull(cause);
assertTrue(cause instanceof SomeException);
@ -409,7 +409,7 @@ public void testAsPredicate() {
FailureOnOddInvocations.invocation = 0;
final Functions.FailablePredicate<Object, Throwable> failablePredicate = (t) -> FailureOnOddInvocations.failingBool();
final Predicate<?> predicate = Functions.asPredicate(failablePredicate);
UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> predicate.test(null));
final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> predicate.test(null));
final Throwable cause = e.getCause();
assertNotNull(cause);
assertTrue(cause instanceof SomeException);
@ -424,7 +424,7 @@ public void testAsBiPredicate() {
FailureOnOddInvocations.invocation = 0;
final Functions.FailableBiPredicate<Object, Object, Throwable> failableBiPredicate = (t1, t2) -> FailureOnOddInvocations.failingBool();
final BiPredicate<?, ?> predicate = Functions.asBiPredicate(failableBiPredicate);
UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> predicate.test(null, null));
final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> predicate.test(null, null));
final Throwable cause = e.getCause();
assertNotNull(cause);
assertTrue(cause instanceof SomeException);
@ -438,7 +438,7 @@ public void testAsSupplier() {
FailureOnOddInvocations.invocation = 0;
final FailableSupplier<FailureOnOddInvocations, Throwable> failableSupplier = () -> new FailureOnOddInvocations();
final Supplier<FailureOnOddInvocations> supplier = Functions.asSupplier(failableSupplier);
UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> supplier.get());
final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> supplier.get());
final Throwable cause = e.getCause();
assertNotNull(cause);
assertTrue(cause instanceof SomeException);
@ -464,7 +464,7 @@ public void testTryWithResources() {
assertTrue(co.isClosed());
co.reset();
final IOException ioe = new IOException("Unknown I/O error");
UncheckedIOException uioe = assertThrows(UncheckedIOException.class, () -> Functions.tryWithResources(() -> consumer.accept(ioe), co::close));
final UncheckedIOException uioe = assertThrows(UncheckedIOException.class, () -> Functions.tryWithResources(() -> consumer.accept(ioe), co::close));
final IOException cause = uioe.getCause();
assertSame(ioe, cause);

View File

@ -524,7 +524,7 @@ public void testLang865() {
@ParameterizedTest
@MethodSource("java.util.Locale#getAvailableLocales")
public void testParseAllLocales(Locale l) {
public void testParseAllLocales(final Locale l) {
// Check if it's possible to recreate the Locale using just the standard constructor
final Locale locale = new Locale(l.getLanguage(), l.getCountry(), l.getVariant());
if (l.equals(locale)) { // it is possible for LocaleUtils.toLocale to handle these Locales

View File

@ -121,8 +121,8 @@ public void testDefaultIfNull() {
assertSame(o, ObjectUtils.getIfNull(o, () -> dflt), "dflt was returned when o was not null");
assertSame(o, ObjectUtils.getIfNull(FOO, () -> dflt), "dflt was returned when o was not null");
assertSame(o, ObjectUtils.getIfNull("foo", () -> dflt), "dflt was returned when o was not null");
MutableInt callsCounter = new MutableInt(0);
Supplier<Object> countingDefaultSupplier = () -> {
final MutableInt callsCounter = new MutableInt(0);
final Supplier<Object> countingDefaultSupplier = () -> {
callsCounter.increment();
return dflt;
};
@ -539,7 +539,7 @@ public void testCloneOfNotCloneable() {
@Test
public void testCloneOfUncloneable() {
final UncloneableString string = new UncloneableString("apache");
CloneFailedException e = assertThrows(CloneFailedException.class, () -> ObjectUtils.clone(string));
final CloneFailedException e = assertThrows(CloneFailedException.class, () -> ObjectUtils.clone(string));
assertEquals(NoSuchMethodException.class, e.getCause().getClass());
}
@ -585,7 +585,7 @@ public void testPossibleCloneOfNotCloneable() {
@Test
public void testPossibleCloneOfUncloneable() {
final UncloneableString string = new UncloneableString("apache");
CloneFailedException e = assertThrows(CloneFailedException.class, () -> ObjectUtils.cloneIfPossible(string));
final CloneFailedException e = assertThrows(CloneFailedException.class, () -> ObjectUtils.cloneIfPossible(string));
assertEquals(NoSuchMethodException.class, e.getCause().getClass());
}

View File

@ -158,7 +158,7 @@ public void testLANG805() {
@Test
public void testLANG807() {
IllegalArgumentException ex =
final IllegalArgumentException ex =
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.random(3, 5, 5, false, false));
final String msg = ex.getMessage();
assertTrue(msg.contains("start"), "Message (" + msg + ") must contain 'start'");

View File

@ -159,7 +159,7 @@ public void write(final int arg0) throws IOException {
throw new IOException(SERIALIZE_IO_EXCEPTION_MESSAGE);
}
};
SerializationException e =
final SerializationException e =
assertThrows(SerializationException.class, () -> SerializationUtils.serialize(iMap, streamTest));
assertEquals("java.io.IOException: " + SERIALIZE_IO_EXCEPTION_MESSAGE, e.getMessage());
}
@ -232,7 +232,7 @@ public void testDeserializeStreamClassNotFound() throws Exception {
oos.close();
final ByteArrayInputStream inTest = new ByteArrayInputStream(streamReal.toByteArray());
SerializationException se =
final SerializationException se =
assertThrows(SerializationException.class, () -> SerializationUtils.deserialize(inTest));
assertEquals("java.lang.ClassNotFoundException: " + CLASS_NOT_FOUND_MESSAGE, se.getMessage());
}

View File

@ -49,7 +49,7 @@ void testSimpleStreamMapFailing() {
try {
Functions.stream(input).map((s) -> Integer.valueOf(s)).collect(Collectors.toList());
fail("Expected Exception");
} catch (NumberFormatException nfe) {
} catch (final NumberFormatException nfe) {
assertEquals("For input string: \"4 \"", nfe.getMessage());
}
}
@ -75,7 +75,7 @@ void testToArray() {
assertEquals("1", array[2]);
}
protected <T extends Throwable> FailableConsumer<String, T> asIntConsumer(T pThrowable) {
protected <T extends Throwable> FailableConsumer<String, T> asIntConsumer(final T pThrowable) {
return (s) -> {
final Integer i = Integer.valueOf(s);
if (i.intValue() == 4) {
@ -92,7 +92,7 @@ void testSimpleStreamForEachFailing() {
try {
Functions.stream(input).forEach(asIntConsumer(ise));
fail("Expected Exception");
} catch (IllegalArgumentException e) {
} catch (final IllegalArgumentException e) {
assertSame(ise, e);
}
output.clear();
@ -100,7 +100,7 @@ void testSimpleStreamForEachFailing() {
try {
Functions.stream(input).forEach(asIntConsumer(oome));
fail("Expected Exception");
} catch (Throwable t) {
} catch (final Throwable t) {
assertSame(oome, t);
}
output.clear();
@ -108,7 +108,7 @@ void testSimpleStreamForEachFailing() {
try {
Functions.stream(input).forEach(asIntConsumer(se));
fail("Expected Exception");
} catch (UndeclaredThrowableException ute) {
} catch (final UndeclaredThrowableException ute) {
assertSame(se, ute.getCause());
}
}
@ -132,7 +132,7 @@ private void assertEvenNumbers(final List<Integer> output) {
}
}
protected <T extends Throwable> FailablePredicate<Integer, T> asIntPredicate(T pThrowable) {
protected <T extends Throwable> FailablePredicate<Integer, T> asIntPredicate(final T pThrowable) {
return (i) -> {
if (i.intValue() == 5) {
if (pThrowable != null) {
@ -160,7 +160,7 @@ void testSimpleStreamFilterFailing() {
.filter(asIntPredicate(iae))
.collect(Collectors.toList());
fail("Expected Exception");
} catch (IllegalArgumentException e) {
} catch (final IllegalArgumentException e) {
assertSame(iae, e);
}
@ -172,7 +172,7 @@ void testSimpleStreamFilterFailing() {
.filter(asIntPredicate(oome))
.collect(Collectors.toList());
fail("Expected Exception");
} catch (Throwable t) {
} catch (final Throwable t) {
assertSame(oome, t);
}
@ -184,7 +184,7 @@ void testSimpleStreamFilterFailing() {
.filter(asIntPredicate(se))
.collect(Collectors.toList());
fail("Expected Exception");
} catch (UndeclaredThrowableException t) {
} catch (final UndeclaredThrowableException t) {
assertSame(se, t.getCause());
}
}

View File

@ -239,7 +239,7 @@ private void innerTestSplitPreserveAllTokens(final char separator, final String
//Fixed LANG-1463
@Test
public void testAbbreviateMarkerWithEmptyString() {
String greaterThanMaxTest = "much too long text";
final String greaterThanMaxTest = "much too long text";
assertEquals("much too long", StringUtils.abbreviate(greaterThanMaxTest, "", 13));
}
@ -684,8 +684,8 @@ public void testGetIfBlank_StringStringSupplier() {
final String s = StringUtils.getIfBlank("abc", () -> "NULL");
assertEquals("abc", s);
//Checking that default value supplied only on demand
MutableInt numberOfCalls = new MutableInt(0);
Supplier<String> countingDefaultSupplier = () -> {
final MutableInt numberOfCalls = new MutableInt(0);
final Supplier<String> countingDefaultSupplier = () -> {
numberOfCalls.increment();
return "NULL";
};
@ -752,8 +752,8 @@ public void testGetIfEmpty_StringStringSupplier() {
final String s = StringUtils.getIfEmpty("abc", () -> "NULL");
assertEquals("abc", s);
//Checking that default value supplied only on demand
MutableInt numberOfCalls = new MutableInt(0);
Supplier<String> countingDefaultSupplier = () -> {
final MutableInt numberOfCalls = new MutableInt(0);
final Supplier<String> countingDefaultSupplier = () -> {
numberOfCalls.increment();
return "NULL";
};
@ -3273,7 +3273,7 @@ public void testToRootLowerCase() {
assertEquals("title", "TITLE".toLowerCase(Locale.ROOT));
assertEquals("title", StringUtils.toRootLowerCase("TITLE"));
// Make sure we are not using the default Locale:
Locale defaultLocales = Locale.getDefault();
final Locale defaultLocales = Locale.getDefault();
try {
Locale.setDefault(TURKISH);
assertEquals("title", StringUtils.toRootLowerCase("TITLE"));
@ -3293,7 +3293,7 @@ public void testToRootUpperCase() {
assertEquals("TITLE", "title".toUpperCase(Locale.ROOT));
assertEquals("TITLE", StringUtils.toRootUpperCase("title"));
// Make sure we are not using the default Locale:
Locale defaultLocales = Locale.getDefault();
final Locale defaultLocales = Locale.getDefault();
try {
Locale.setDefault(TURKISH);
assertEquals("TITLE", StringUtils.toRootUpperCase("title"));

View File

@ -712,7 +712,7 @@ void shouldNotThrowExceptionForNonEmptyCollection() {
@Test
void shouldReturnSameInstance() {
Set<String> col = Collections.singleton("a");
final Set<String> col = Collections.singleton("a");
final Set<String> result = Validate.noNullElements(col);
assertSame(col, result);
@ -747,7 +747,7 @@ void shouldNotThrowExceptionForNonEmptyCollection() {
@Test
void shouldReturnSameInstance() {
Set<String> col = Collections.singleton("a");
final Set<String> col = Collections.singleton("a");
final Set<String> result = Validate.noNullElements(col, "MSG");
assertSame(col, result);

View File

@ -447,7 +447,7 @@ public void testObjectRecursiveGenericInteger() {
@Test
public void testObjectRecursiveGenericString() {
// Note: Do not use literals, because string literals are always mapped by same object (internal() of String))!
String s1_a = String.valueOf(1);
final String s1_a = String.valueOf(1);
final TestRecursiveGenericObject<String> o1_a = new TestRecursiveGenericObject<>(s1_a);
final TestRecursiveGenericObject<String> o1_b = new TestRecursiveGenericObject<>(String.valueOf(1));
final TestRecursiveGenericObject<String> o2 = new TestRecursiveGenericObject<>(String.valueOf(2));

View File

@ -23,10 +23,10 @@
public class ReflectionToStringBuilderSummaryTest {
@SuppressWarnings("unused")
private String stringField = "string";
private final String stringField = "string";
@ToStringSummary
private String summaryString = "summary";
private final String summaryString = "summary";
@Test
public void testSummary() {

View File

@ -179,7 +179,7 @@ public void testGetRuntimeException() {
final RuntimeException rex = new RuntimeException();
init.ex = rex;
init.start();
Exception ex = assertThrows(Exception.class, init::get);
final Exception ex = assertThrows(Exception.class, init::get);
assertEquals(rex, ex, "Runtime exception not thrown");
}
@ -193,7 +193,7 @@ public void testGetCheckedException() {
final Exception ex = new Exception();
init.ex = ex;
init.start();
ConcurrentException cex = assertThrows(ConcurrentException.class, init::get);
final ConcurrentException cex = assertThrows(ConcurrentException.class, init::get);
assertEquals(ex, cex.getCause(), "Exception not thrown");
}

View File

@ -107,7 +107,7 @@ public void testExtractCauseNullCause() {
@Test
public void testExtractCauseError() {
final Error err = new AssertionError("Test");
AssertionError e =
final AssertionError e =
assertThrows(AssertionError.class, () -> ConcurrentUtils.extractCause(new ExecutionException(err)));
assertEquals(err, e, "Wrong error");
}
@ -154,7 +154,7 @@ public void testExtractCauseUncheckedNullCause() {
@Test
public void testExtractCauseUncheckedError() {
final Error err = new AssertionError("Test");
Error e = assertThrows(Error.class, () -> ConcurrentUtils.extractCauseUnchecked(new ExecutionException(err)));
final Error e = assertThrows(Error.class, () -> ConcurrentUtils.extractCauseUnchecked(new ExecutionException(err)));
assertEquals(err, e, "Wrong error");
}
@ -164,7 +164,7 @@ public void testExtractCauseUncheckedError() {
@Test
public void testExtractCauseUncheckedUncheckedException() {
final RuntimeException rex = new RuntimeException("Test");
RuntimeException r =
final RuntimeException r =
assertThrows(RuntimeException.class, () -> ConcurrentUtils.extractCauseUnchecked(new ExecutionException(rex)));
assertEquals(rex, r, "Wrong exception");
}
@ -186,7 +186,7 @@ public void testExtractCauseUncheckedChecked() {
@Test
public void testHandleCauseError() {
final Error err = new AssertionError("Test");
Error e = assertThrows(Error.class, () -> ConcurrentUtils.handleCause(new ExecutionException(err)));
final Error e = assertThrows(Error.class, () -> ConcurrentUtils.handleCause(new ExecutionException(err)));
assertEquals(err, e, "Wrong error");
}
@ -196,7 +196,7 @@ public void testHandleCauseError() {
@Test
public void testHandleCauseUncheckedException() {
final RuntimeException rex = new RuntimeException("Test");
RuntimeException r =
final RuntimeException r =
assertThrows(RuntimeException.class, () -> ConcurrentUtils.handleCause(new ExecutionException(rex)));
assertEquals(rex, r, "Wrong exception");
}
@ -207,7 +207,7 @@ public void testHandleCauseUncheckedException() {
@Test
public void testHandleCauseChecked() {
final Exception ex = new Exception("Test");
ConcurrentException cex =
final ConcurrentException cex =
assertThrows(ConcurrentException.class, () -> ConcurrentUtils.handleCause(new ExecutionException(ex)));
assertEquals(ex, cex.getCause(), "Wrong cause");
}
@ -231,7 +231,7 @@ public void testHandleCauseNull() throws ConcurrentException {
@Test
public void testHandleCauseUncheckedError() {
final Error err = new AssertionError("Test");
Error e = assertThrows(Error.class, () -> ConcurrentUtils.handleCauseUnchecked(new ExecutionException(err)));
final Error e = assertThrows(Error.class, () -> ConcurrentUtils.handleCauseUnchecked(new ExecutionException(err)));
assertEquals(err, e, "Wrong error");
}
@ -241,7 +241,7 @@ public void testHandleCauseUncheckedError() {
@Test
public void testHandleCauseUncheckedUncheckedException() {
final RuntimeException rex = new RuntimeException("Test");
RuntimeException r =
final RuntimeException r =
assertThrows(RuntimeException.class, () -> ConcurrentUtils.handleCauseUnchecked(new ExecutionException(rex)));
assertEquals(rex, r, "Wrong exception");
}
@ -252,7 +252,7 @@ public void testHandleCauseUncheckedUncheckedException() {
@Test
public void testHandleCauseUncheckedChecked() {
final Exception ex = new Exception("Test");
ConcurrentRuntimeException crex =
final ConcurrentRuntimeException crex =
assertThrows(ConcurrentRuntimeException.class, () -> ConcurrentUtils.handleCauseUnchecked(new ExecutionException(ex)));
assertEquals(ex, crex.getCause(), "Wrong cause");
}
@ -346,7 +346,7 @@ public void testInitializeUncheckedEx() throws ConcurrentException {
final Exception cause = new Exception();
EasyMock.expect(init.get()).andThrow(new ConcurrentException(cause));
EasyMock.replay(init);
ConcurrentRuntimeException crex =
final ConcurrentRuntimeException crex =
assertThrows(ConcurrentRuntimeException.class, () -> ConcurrentUtils.initializeUnchecked(init));
assertSame(cause, crex.getCause(), "Wrong cause");
EasyMock.verify(init);
@ -524,7 +524,7 @@ public void testCreateIfAbsentUncheckedException()
final Exception ex = new Exception();
EasyMock.expect(init.get()).andThrow(new ConcurrentException(ex));
EasyMock.replay(init);
ConcurrentRuntimeException crex =
final ConcurrentRuntimeException crex =
assertThrows(
ConcurrentRuntimeException.class,
() -> ConcurrentUtils.createIfAbsentUnchecked(new ConcurrentHashMap<>(), "test", init));

View File

@ -161,8 +161,8 @@ public void testOpeningWhenThresholdReachedThroughBatch() {
final long timeIncrement = NANO_FACTOR / OPENING_THRESHOLD - 1;
final EventCountCircuitBreakerTestImpl breaker = new EventCountCircuitBreakerTestImpl(OPENING_THRESHOLD, 1,
TimeUnit.SECONDS, CLOSING_THRESHOLD, 1, TimeUnit.SECONDS);
long startTime = timeIncrement * (OPENING_THRESHOLD + 1);
boolean open = !breaker.at(startTime).incrementAndCheckState(OPENING_THRESHOLD + 1);
final long startTime = timeIncrement * (OPENING_THRESHOLD + 1);
final boolean open = !breaker.at(startTime).incrementAndCheckState(OPENING_THRESHOLD + 1);
assertTrue(open, "Not open");
assertFalse(breaker.isClosed(), "Closed");
}

View File

@ -273,7 +273,7 @@ public void testInitializeRuntimeEx() {
child.ex = new RuntimeException();
initializer.addInitializer(CHILD_INIT, child);
initializer.start();
Exception ex = assertThrows(Exception.class, initializer::get);
final Exception ex = assertThrows(Exception.class, initializer::get);
assertEquals(child.ex, ex, "Wrong exception");
}

View File

@ -69,7 +69,7 @@ public void testAddEventListenerWithNoAddMethod() {
final PropertyChangeSource src = new PropertyChangeSource();
final EventCountingInvociationHandler handler = new EventCountingInvociationHandler();
final ObjectChangeListener listener = handler.createListener(ObjectChangeListener.class);
IllegalArgumentException e =
final IllegalArgumentException e =
assertThrows(IllegalArgumentException.class, () -> EventUtils.addEventListener(src, ObjectChangeListener.class, listener));
assertEquals("Class " + src.getClass().getName() + " does not have a public add" + ObjectChangeListener.class.getSimpleName() + " method which takes a parameter of type " + ObjectChangeListener.class.getName() + ".",
e.getMessage());
@ -90,7 +90,7 @@ public void testAddEventListenerWithPrivateAddMethod() {
final PropertyChangeSource src = new PropertyChangeSource();
final EventCountingInvociationHandler handler = new EventCountingInvociationHandler();
final VetoableChangeListener listener = handler.createListener(VetoableChangeListener.class);
IllegalArgumentException e =
final IllegalArgumentException e =
assertThrows(IllegalArgumentException.class, () -> EventUtils.addEventListener(src, VetoableChangeListener.class, listener));
assertEquals("Class " + src.getClass().getName() + " does not have a public add" + VetoableChangeListener.class.getSimpleName() + " method which takes a parameter of type " + VetoableChangeListener.class.getName() + ".",
e.getMessage());

View File

@ -566,7 +566,7 @@ public void testRemoveCommonFrames_ListList() {
@Test
public void testThrow() {
final Exception expected = new InterruptedException();
Exception actual = assertThrows(Exception.class, () -> ExceptionUtils.rethrow(expected));
final Exception actual = assertThrows(Exception.class, () -> ExceptionUtils.rethrow(expected));
assertSame(expected, actual);
}
@ -678,25 +678,25 @@ public void testThrowableOfType_ThrowableClassInt() {
@Test
public void testWrapAndUnwrapCheckedException() {
Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new IOException()));
final Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new IOException()));
assertTrue(ExceptionUtils.hasCause(t, IOException.class));
}
@Test
public void testWrapAndUnwrapError() {
Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new OutOfMemoryError()));
final Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new OutOfMemoryError()));
assertTrue(ExceptionUtils.hasCause(t, Error.class));
}
@Test
public void testWrapAndUnwrapRuntimeException() {
Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new IllegalArgumentException()));
final Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new IllegalArgumentException()));
assertTrue(ExceptionUtils.hasCause(t, RuntimeException.class));
}
@Test
public void testWrapAndUnwrapThrowable() {
Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new TestThrowable()));
final Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new TestThrowable()));
assertTrue(ExceptionUtils.hasCause(t, TestThrowable.class));
}
}

View File

@ -36,6 +36,7 @@
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
@ -172,7 +173,7 @@ public void testGetAllFields() {
final Field[] allFields = FieldUtils.getAllFields(PublicChild.class);
// Under Jacoco,0.8.1 and Java 10, the field count is 7.
int expected = 5;
for (Field field : allFields) {
for (final Field field : allFields) {
if (field.getName().equals(JACOCO_DATA_FIELD_NAME)) {
expected++;
}
@ -188,11 +189,11 @@ public void testGetAllFieldsList() {
final List<Field> fieldsInteger = Arrays.asList(Integer.class.getDeclaredFields());
final List<Field> allFieldsInteger = new ArrayList<>(fieldsInteger);
allFieldsInteger.addAll(fieldsNumber);
assertEquals(allFieldsInteger, FieldUtils.getAllFieldsList(Integer.class));
assertEquals(new HashSet(allFieldsInteger), new HashSet(FieldUtils.getAllFieldsList(Integer.class)));
final List<Field> allFields = FieldUtils.getAllFieldsList(PublicChild.class);
// Under Jacoco,0.8.1 and Java 10, the field count is 7.
int expected = 5;
for (Field field : allFields) {
for (final Field field : allFields) {
if (field.getName().equals(JACOCO_DATA_FIELD_NAME)) {
expected++;
}
@ -671,7 +672,7 @@ public void testReadDeclaredNamedFieldForceAccess() throws Exception {
@Test
public void testWriteStaticField() throws Exception {
Field field = StaticContainer.class.getDeclaredField("mutablePublic");
final Field field = StaticContainer.class.getDeclaredField("mutablePublic");
FieldUtils.writeStaticField(field, "new");
assertEquals("new", StaticContainer.mutablePublic);
assertThrows(
@ -829,7 +830,7 @@ public void testWriteDeclaredNamedStaticFieldForceAccess() throws Exception {
@Test
public void testWriteField() throws Exception {
Field field = parentClass.getDeclaredField("s");
final Field field = parentClass.getDeclaredField("s");
FieldUtils.writeField(field, publicChild, "S");
assertEquals("S", field.get(publicChild));
assertThrows(
@ -1048,10 +1049,10 @@ public void testRemoveFinalModifierAccessNotNeeded() throws Exception {
* @param forceAccess {@link Boolean} to be curried into
* {@link FieldUtils#removeFinalModifier(Field, boolean)}.
*/
private void callRemoveFinalModifierCheckForException(Field field, Boolean forceAccess) {
private void callRemoveFinalModifierCheckForException(final Field field, final Boolean forceAccess) {
try {
FieldUtils.removeFinalModifier(field, forceAccess);
} catch (UnsupportedOperationException exception) {
} catch (final UnsupportedOperationException exception) {
if (SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_12)) {
assertTrue(exception.getCause() instanceof NoSuchFieldException);
} else {

View File

@ -521,7 +521,7 @@ public void testGetCharsIntIntCharArrayInt( ) {
final StrBuilder sb = new StrBuilder();
sb.append("junit");
char[] a = new char[5];
final char[] a = new char[5];
sb.getChars(0, 5, a, 0);
assertArrayEquals(new char[]{'j', 'u', 'n', 'i', 't'}, a);
@ -538,7 +538,7 @@ public void testGetCharsIntIntCharArrayInt( ) {
//-----------------------------------------------------------------------
@Test
public void testDeleteIntInt() {
StrBuilder sb = new StrBuilder("abc");
final StrBuilder sb = new StrBuilder("abc");
sb.delete(0, 1);
assertEquals("bc", sb.toString());
sb.delete(1, 2);
@ -679,7 +679,7 @@ public void testDeleteFirst_StrMatcher() {
// -----------------------------------------------------------------------
@Test
public void testReplace_int_int_String() {
StrBuilder sb = new StrBuilder("abc");
final StrBuilder sb = new StrBuilder("abc");
sb.replace(0, 1, "d");
assertEquals("dbc", sb.toString());
sb.replace(0, 1, "aaa");
@ -693,12 +693,12 @@ public void testReplace_int_int_String() {
sb.replace(0, 1000, "text");
assertEquals("text", sb.toString());
StrBuilder sb1 = new StrBuilder("atext");
final StrBuilder sb1 = new StrBuilder("atext");
sb1.replace(1, 1, "ny");
assertEquals("anytext", sb1.toString());
assertThrows(IndexOutOfBoundsException.class, () -> sb1.replace(2, 1, "anything"));
StrBuilder sb2 = new StrBuilder();
final StrBuilder sb2 = new StrBuilder();
assertThrows(IndexOutOfBoundsException.class, () -> sb2.replace(1, 2, "anything"));
assertThrows(IndexOutOfBoundsException.class, () -> sb2.replace(-1, 1, "anything"));
}
@ -960,13 +960,13 @@ public void testReplace_StrMatcher_String_int_int_int_VaryStartIndex() {
sb.replace(StrMatcher.stringMatcher("aa"), "-", 10, sb.length(), -1);
assertEquals("aaxaaaayaa", sb.toString());
StrBuilder sb1 = new StrBuilder("aaxaaaayaa");
final StrBuilder sb1 = new StrBuilder("aaxaaaayaa");
assertThrows(
IndexOutOfBoundsException.class,
() -> sb1.replace(StrMatcher.stringMatcher("aa"), "-", 11, sb1.length(), -1));
assertEquals("aaxaaaayaa", sb1.toString());
StrBuilder sb2 = new StrBuilder("aaxaaaayaa");
final StrBuilder sb2 = new StrBuilder("aaxaaaayaa");
assertThrows(
IndexOutOfBoundsException.class,
() -> sb2.replace(StrMatcher.stringMatcher("aa"), "-", -1, sb2.length(), -1));
@ -1019,7 +1019,7 @@ public void testReplace_StrMatcher_String_int_int_int_VaryEndIndex() {
sb.replace(StrMatcher.stringMatcher("aa"), "-", 0, 1000, -1);
assertEquals("-x--y-", sb.toString());
StrBuilder sb1 = new StrBuilder("aaxaaaayaa");
final StrBuilder sb1 = new StrBuilder("aaxaaaayaa");
assertThrows(
IndexOutOfBoundsException.class,
() -> sb1.replace(StrMatcher.stringMatcher("aa"), "-", 2, 1, -1));

View File

@ -245,7 +245,7 @@ public void testCyclicReplacement() {
map.put("critterSpeed", "quick");
map.put("critterColor", "brown");
map.put("critterType", "${animal}");
StrSubstitutor sub = new StrSubstitutor(map);
final StrSubstitutor sub = new StrSubstitutor(map);
assertThrows(
IllegalStateException.class,
() -> sub.replace("The ${animal} jumps over the ${target}."),
@ -253,7 +253,7 @@ public void testCyclicReplacement() {
// also check even when default value is set.
map.put("critterType", "${animal:-fox}");
StrSubstitutor sub2 = new StrSubstitutor(map);
final StrSubstitutor sub2 = new StrSubstitutor(map);
assertThrows(
IllegalStateException.class,
() -> sub2.replace("The ${animal} jumps over the ${target}."),

View File

@ -1514,10 +1514,10 @@ public void testWeekIterator() {
it = DateUtils.iterator((Object) now, DateUtils.RANGE_WEEK_CENTER);
assertWeekIterator(it, centered);
Iterator<?> it2 = DateUtils.iterator((Object) now.getTime(), DateUtils.RANGE_WEEK_CENTER);
final Iterator<?> it2 = DateUtils.iterator((Object) now.getTime(), DateUtils.RANGE_WEEK_CENTER);
assertWeekIterator(it2, centered);
assertThrows(NoSuchElementException.class, it2::next);
Iterator<?> it3 = DateUtils.iterator(now, DateUtils.RANGE_WEEK_CENTER);
final Iterator<?> it3 = DateUtils.iterator(now, DateUtils.RANGE_WEEK_CENTER);
it3.next();
assertThrows(UnsupportedOperationException.class, it3::remove);

View File

@ -140,7 +140,7 @@ public void testLowerCasePP(final String format, final String input, final Local
checkParsePosition(input.toLowerCase(locale), format, locale, valid);
}
private void checkParse(final String formattedDate, String format, Locale locale, boolean valid) {
private void checkParse(final String formattedDate, final String format, final Locale locale, final boolean valid) {
final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
sdf.setTimeZone(timeZone);
final DateParser fdf = new FastDateParser(format, timeZone, locale);
@ -176,7 +176,7 @@ private void checkParse(final String formattedDate, String format, Locale locale
assertEquals(sdfE, fdfE, locale.toString()+" "+formattedDate + " expected same Exception ");
}
}
private void checkParsePosition(final String formattedDate, String format, Locale locale, boolean valid) {
private void checkParsePosition(final String formattedDate, final String format, final Locale locale, final boolean valid) {
final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
sdf.setTimeZone(timeZone);
final DateParser fdf = new FastDateParser(format, timeZone, locale);

View File

@ -37,7 +37,7 @@ public static Stream<TimeZone> data() {
@ParameterizedTest
@MethodSource("data")
public void testCalendarTimezoneRespected(TimeZone timeZone) {
public void testCalendarTimezoneRespected(final TimeZone timeZone) {
final Calendar cal = Calendar.getInstance(timeZone);
final SimpleDateFormat sdf = new SimpleDateFormat(PATTERN);

View File

@ -54,7 +54,7 @@ public static Stream<Arguments> data() {
@ParameterizedTest
@MethodSource("data")
public void testParser(Calendar vulgar, String isoForm) {
public void testParser(final Calendar vulgar, final String isoForm) {
final DateParser parser = new FastDateParser("YYYY-'W'ww-u", TimeZone.getDefault(), Locale.getDefault());
final Calendar cal = Calendar.getInstance();
@ -68,7 +68,7 @@ public void testParser(Calendar vulgar, String isoForm) {
@ParameterizedTest
@MethodSource("data")
public void testPrinter(Calendar vulgar, String isoForm) {
public void testPrinter(final Calendar vulgar, final String isoForm) {
final FastDatePrinter printer = new FastDatePrinter("YYYY-'W'ww-u", TimeZone.getDefault(), Locale.getDefault());
vulgar.setMinimalDaysInFirstWeek(4);

View File

@ -154,7 +154,7 @@ public void testPairOfObjects() {
assertNull(pair2.getLeft());
assertEquals("bar", pair2.right);
assertEquals("bar", pair2.getRight());
ImmutablePair pair3 = ImmutablePair.of(null, null);
final ImmutablePair pair3 = ImmutablePair.of(null, null);
assertNull(pair3.left);
assertNull(pair3.right);
}
@ -182,11 +182,11 @@ public void testToString() {
@Test
public void testUseAsKeyOfHashMap() {
HashMap<ImmutablePair<Object, Object>, String> map = new HashMap<>();
Object o1 = new Object();
Object o2 = new Object();
ImmutablePair<Object, Object> key1 = ImmutablePair.of(o1, o2);
String value1 = "a1";
final HashMap<ImmutablePair<Object, Object>, String> map = new HashMap<>();
final Object o1 = new Object();
final Object o2 = new Object();
final ImmutablePair<Object, Object> key1 = ImmutablePair.of(o1, o2);
final String value1 = "a1";
map.put(key1, value1);
assertEquals(value1, map.get(key1));
assertEquals(value1, map.get(ImmutablePair.of(o1, o2)));
@ -194,17 +194,17 @@ public void testUseAsKeyOfHashMap() {
@Test
public void testUseAsKeyOfTreeMap() {
TreeMap<ImmutablePair<Integer, Integer>, String> map = new TreeMap<>();
final TreeMap<ImmutablePair<Integer, Integer>, String> map = new TreeMap<>();
map.put(ImmutablePair.of(1, 2), "12");
map.put(ImmutablePair.of(1, 1), "11");
map.put(ImmutablePair.of(0, 1), "01");
ArrayList<ImmutablePair<Integer, Integer>> expected = new ArrayList<>();
final ArrayList<ImmutablePair<Integer, Integer>> expected = new ArrayList<>();
expected.add(ImmutablePair.of(0, 1));
expected.add(ImmutablePair.of(1, 1));
expected.add(ImmutablePair.of(1, 2));
Iterator<Entry<ImmutablePair<Integer, Integer>, String>> it = map.entrySet().iterator();
for (ImmutablePair<Integer, Integer> item : expected) {
Entry<ImmutablePair<Integer, Integer>, String> entry = it.next();
final Iterator<Entry<ImmutablePair<Integer, Integer>, String>> it = map.entrySet().iterator();
for (final ImmutablePair<Integer, Integer> item : expected) {
final Entry<ImmutablePair<Integer, Integer>, String> entry = it.next();
assertEquals(item, entry.getKey());
assertEquals(item.getLeft() + "" + item.getRight(), entry.getValue());
}

View File

@ -163,12 +163,12 @@ public void testTripleOf() {
@Test
public void testUseAsKeyOfHashMap() {
HashMap<ImmutableTriple<Object, Object, Object>, String> map = new HashMap<>();
Object o1 = new Object();
Object o2 = new Object();
Object o3 = new Object();
ImmutableTriple<Object, Object, Object> key1 = ImmutableTriple.of(o1, o2, o3);
String value1 = "a1";
final HashMap<ImmutableTriple<Object, Object, Object>, String> map = new HashMap<>();
final Object o1 = new Object();
final Object o2 = new Object();
final Object o3 = new Object();
final ImmutableTriple<Object, Object, Object> key1 = ImmutableTriple.of(o1, o2, o3);
final String value1 = "a1";
map.put(key1, value1);
assertEquals(value1, map.get(key1));
assertEquals(value1, map.get(ImmutableTriple.of(o1, o2, o3)));
@ -176,17 +176,17 @@ public void testUseAsKeyOfHashMap() {
@Test
public void testUseAsKeyOfTreeMap() {
TreeMap<ImmutableTriple<Integer, Integer, Integer>, String> map = new TreeMap<>();
final TreeMap<ImmutableTriple<Integer, Integer, Integer>, String> map = new TreeMap<>();
map.put(ImmutableTriple.of(0, 1, 2), "012");
map.put(ImmutableTriple.of(0, 1, 1), "011");
map.put(ImmutableTriple.of(0, 0, 1), "001");
ArrayList<ImmutableTriple<Integer, Integer, Integer>> expected = new ArrayList<>();
final ArrayList<ImmutableTriple<Integer, Integer, Integer>> expected = new ArrayList<>();
expected.add(ImmutableTriple.of(0, 0, 1));
expected.add(ImmutableTriple.of(0, 1, 1));
expected.add(ImmutableTriple.of(0, 1, 2));
Iterator<Entry<ImmutableTriple<Integer, Integer, Integer>, String>> it = map.entrySet().iterator();
for (ImmutableTriple<Integer, Integer, Integer> item : expected) {
Entry<ImmutableTriple<Integer, Integer, Integer>, String> entry = it.next();
final Iterator<Entry<ImmutableTriple<Integer, Integer, Integer>, String>> it = map.entrySet().iterator();
for (final ImmutableTriple<Integer, Integer, Integer> item : expected) {
final Entry<ImmutableTriple<Integer, Integer, Integer>, String> entry = it.next();
assertEquals(item, entry.getKey());
assertEquals(item.getLeft() + "" + item.getMiddle() + "" + item.getRight(), entry.getValue());
}

View File

@ -123,7 +123,7 @@ public void testPairOfObjects() {
final MutablePair<Object, String> pair2 = MutablePair.of(null, "bar");
assertNull(pair2.getLeft());
assertEquals("bar", pair2.getRight());
MutablePair pair3 = MutablePair.of(null, null);
final MutablePair pair3 = MutablePair.of(null, null);
assertNull(pair3.left);
assertNull(pair3.right);
}

View File

@ -123,7 +123,7 @@ public void testPairOfObjects() {
assertTrue(pair2 instanceof ImmutablePair<?, ?>);
assertNull(((ImmutablePair<Object, String>) pair2).left);
assertEquals("bar", ((ImmutablePair<Object, String>) pair2).right);
Pair pair3 = Pair.of(null, null);
final Pair pair3 = Pair.of(null, null);
assertNull(pair3.getLeft());
assertNull(pair3.getRight());
}