Merge branch 'master' of https://github.com/apache/commons-lang into fix_FastDateParserTest
This commit is contained in:
commit
c7c2dd783a
10
pom.xml
10
pom.xml
|
@ -22,7 +22,7 @@
|
|||
<parent>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-parent</artifactId>
|
||||
<version>50</version>
|
||||
<version>51</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
|
@ -612,8 +612,8 @@
|
|||
<uberjar.name>benchmarks</uberjar.name>
|
||||
|
||||
<commons.jacoco.version>0.8.5</commons.jacoco.version>
|
||||
<commons.surefire.version>3.0.0-M4</commons.surefire.version>
|
||||
<commons.javadoc.version>3.1.1</commons.javadoc.version>
|
||||
<commons.surefire.version>3.0.0-M5</commons.surefire.version>
|
||||
<commons.javadoc.version>3.2.0</commons.javadoc.version>
|
||||
|
||||
<!-- never generate report if there are binary incompatible changes -->
|
||||
<commons.japicmp.breakBuildOnBinaryIncompatibleModifications>true</commons.japicmp.breakBuildOnBinaryIncompatibleModifications>
|
||||
|
@ -764,7 +764,7 @@
|
|||
<dependency>
|
||||
<groupId>com.github.spotbugs</groupId>
|
||||
<artifactId>spotbugs</artifactId>
|
||||
<version>4.0.4</version>
|
||||
<version>4.0.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<configuration>
|
||||
|
@ -778,7 +778,7 @@
|
|||
<dependency>
|
||||
<groupId>biz.aQute.bnd</groupId>
|
||||
<artifactId>biz.aQute.bndlib</artifactId>
|
||||
<version>5.1.0</version>
|
||||
<version>5.1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
|
|
|
@ -48,10 +48,6 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
<release version="3.11" date="2020-MM-DD" description="New features and bug fixes..">
|
||||
<action type="update" dev="kinow" due-to="XenoAmess">remove encoding and docEncoding and use inherited values from commons-parent</action>
|
||||
<action type="fix" dev="kinow" due-to="contextshuffling">Fix Javadoc for StringUtils.appendIfMissingIgnoreCase() #507.</action>
|
||||
<action type="update" dev="ggregory">org.junit-pioneer:junit-pioneer 0.5.4 -> 0.6.0.</action>
|
||||
<action type="update" dev="ggregory">org.junit.jupiter:junit-jupiter 5.6.0 -> 5.6.1.</action>
|
||||
<action type="update" dev="ggregory">com.github.spotbugs:spotbugs 4.0.0 -> 4.0.4.</action>
|
||||
<action type="update" dev="ggregory">com.puppycrawl.tools:checkstyle 8.29 -> 8.33.</action>
|
||||
<action type="update" dev="ggregory" due-to="Isira Seneviratne, Bruno P. Kinoshita">Simplify null checks in Pair.hashCode() using Objects.hashCode(). #517.</action>
|
||||
<action type="update" dev="ggregory" due-to="Isira Seneviratne, Bruno P. Kinoshita">Simplify null checks in Triple.hashCode() using Objects.hashCode(). #516.</action>
|
||||
<action type="update" dev="ggregory" due-to="Isira Seneviratne, Bruno P. Kinoshita">Simplify some if statements in StringUtils. #521.</action>
|
||||
|
@ -75,9 +71,20 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
<action issue="LANG-1558" type="update" dev="ggregory" due-to="XenoAmess">Simplify if as some conditions are covered by others #543.</action>
|
||||
<action issue="LANG-1528" type="fix" dev="ggregory" due-to="Edwin Delgado H">StringUtils.replaceEachRepeatedly gives IllegalStateException #505.</action>
|
||||
<action issue="LANG-1570" type="add" dev="ggregory" due-to="Edgar Asatryan">Add JavaVersion enum constants for Java 14 and 15. #553.</action>
|
||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add JavaVersion enum constants for Java 16.</action>
|
||||
<action issue="LANG-1556" type="add" dev="ggregory" due-to="XenoAmess">Use Java 8 lambdas and Map operations.</action>
|
||||
<action issue="LANG-1565" type="add" dev="ggregory" due-to="XenoAmess">Change removeLastFieldSeparator to use endsWith #550.</action>
|
||||
<action issue="LANG-1557" type="add" dev="ggregory" due-to="XenoAmess, Gary Gregory">Change a Pattern to a static final field, for not letting it compile each time the function invoked. #542.</action>
|
||||
<action type="add" dev="ggregory">Add ImmutablePair factory methods left() and right().</action>
|
||||
<action type="add" dev="ggregory">Add ObjectUtils.toString(Object, Supplier<String>).</action>
|
||||
<action issue="LANG-1567" type="update" dev="ggregory" due-to="Miguel Muñoz, Bruno P. Kinoshita, Gary Gregory">Fixed Javadocs for setTestRecursive() #556.</action>
|
||||
<action issue="LANG-1542" type="update" dev="ggregory" due-to=" Trần Ngọc Khoa, Gary Gregory">ToStringBuilder.reflectionToString - Wrong JSON format when object has a List of Enum.</action>
|
||||
<action type="update" dev="ggregory">org.apache.commons:commons-parent 50 -> 51.</action>
|
||||
<action type="update" dev="ggregory">org.junit-pioneer:junit-pioneer 0.5.4 -> 0.6.0.</action>
|
||||
<action type="update" dev="ggregory">org.junit.jupiter:junit-jupiter 5.6.0 -> 5.6.1.</action>
|
||||
<action type="update" dev="ggregory">com.github.spotbugs:spotbugs 4.0.0 -> 4.0.6.</action>
|
||||
<action type="update" dev="ggregory">com.puppycrawl.tools:checkstyle 8.29 -> 8.33.</action>
|
||||
<action type="update" dev="ggregory">commons.surefire.version 3.0.0-M4 -> 3.0.0-M5..</action>
|
||||
</release>
|
||||
|
||||
<release version="3.10" date="2020-03-22" description="New features and bug fixes. Requires Java 8, supports Java 9, 10, 11.">
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import org.apache.commons.lang3.arch.Processor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.lang3.arch.Processor;
|
||||
|
||||
/**
|
||||
* An utility class for the os.arch System Property. The class defines methods for
|
||||
* identifying the architecture of the current JVM.
|
||||
|
|
|
@ -295,8 +295,8 @@ static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, fi
|
|||
}
|
||||
|
||||
// The real same check as in String.regionMatches():
|
||||
char u1 = Character.toUpperCase(c1);
|
||||
char u2 = Character.toUpperCase(c2);
|
||||
final char u1 = Character.toUpperCase(c1);
|
||||
final char u2 = Character.toUpperCase(c2);
|
||||
if (u1 != u2 && Character.toLowerCase(u1) != Character.toLowerCase(u2)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -33,13 +33,6 @@
|
|||
|
||||
import org.apache.commons.lang3.Streams.FailableStream;
|
||||
import org.apache.commons.lang3.function.FailableBooleanSupplier;
|
||||
import org.apache.commons.lang3.function.FailableDoubleBinaryOperator;
|
||||
import org.apache.commons.lang3.function.FailableDoubleConsumer;
|
||||
import org.apache.commons.lang3.function.FailableDoubleSupplier;
|
||||
import org.apache.commons.lang3.function.FailableIntConsumer;
|
||||
import org.apache.commons.lang3.function.FailableIntSupplier;
|
||||
import org.apache.commons.lang3.function.FailableLongConsumer;
|
||||
import org.apache.commons.lang3.function.FailableLongSupplier;
|
||||
|
||||
/**
|
||||
* This class provides utility functions, and classes for working with the {@code java.util.function} package, or more
|
||||
|
@ -313,42 +306,6 @@ public static <O, T extends Throwable> void accept(final FailableConsumer<O, T>
|
|||
run(() -> consumer.accept(object));
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes a consumer and rethrows any exception as a {@link RuntimeException}.
|
||||
*
|
||||
* @param consumer the consumer to consume
|
||||
* @param value the value to consume by {@code consumer}
|
||||
* @param <T> the type of checked exception the consumer may throw
|
||||
* @since 3.11
|
||||
*/
|
||||
public static <T extends Throwable> void accept(final FailableDoubleConsumer<T> consumer, final double value) {
|
||||
run(() -> consumer.accept(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes a consumer and rethrows any exception as a {@link RuntimeException}.
|
||||
*
|
||||
* @param consumer the consumer to consume
|
||||
* @param value the value to consume by {@code consumer}
|
||||
* @param <T> the type of checked exception the consumer may throw
|
||||
* @since 3.11
|
||||
*/
|
||||
public static <T extends Throwable> void accept(final FailableIntConsumer<T> consumer, final int value) {
|
||||
run(() -> consumer.accept(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes a consumer and rethrows any exception as a {@link RuntimeException}.
|
||||
*
|
||||
* @param consumer the consumer to consume
|
||||
* @param value the value to consume by {@code consumer}
|
||||
* @param <T> the type of checked exception the consumer may throw
|
||||
* @since 3.11
|
||||
*/
|
||||
public static <T extends Throwable> void accept(final FailableLongConsumer<T> consumer, final long value) {
|
||||
run(() -> consumer.accept(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a function and rethrows any exception as a {@link RuntimeException}.
|
||||
*
|
||||
|
@ -380,21 +337,6 @@ public static <I, O, T extends Throwable> O apply(final FailableFunction<I, O, T
|
|||
return get(() -> function.apply(input));
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a function and rethrows any exception as a {@link RuntimeException}.
|
||||
*
|
||||
* @param function the function to apply
|
||||
* @param left the first input to apply {@code function} on
|
||||
* @param right the second input to apply {@code function} on
|
||||
* @param <T> the type of checked exception the function may throw
|
||||
* @return the value returned from the function
|
||||
* @since 3.11
|
||||
*/
|
||||
public static <T extends Throwable> double applyAsDouble(final FailableDoubleBinaryOperator<T> function,
|
||||
final double left, final double right) {
|
||||
return getAsDouble(() -> function.applyAsDouble(left, right));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given {@link FailableBiConsumer} into a standard {@link BiConsumer}.
|
||||
*
|
||||
|
@ -542,9 +484,8 @@ public static <O, T extends Throwable> O get(final FailableSupplier<O, T> suppli
|
|||
* @param supplier The boolean supplier to invoke.
|
||||
* @param <T> The type of checked exception, which the supplier can throw.
|
||||
* @return The boolean, which has been created by the supplier
|
||||
* @since 3.11
|
||||
*/
|
||||
public static <T extends Throwable> boolean getAsBoolean(final FailableBooleanSupplier<T> supplier) {
|
||||
private static <T extends Throwable> boolean getAsBoolean(final FailableBooleanSupplier<T> supplier) {
|
||||
try {
|
||||
return supplier.getAsBoolean();
|
||||
} catch (final Throwable t) {
|
||||
|
@ -552,54 +493,6 @@ public static <T extends Throwable> boolean getAsBoolean(final FailableBooleanSu
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a double supplier, and returns the result.
|
||||
*
|
||||
* @param supplier The double supplier to invoke.
|
||||
* @param <T> The type of checked exception, which the supplier can throw.
|
||||
* @return The boolean, which has been created by the supplier
|
||||
* @since 3.11
|
||||
*/
|
||||
public static <T extends Throwable> double getAsDouble(final FailableDoubleSupplier<T> supplier) {
|
||||
try {
|
||||
return supplier.getAsDouble();
|
||||
} catch (final Throwable t) {
|
||||
throw rethrow(t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes an int supplier, and returns the result.
|
||||
*
|
||||
* @param supplier The int supplier to invoke.
|
||||
* @param <T> The type of checked exception, which the supplier can throw.
|
||||
* @return The boolean, which has been created by the supplier
|
||||
* @since 3.11
|
||||
*/
|
||||
public static <T extends Throwable> int getAsInt(final FailableIntSupplier<T> supplier) {
|
||||
try {
|
||||
return supplier.getAsInt();
|
||||
} catch (final Throwable t) {
|
||||
throw rethrow(t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a long supplier, and returns the result.
|
||||
*
|
||||
* @param supplier The long supplier to invoke.
|
||||
* @param <T> The type of checked exception, which the supplier can throw.
|
||||
* @return The boolean, which has been created by the supplier
|
||||
* @since 3.11
|
||||
*/
|
||||
public static <T extends Throwable> long getAsLong(final FailableLongSupplier<T> supplier) {
|
||||
try {
|
||||
return supplier.getAsLong();
|
||||
} catch (final Throwable t) {
|
||||
throw rethrow(t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Rethrows a {@link Throwable} as an unchecked exception. If the argument is already unchecked, namely a
|
||||
|
@ -697,7 +590,7 @@ public static <O> FailableStream<O> stream(final Stream<O> stream) {
|
|||
*/
|
||||
public static <O1, O2, T extends Throwable> boolean test(final FailableBiPredicate<O1, O2, T> predicate,
|
||||
final O1 object1, final O2 object2) {
|
||||
return get(() -> predicate.test(object1, object2));
|
||||
return getAsBoolean(() -> predicate.test(object1, object2));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -710,7 +603,7 @@ public static <O1, O2, T extends Throwable> boolean test(final FailableBiPredica
|
|||
* @return the boolean value returned by the predicate
|
||||
*/
|
||||
public static <O, T extends Throwable> boolean test(final FailablePredicate<O, T> predicate, final O object) {
|
||||
return get(() -> predicate.test(object));
|
||||
return getAsBoolean(() -> predicate.test(object));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -129,6 +129,13 @@ public enum JavaVersion {
|
|||
*/
|
||||
JAVA_15(15.0f, "15"),
|
||||
|
||||
/**
|
||||
* Java 16
|
||||
*
|
||||
* @since 3.11
|
||||
*/
|
||||
JAVA_16(16.0f, "16"),
|
||||
|
||||
/**
|
||||
* The most recent java version. Mainly introduced to avoid to break when a new version of Java is used.
|
||||
*/
|
||||
|
@ -242,6 +249,8 @@ static JavaVersion get(final String nom) {
|
|||
return JAVA_14;
|
||||
} else if ("15".equals(nom)) {
|
||||
return JAVA_15;
|
||||
} else if ("16".equals(nom)) {
|
||||
return JAVA_16;
|
||||
}
|
||||
final float v = toFloatVersion(nom);
|
||||
if ((v - 1.) < 1.) { // then we need to check decimals > .9
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -21,11 +21,11 @@
|
|||
import java.text.Normalizer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -6693,8 +6693,8 @@ private static String replaceEach(
|
|||
|
||||
// if recursing, this shouldn't be less than 0
|
||||
if (timeToLive < 0) {
|
||||
Set<String> searchSet = new HashSet<>(Arrays.asList(searchList));
|
||||
Set<String> replacementSet = new HashSet<>(Arrays.asList(replacementList));
|
||||
final Set<String> searchSet = new HashSet<>(Arrays.asList(searchList));
|
||||
final Set<String> replacementSet = new HashSet<>(Arrays.asList(replacementList));
|
||||
searchSet.retainAll(replacementSet);
|
||||
if (searchSet.size() > 0) {
|
||||
throw new IllegalStateException("Aborting to protect against StackOverflowError - " +
|
||||
|
@ -8277,7 +8277,7 @@ public static String[] stripAll(final String... strs) {
|
|||
* @return the stripped Strings, {@code null} if null array input
|
||||
*/
|
||||
public static String[] stripAll(final String[] strs, final String stripChars) {
|
||||
int strsLen = ArrayUtils.getLength(strs);
|
||||
final int strsLen = ArrayUtils.getLength(strs);
|
||||
if (strsLen == 0) {
|
||||
return strs;
|
||||
}
|
||||
|
|
|
@ -245,9 +245,12 @@ public EqualsBuilder setTestTransients(final boolean testTransients) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set whether to include transient fields when reflectively comparing objects.
|
||||
* @param testRecursive whether to do a recursive test
|
||||
* Set whether to test fields recursively, instead of using their equals method, when reflectively comparing objects.
|
||||
* String objects, which cache a hash value, are automatically excluded from recursive testing.
|
||||
* You may specify other exceptions by calling {@link #setBypassReflectionClasses(List)}.
|
||||
* @param testRecursive whether to do a recursive test
|
||||
* @return EqualsBuilder - used to chain calls.
|
||||
* @see #setBypassReflectionClasses(List)
|
||||
* @since 3.6
|
||||
*/
|
||||
public EqualsBuilder setTestRecursive(final boolean testRecursive) {
|
||||
|
@ -265,6 +268,7 @@ public EqualsBuilder setTestRecursive(final boolean testRecursive) {
|
|||
* your own set of classes here, remember to include {@code String} class, too.</p>
|
||||
* @param bypassReflectionClasses classes to bypass reflection test
|
||||
* @return EqualsBuilder - used to chain calls.
|
||||
* @see #setTestRecursive(boolean)
|
||||
* @since 3.8
|
||||
*/
|
||||
public EqualsBuilder setBypassReflectionClasses(final List<Class<?>> bypassReflectionClasses) {
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Use this annotation to exclude a field from being used by
|
||||
|
|
|
@ -624,6 +624,16 @@ protected void appendDetail(final StringBuffer buffer, final String fieldName, f
|
|||
* {@code toString}, not {@code null}
|
||||
*/
|
||||
protected void appendDetail(final StringBuffer buffer, final String fieldName, final Collection<?> coll) {
|
||||
if (coll != null && !coll.isEmpty()) {
|
||||
buffer.append(arrayStart);
|
||||
int i = 0;
|
||||
for (final Object item : coll) {
|
||||
appendDetail(buffer, fieldName, i++, item);
|
||||
}
|
||||
buffer.append(arrayEnd);
|
||||
return;
|
||||
}
|
||||
|
||||
buffer.append(coll);
|
||||
}
|
||||
|
||||
|
@ -919,19 +929,32 @@ protected void appendDetail(final StringBuffer buffer, final String fieldName, f
|
|||
buffer.append(arrayStart);
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
final Object item = array[i];
|
||||
if (i > 0) {
|
||||
buffer.append(arraySeparator);
|
||||
}
|
||||
if (item == null) {
|
||||
appendNullText(buffer, fieldName);
|
||||
|
||||
} else {
|
||||
appendInternal(buffer, fieldName, item, arrayContentDetail);
|
||||
}
|
||||
appendDetail(buffer, fieldName, i, item);
|
||||
}
|
||||
buffer.append(arrayEnd);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Append to the {@code toString} the detail of an
|
||||
* {@code Object} array item.</p>
|
||||
*
|
||||
* @param buffer the {@code StringBuffer} to populate
|
||||
* @param fieldName the field name, typically not used as already appended
|
||||
* @param i the array item index to add
|
||||
* @param item the array item to add
|
||||
* @since 3.11
|
||||
*/
|
||||
protected void appendDetail(final StringBuffer buffer, final String fieldName, final int i, final Object item) {
|
||||
if (i > 0) {
|
||||
buffer.append(arraySeparator);
|
||||
}
|
||||
if (item == null) {
|
||||
appendNullText(buffer, fieldName);
|
||||
} else {
|
||||
appendInternal(buffer, fieldName, item, arrayContentDetail);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Append to the {@code toString} the detail of an array type.</p>
|
||||
*
|
||||
|
@ -946,15 +969,7 @@ protected void reflectionAppendArrayDetail(final StringBuffer buffer, final Stri
|
|||
final int length = Array.getLength(array);
|
||||
for (int i = 0; i < length; i++) {
|
||||
final Object item = Array.get(array, i);
|
||||
if (i > 0) {
|
||||
buffer.append(arraySeparator);
|
||||
}
|
||||
if (item == null) {
|
||||
appendNullText(buffer, fieldName);
|
||||
|
||||
} else {
|
||||
appendInternal(buffer, fieldName, item, arrayContentDetail);
|
||||
}
|
||||
appendDetail(buffer, fieldName, i, item);
|
||||
}
|
||||
buffer.append(arrayEnd);
|
||||
}
|
||||
|
|
|
@ -39,30 +39,30 @@
|
|||
* the lock.</li>
|
||||
* <li>If you want to access the locked object, create a {@link FailableConsumer}. The consumer will receive the locked
|
||||
* object as a parameter. For convenience, the consumer may be implemented as a Lambda. Then invoke
|
||||
* {@link Locks.Lock#runReadLocked(FailableConsumer)}, or {@link Locks.Lock#runWriteLocked(FailableConsumer)}, passing
|
||||
* {@link Locks.Lock#acceptReadLocked(FailableConsumer)}, or {@link Locks.Lock#acceptWriteLocked(FailableConsumer)}, passing
|
||||
* the consumer.</li>
|
||||
* <li>As an alternative, if you need to produce a result object, you may use a {@link FailableFunction}. This function
|
||||
* may also be implemented as a Lambda. To have the function executed, invoke
|
||||
* {@link Locks.Lock#callReadLocked(FailableFunction)}, or {@link Locks.Lock#callWriteLocked(FailableFunction)}.</li>
|
||||
* {@link Locks.Lock#applyReadLocked(FailableFunction)}, or {@link Locks.Lock#applyWriteLocked(FailableFunction)}.</li>
|
||||
* </ol>
|
||||
*
|
||||
* Example: A thread safe logger class.
|
||||
*
|
||||
* <pre>
|
||||
* public class SimpleLogger {
|
||||
*
|
||||
* private final Lock<PrintStream> lock;
|
||||
*
|
||||
* public SimpleLogger(OutputStream out) {
|
||||
* PrintStream ps = new PrintStream(out);
|
||||
* lock = Locks.lock(ps);
|
||||
* lock = Locks.lock(new PrintStream(out));
|
||||
* }
|
||||
*
|
||||
* public void log(String message) {
|
||||
* lock.runWriteLocked((ps) -> ps.println(message));
|
||||
* lock.acceptWriteLocked((ps) -> ps.println(message));
|
||||
* }
|
||||
*
|
||||
* public void log(byte[] buffer) {
|
||||
* lock.runWriteLocked((ps) -> { ps.write(buffer); ps.println(); });
|
||||
* lock.acceptWriteLocked((ps) -> { ps.write(buffer); ps.println(); });
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
|
@ -71,30 +71,31 @@
|
|||
public class Locks {
|
||||
|
||||
public static class Lock<O extends Object> {
|
||||
private final O lockedObject;
|
||||
|
||||
private final StampedLock lock = new StampedLock();
|
||||
private final O lockedObject;
|
||||
|
||||
public Lock(final O lockedObject) {
|
||||
this.lockedObject = Objects.requireNonNull(lockedObject, "Locked Object");
|
||||
}
|
||||
|
||||
public void runReadLocked(final FailableConsumer<O, ?> consumer) {
|
||||
acceptLocked(() -> lock.readLock(), consumer);
|
||||
public void acceptReadLocked(final FailableConsumer<O, ?> consumer) {
|
||||
lockAcceptUnlock(() -> lock.readLock(), consumer);
|
||||
}
|
||||
|
||||
public void runWriteLocked(final FailableConsumer<O, ?> consumer) {
|
||||
acceptLocked(() -> lock.writeLock(), consumer);
|
||||
public void acceptWriteLocked(final FailableConsumer<O, ?> consumer) {
|
||||
lockAcceptUnlock(() -> lock.writeLock(), consumer);
|
||||
}
|
||||
|
||||
public <T> T callReadLocked(final FailableFunction<O, T, ?> function) {
|
||||
return applyLocked(() -> lock.readLock(), function);
|
||||
public <T> T applyReadLocked(final FailableFunction<O, T, ?> function) {
|
||||
return lockApplyUnlock(() -> lock.readLock(), function);
|
||||
}
|
||||
|
||||
public <T> T callWriteLocked(final FailableFunction<O, T, ?> function) {
|
||||
return applyLocked(() -> lock.writeLock(), function);
|
||||
public <T> T applyWriteLocked(final FailableFunction<O, T, ?> function) {
|
||||
return lockApplyUnlock(() -> lock.writeLock(), function);
|
||||
}
|
||||
|
||||
protected void acceptLocked(final LongSupplier stampSupplier, final FailableConsumer<O, ?> consumer) {
|
||||
protected void lockAcceptUnlock(final LongSupplier stampSupplier, final FailableConsumer<O, ?> consumer) {
|
||||
final long stamp = stampSupplier.getAsLong();
|
||||
try {
|
||||
consumer.accept(lockedObject);
|
||||
|
@ -105,7 +106,7 @@ protected void acceptLocked(final LongSupplier stampSupplier, final FailableCons
|
|||
}
|
||||
}
|
||||
|
||||
protected <T> T applyLocked(final LongSupplier stampSupplier, final FailableFunction<O, T, ?> function) {
|
||||
protected <T> T lockApplyUnlock(final LongSupplier stampSupplier, final FailableFunction<O, T, ?> function) {
|
||||
final long stamp = stampSupplier.getAsLong();
|
||||
try {
|
||||
return function.apply(lockedObject);
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.concurrent;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* A specialized <em>semaphore</em> implementation that provides a number of
|
||||
|
|
|
@ -24,12 +24,12 @@
|
|||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.ClassUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* <p>Provides utilities for manipulating and examining
|
||||
|
@ -624,20 +624,21 @@ public static void printRootCauseStackTrace(final Throwable throwable) {
|
|||
* that don't have nested causes.</p>
|
||||
*
|
||||
* @param throwable the throwable to output, may be null
|
||||
* @param stream the stream to output to, may not be null
|
||||
* @throws IllegalArgumentException if the stream is {@code null}
|
||||
* @param printStream the stream to output to, may not be null
|
||||
* @throws NullPointerException if the printStream is {@code null}
|
||||
* @since 2.0
|
||||
*/
|
||||
public static void printRootCauseStackTrace(final Throwable throwable, final PrintStream stream) {
|
||||
@SuppressWarnings("resource")
|
||||
public static void printRootCauseStackTrace(final Throwable throwable, final PrintStream printStream) {
|
||||
if (throwable == null) {
|
||||
return;
|
||||
}
|
||||
Validate.notNull(stream, "The PrintStream must not be null");
|
||||
Objects.requireNonNull(printStream, "printStream");
|
||||
final String[] trace = getRootCauseStackTrace(throwable);
|
||||
for (final String element : trace) {
|
||||
stream.println(element);
|
||||
printStream.println(element);
|
||||
}
|
||||
stream.flush();
|
||||
printStream.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -655,20 +656,21 @@ public static void printRootCauseStackTrace(final Throwable throwable, final Pri
|
|||
* that don't have nested causes.</p>
|
||||
*
|
||||
* @param throwable the throwable to output, may be null
|
||||
* @param writer the writer to output to, may not be null
|
||||
* @throws IllegalArgumentException if the writer is {@code null}
|
||||
* @param printWriter the writer to output to, may not be null
|
||||
* @throws NullPointerException if the printWriter is {@code null}
|
||||
* @since 2.0
|
||||
*/
|
||||
public static void printRootCauseStackTrace(final Throwable throwable, final PrintWriter writer) {
|
||||
@SuppressWarnings("resource")
|
||||
public static void printRootCauseStackTrace(final Throwable throwable, final PrintWriter printWriter) {
|
||||
if (throwable == null) {
|
||||
return;
|
||||
}
|
||||
Validate.notNull(writer, "The PrintWriter must not be null");
|
||||
Objects.requireNonNull(printWriter, "printWriter");
|
||||
final String[] trace = getRootCauseStackTrace(throwable);
|
||||
for (final String element : trace) {
|
||||
writer.println(element);
|
||||
printWriter.println(element);
|
||||
}
|
||||
writer.flush();
|
||||
printWriter.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -41,15 +41,14 @@
|
|||
* constructs like:
|
||||
*
|
||||
* <pre>
|
||||
* {@code
|
||||
* Consumer<java.lang.reflect.Method> consumer = (m) -> {
|
||||
* try {
|
||||
* m.invoke(o, args);
|
||||
* } catch (Throwable t) {
|
||||
* throw Failable.rethrow(t);
|
||||
* }
|
||||
* };
|
||||
* }</pre>
|
||||
* Consumer<java.lang.reflect.Method-> consumer = (m) -> {
|
||||
* try {
|
||||
* m.invoke(o, args);
|
||||
* } catch (Throwable t) {
|
||||
* throw Failable.rethrow(t);
|
||||
* }
|
||||
* };
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* By replacing a {@link java.util.function.Consumer Consumer<O>} with a {@link FailableConsumer
|
||||
|
@ -57,9 +56,8 @@
|
|||
* </p>
|
||||
*
|
||||
* <pre>
|
||||
* {@code
|
||||
* Functions.accept((m) -> m.invoke(o,args));
|
||||
* }</pre>
|
||||
* Functions.accept((m) -> m.invoke(o, args));
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* Obviously, the second version is much more concise and the spirit of Lambda expressions is met better than the second
|
||||
|
@ -76,12 +74,12 @@ public class Failable {
|
|||
* @param consumer the consumer to consume
|
||||
* @param object1 the first object to consume by {@code consumer}
|
||||
* @param object2 the second object to consume by {@code consumer}
|
||||
* @param <O1> the type of the first argument the consumer accepts
|
||||
* @param <O2> the type of the second argument the consumer accepts
|
||||
* @param <T> the type of checked exception the consumer may throw
|
||||
* @param <T> the type of the first argument the consumer accepts
|
||||
* @param <U> the type of the second argument the consumer accepts
|
||||
* @param <E> the type of checked exception the consumer may throw
|
||||
*/
|
||||
public static <O1, O2, T extends Throwable> void accept(final FailableBiConsumer<O1, O2, T> consumer,
|
||||
final O1 object1, final O2 object2) {
|
||||
public static <T, U, E extends Throwable> void accept(final FailableBiConsumer<T, U, E> consumer, final T object1,
|
||||
final U object2) {
|
||||
run(() -> consumer.accept(object1, object2));
|
||||
}
|
||||
|
||||
|
@ -90,10 +88,10 @@ public static <O1, O2, T extends Throwable> void accept(final FailableBiConsumer
|
|||
*
|
||||
* @param consumer the consumer to consume
|
||||
* @param object the object to consume by {@code consumer}
|
||||
* @param <O> the type the consumer accepts
|
||||
* @param <T> the type of checked exception the consumer may throw
|
||||
* @param <T> the type the consumer accepts
|
||||
* @param <E> the type of checked exception the consumer may throw
|
||||
*/
|
||||
public static <O, T extends Throwable> void accept(final FailableConsumer<O, T> consumer, final O object) {
|
||||
public static <T, E extends Throwable> void accept(final FailableConsumer<T, E> consumer, final T object) {
|
||||
run(() -> consumer.accept(object));
|
||||
}
|
||||
|
||||
|
@ -102,9 +100,9 @@ public static <O, T extends Throwable> void accept(final FailableConsumer<O, T>
|
|||
*
|
||||
* @param consumer the consumer to consume
|
||||
* @param value the value to consume by {@code consumer}
|
||||
* @param <T> the type of checked exception the consumer may throw
|
||||
* @param <E> the type of checked exception the consumer may throw
|
||||
*/
|
||||
public static <T extends Throwable> void accept(final FailableDoubleConsumer<T> consumer, final double value) {
|
||||
public static <E extends Throwable> void accept(final FailableDoubleConsumer<E> consumer, final double value) {
|
||||
run(() -> consumer.accept(value));
|
||||
}
|
||||
|
||||
|
@ -113,9 +111,9 @@ public static <T extends Throwable> void accept(final FailableDoubleConsumer<T>
|
|||
*
|
||||
* @param consumer the consumer to consume
|
||||
* @param value the value to consume by {@code consumer}
|
||||
* @param <T> the type of checked exception the consumer may throw
|
||||
* @param <E> the type of checked exception the consumer may throw
|
||||
*/
|
||||
public static <T extends Throwable> void accept(final FailableIntConsumer<T> consumer, final int value) {
|
||||
public static <E extends Throwable> void accept(final FailableIntConsumer<E> consumer, final int value) {
|
||||
run(() -> consumer.accept(value));
|
||||
}
|
||||
|
||||
|
@ -124,9 +122,9 @@ public static <T extends Throwable> void accept(final FailableIntConsumer<T> con
|
|||
*
|
||||
* @param consumer the consumer to consume
|
||||
* @param value the value to consume by {@code consumer}
|
||||
* @param <T> the type of checked exception the consumer may throw
|
||||
* @param <E> the type of checked exception the consumer may throw
|
||||
*/
|
||||
public static <T extends Throwable> void accept(final FailableLongConsumer<T> consumer, final long value) {
|
||||
public static <E extends Throwable> void accept(final FailableLongConsumer<E> consumer, final long value) {
|
||||
run(() -> consumer.accept(value));
|
||||
}
|
||||
|
||||
|
@ -136,14 +134,14 @@ public static <T extends Throwable> void accept(final FailableLongConsumer<T> co
|
|||
* @param function the function to apply
|
||||
* @param input1 the first input to apply {@code function} on
|
||||
* @param input2 the second input to apply {@code function} on
|
||||
* @param <O1> the type of the first argument the function accepts
|
||||
* @param <O2> the type of the second argument the function accepts
|
||||
* @param <O> the return type of the function
|
||||
* @param <T> the type of checked exception the function may throw
|
||||
* @param <T> the type of the first argument the function accepts
|
||||
* @param <U> the type of the second argument the function accepts
|
||||
* @param <R> the return type of the function
|
||||
* @param <E> the type of checked exception the function may throw
|
||||
* @return the value returned from the function
|
||||
*/
|
||||
public static <O1, O2, O, T extends Throwable> O apply(final FailableBiFunction<O1, O2, O, T> function,
|
||||
final O1 input1, final O2 input2) {
|
||||
public static <T, U, R, E extends Throwable> R apply(final FailableBiFunction<T, U, R, E> function, final T input1,
|
||||
final U input2) {
|
||||
return get(() -> function.apply(input1, input2));
|
||||
}
|
||||
|
||||
|
@ -152,12 +150,12 @@ public static <O1, O2, O, T extends Throwable> O apply(final FailableBiFunction<
|
|||
*
|
||||
* @param function the function to apply
|
||||
* @param input the input to apply {@code function} on
|
||||
* @param <I> the type of the argument the function accepts
|
||||
* @param <O> the return type of the function
|
||||
* @param <T> the type of checked exception the function may throw
|
||||
* @param <T> the type of the argument the function accepts
|
||||
* @param <R> the return type of the function
|
||||
* @param <E> 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(final FailableFunction<I, O, T> function, final I input) {
|
||||
public static <T, R, E extends Throwable> R apply(final FailableFunction<T, R, E> function, final T input) {
|
||||
return get(() -> function.apply(input));
|
||||
}
|
||||
|
||||
|
@ -167,10 +165,10 @@ public static <I, O, T extends Throwable> O apply(final FailableFunction<I, O, T
|
|||
* @param function the function to apply
|
||||
* @param left the first input to apply {@code function} on
|
||||
* @param right the second input to apply {@code function} on
|
||||
* @param <T> the type of checked exception the function may throw
|
||||
* @param <E> the type of checked exception the function may throw
|
||||
* @return the value returned from the function
|
||||
*/
|
||||
public static <T extends Throwable> double applyAsDouble(final FailableDoubleBinaryOperator<T> function,
|
||||
public static <E extends Throwable> double applyAsDouble(final FailableDoubleBinaryOperator<E> function,
|
||||
final double left, final double right) {
|
||||
return getAsDouble(() -> function.applyAsDouble(left, right));
|
||||
}
|
||||
|
@ -178,82 +176,82 @@ public static <T extends Throwable> double applyAsDouble(final FailableDoubleBin
|
|||
/**
|
||||
* Converts the given {@link FailableBiConsumer} into a standard {@link BiConsumer}.
|
||||
*
|
||||
* @param <O1> the type of the first argument of the consumers
|
||||
* @param <O2> the type of the second argument of the consumers
|
||||
* @param <T> the type of the first argument of the consumers
|
||||
* @param <U> the type of the second argument of the consumers
|
||||
* @param consumer a failable {@code BiConsumer}
|
||||
* @return a standard {@code BiConsumer}
|
||||
*/
|
||||
public static <O1, O2> BiConsumer<O1, O2> asBiConsumer(final FailableBiConsumer<O1, O2, ?> consumer) {
|
||||
public static <T, U> BiConsumer<T, U> asBiConsumer(final FailableBiConsumer<T, U, ?> consumer) {
|
||||
return (input1, input2) -> accept(consumer, input1, input2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given {@link FailableBiFunction} into a standard {@link BiFunction}.
|
||||
*
|
||||
* @param <O1> the type of the first argument of the input of the functions
|
||||
* @param <O2> the type of the second argument of the input of the functions
|
||||
* @param <O> the type of the output of the functions
|
||||
* @param <T> the type of the first argument of the input of the functions
|
||||
* @param <U> the type of the second argument of the input of the functions
|
||||
* @param <R> the type of the output of the functions
|
||||
* @param function a {@code FailableBiFunction}
|
||||
* @return a standard {@code BiFunction}
|
||||
*/
|
||||
public static <O1, O2, O> BiFunction<O1, O2, O> asBiFunction(final FailableBiFunction<O1, O2, O, ?> function) {
|
||||
public static <T, U, R> BiFunction<T, U, R> asBiFunction(final FailableBiFunction<T, U, R, ?> function) {
|
||||
return (input1, input2) -> apply(function, input1, input2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given {@link FailableBiPredicate} into a standard {@link BiPredicate}.
|
||||
*
|
||||
* @param <O1> the type of the first argument used by the predicates
|
||||
* @param <O2> the type of the second argument used by the predicates
|
||||
* @param <T> the type of the first argument used by the predicates
|
||||
* @param <U> the type of the second argument used by the predicates
|
||||
* @param predicate a {@code FailableBiPredicate}
|
||||
* @return a standard {@code BiPredicate}
|
||||
*/
|
||||
public static <O1, O2> BiPredicate<O1, O2> asBiPredicate(final FailableBiPredicate<O1, O2, ?> predicate) {
|
||||
public static <T, U> BiPredicate<T, U> asBiPredicate(final FailableBiPredicate<T, U, ?> predicate) {
|
||||
return (input1, input2) -> test(predicate, input1, input2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given {@link FailableCallable} into a standard {@link Callable}.
|
||||
*
|
||||
* @param <O> the type used by the callables
|
||||
* @param <V> the type used by the callables
|
||||
* @param callable a {@code FailableCallable}
|
||||
* @return a standard {@code Callable}
|
||||
*/
|
||||
public static <O> Callable<O> asCallable(final FailableCallable<O, ?> callable) {
|
||||
public static <V> Callable<V> asCallable(final FailableCallable<V, ?> callable) {
|
||||
return () -> call(callable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given {@link FailableConsumer} into a standard {@link Consumer}.
|
||||
*
|
||||
* @param <I> the type used by the consumers
|
||||
* @param <T> the type used by the consumers
|
||||
* @param consumer a {@code FailableConsumer}
|
||||
* @return a standard {@code Consumer}
|
||||
*/
|
||||
public static <I> Consumer<I> asConsumer(final FailableConsumer<I, ?> consumer) {
|
||||
public static <T> Consumer<T> asConsumer(final FailableConsumer<T, ?> consumer) {
|
||||
return input -> accept(consumer, input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given {@link FailableFunction} into a standard {@link Function}.
|
||||
*
|
||||
* @param <I> the type of the input of the functions
|
||||
* @param <O> the type of the output of the functions
|
||||
* @param <T> the type of the input of the functions
|
||||
* @param <R> the type of the output of the functions
|
||||
* @param function a {code FailableFunction}
|
||||
* @return a standard {@code Function}
|
||||
*/
|
||||
public static <I, O> Function<I, O> asFunction(final FailableFunction<I, O, ?> function) {
|
||||
public static <T, R> Function<T, R> asFunction(final FailableFunction<T, R, ?> function) {
|
||||
return input -> apply(function, input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given {@link FailablePredicate} into a standard {@link Predicate}.
|
||||
*
|
||||
* @param <I> the type used by the predicates
|
||||
* @param <T> the type used by the predicates
|
||||
* @param predicate a {@code FailablePredicate}
|
||||
* @return a standard {@code Predicate}
|
||||
*/
|
||||
public static <I> Predicate<I> asPredicate(final FailablePredicate<I, ?> predicate) {
|
||||
public static <T> Predicate<T> asPredicate(final FailablePredicate<T, ?> predicate) {
|
||||
return input -> test(predicate, input);
|
||||
}
|
||||
|
||||
|
@ -270,11 +268,11 @@ public static Runnable asRunnable(final FailableRunnable<?> runnable) {
|
|||
/**
|
||||
* Converts the given {@link FailableSupplier} into a standard {@link Supplier}.
|
||||
*
|
||||
* @param <O> the type supplied by the suppliers
|
||||
* @param <T> the type supplied by the suppliers
|
||||
* @param supplier a {@code FailableSupplier}
|
||||
* @return a standard {@code Supplier}
|
||||
*/
|
||||
public static <O> Supplier<O> asSupplier(final FailableSupplier<O, ?> supplier) {
|
||||
public static <T> Supplier<T> asSupplier(final FailableSupplier<T, ?> supplier) {
|
||||
return () -> get(supplier);
|
||||
}
|
||||
|
||||
|
@ -282,11 +280,11 @@ public static <O> Supplier<O> asSupplier(final FailableSupplier<O, ?> supplier)
|
|||
* Calls a callable and rethrows any exception as a {@link RuntimeException}.
|
||||
*
|
||||
* @param callable the callable to call
|
||||
* @param <O> the return type of the callable
|
||||
* @param <T> the type of checked exception the callable may throw
|
||||
* @param <V> the return type of the callable
|
||||
* @param <E> the type of checked exception the callable may throw
|
||||
* @return the value returned from the callable
|
||||
*/
|
||||
public static <O, T extends Throwable> O call(final FailableCallable<O, T> callable) {
|
||||
public static <V, E extends Throwable> V call(final FailableCallable<V, E> callable) {
|
||||
return get(callable::call);
|
||||
}
|
||||
|
||||
|
@ -294,11 +292,11 @@ public static <O, T extends Throwable> O call(final FailableCallable<O, T> calla
|
|||
* Invokes a supplier, and returns the result.
|
||||
*
|
||||
* @param supplier The supplier to invoke.
|
||||
* @param <O> The suppliers output type.
|
||||
* @param <T> The type of checked exception, which the supplier can throw.
|
||||
* @param <T> The suppliers output type.
|
||||
* @param <E> 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(final FailableSupplier<O, T> supplier) {
|
||||
public static <T, E extends Throwable> T get(final FailableSupplier<T, E> supplier) {
|
||||
try {
|
||||
return supplier.get();
|
||||
} catch (final Throwable t) {
|
||||
|
@ -310,10 +308,10 @@ public static <O, T extends Throwable> O get(final FailableSupplier<O, T> suppli
|
|||
* Invokes a boolean supplier, and returns the result.
|
||||
*
|
||||
* @param supplier The boolean supplier to invoke.
|
||||
* @param <T> The type of checked exception, which the supplier can throw.
|
||||
* @param <E> The type of checked exception, which the supplier can throw.
|
||||
* @return The boolean, which has been created by the supplier
|
||||
*/
|
||||
public static <T extends Throwable> boolean getAsBoolean(final FailableBooleanSupplier<T> supplier) {
|
||||
public static <E extends Throwable> boolean getAsBoolean(final FailableBooleanSupplier<E> supplier) {
|
||||
try {
|
||||
return supplier.getAsBoolean();
|
||||
} catch (final Throwable t) {
|
||||
|
@ -325,10 +323,10 @@ public static <T extends Throwable> boolean getAsBoolean(final FailableBooleanSu
|
|||
* Invokes a double supplier, and returns the result.
|
||||
*
|
||||
* @param supplier The double supplier to invoke.
|
||||
* @param <T> The type of checked exception, which the supplier can throw.
|
||||
* @param <E> The type of checked exception, which the supplier can throw.
|
||||
* @return The boolean, which has been created by the supplier
|
||||
*/
|
||||
public static <T extends Throwable> double getAsDouble(final FailableDoubleSupplier<T> supplier) {
|
||||
public static <E extends Throwable> double getAsDouble(final FailableDoubleSupplier<E> supplier) {
|
||||
try {
|
||||
return supplier.getAsDouble();
|
||||
} catch (final Throwable t) {
|
||||
|
@ -340,10 +338,10 @@ public static <T extends Throwable> double getAsDouble(final FailableDoubleSuppl
|
|||
* Invokes an int supplier, and returns the result.
|
||||
*
|
||||
* @param supplier The int supplier to invoke.
|
||||
* @param <T> The type of checked exception, which the supplier can throw.
|
||||
* @param <E> The type of checked exception, which the supplier can throw.
|
||||
* @return The boolean, which has been created by the supplier
|
||||
*/
|
||||
public static <T extends Throwable> int getAsInt(final FailableIntSupplier<T> supplier) {
|
||||
public static <E extends Throwable> int getAsInt(final FailableIntSupplier<E> supplier) {
|
||||
try {
|
||||
return supplier.getAsInt();
|
||||
} catch (final Throwable t) {
|
||||
|
@ -355,10 +353,10 @@ public static <T extends Throwable> int getAsInt(final FailableIntSupplier<T> su
|
|||
* Invokes a long supplier, and returns the result.
|
||||
*
|
||||
* @param supplier The long supplier to invoke.
|
||||
* @param <T> The type of checked exception, which the supplier can throw.
|
||||
* @param <E> The type of checked exception, which the supplier can throw.
|
||||
* @return The boolean, which has been created by the supplier
|
||||
*/
|
||||
public static <T extends Throwable> long getAsLong(final FailableLongSupplier<T> supplier) {
|
||||
public static <E extends Throwable> long getAsLong(final FailableLongSupplier<E> supplier) {
|
||||
try {
|
||||
return supplier.getAsLong();
|
||||
} catch (final Throwable t) {
|
||||
|
@ -410,9 +408,9 @@ public static RuntimeException rethrow(final Throwable throwable) {
|
|||
* Runs a runnable and rethrows any exception as a {@link RuntimeException}.
|
||||
*
|
||||
* @param runnable The runnable to run
|
||||
* @param <T> the type of checked exception the runnable may throw
|
||||
* @param <E> the type of checked exception the runnable may throw
|
||||
*/
|
||||
public static <T extends Throwable> void run(final FailableRunnable<T> runnable) {
|
||||
public static <E extends Throwable> void run(final FailableRunnable<E> runnable) {
|
||||
try {
|
||||
runnable.run();
|
||||
} catch (final Throwable t) {
|
||||
|
@ -429,10 +427,10 @@ public static <T extends Throwable> void run(final FailableRunnable<T> runnable)
|
|||
* </pre>
|
||||
*
|
||||
* @param collection The collection, which is being converted into a {@link FailableStream}.
|
||||
* @param <O> The collections element type. (In turn, the result streams element type.)
|
||||
* @param <E> The collections element type. (In turn, the result streams element type.)
|
||||
* @return The created {@link FailableStream}.
|
||||
*/
|
||||
public static <O> FailableStream<O> stream(final Collection<O> collection) {
|
||||
public static <E> FailableStream<E> stream(final Collection<E> collection) {
|
||||
return new FailableStream<>(collection.stream());
|
||||
}
|
||||
|
||||
|
@ -443,10 +441,10 @@ public static <O> FailableStream<O> stream(final Collection<O> collection) {
|
|||
* {@link Function}, {@link Consumer}, etc.
|
||||
*
|
||||
* @param stream The stream, which is being converted into a {@link FailableStream}.
|
||||
* @param <O> The streams element type.
|
||||
* @param <T> The streams element type.
|
||||
* @return The created {@link FailableStream}.
|
||||
*/
|
||||
public static <O> FailableStream<O> stream(final Stream<O> stream) {
|
||||
public static <T> FailableStream<T> stream(final Stream<T> stream) {
|
||||
return new FailableStream<>(stream);
|
||||
}
|
||||
|
||||
|
@ -456,14 +454,14 @@ public static <O> FailableStream<O> stream(final Stream<O> stream) {
|
|||
* @param predicate the predicate to test
|
||||
* @param object1 the first input to test by {@code predicate}
|
||||
* @param object2 the second input to test by {@code predicate}
|
||||
* @param <O1> the type of the first argument the predicate tests
|
||||
* @param <O2> the type of the second argument the predicate tests
|
||||
* @param <T> the type of checked exception the predicate may throw
|
||||
* @param <T> the type of the first argument the predicate tests
|
||||
* @param <U> the type of the second argument the predicate tests
|
||||
* @param <E> 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(final FailableBiPredicate<O1, O2, T> predicate,
|
||||
final O1 object1, final O2 object2) {
|
||||
return get(() -> predicate.test(object1, object2));
|
||||
public static <T, U, E extends Throwable> boolean test(final FailableBiPredicate<T, U, E> predicate,
|
||||
final T object1, final U object2) {
|
||||
return getAsBoolean(() -> predicate.test(object1, object2));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -471,12 +469,12 @@ public static <O1, O2, T extends Throwable> boolean test(final FailableBiPredica
|
|||
*
|
||||
* @param predicate the predicate to test
|
||||
* @param object the input to test by {@code predicate}
|
||||
* @param <O> the type of argument the predicate tests
|
||||
* @param <T> the type of checked exception the predicate may throw
|
||||
* @param <T> the type of argument the predicate tests
|
||||
* @param <E> 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(final FailablePredicate<O, T> predicate, final O object) {
|
||||
return get(() -> predicate.test(object));
|
||||
public static <T, E extends Throwable> boolean test(final FailablePredicate<T, E> predicate, final T object) {
|
||||
return getAsBoolean(() -> predicate.test(object));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -487,10 +485,8 @@ public static <O, T extends Throwable> boolean test(final FailablePredicate<O, T
|
|||
* {@link Throwable} is rethrown. Example use:
|
||||
*
|
||||
* <pre>
|
||||
* {@code
|
||||
* final FileInputStream fis = new FileInputStream("my.file");
|
||||
* Functions.tryWithResources(useInputStream(fis), null, () -> fis.close());
|
||||
* }
|
||||
* final FileInputStream fis = new FileInputStream("my.file");
|
||||
* Functions.tryWithResources(useInputStream(fis), null, () -> fis.close());
|
||||
* </pre>
|
||||
*
|
||||
* @param action The action to execute. This object <em>will</em> always be invoked.
|
||||
|
@ -549,10 +545,8 @@ public static void tryWithResources(final FailableRunnable<? extends Throwable>
|
|||
* {@link Throwable} is rethrown. Example use:
|
||||
*
|
||||
* <pre>
|
||||
* {@code
|
||||
* final FileInputStream fis = new FileInputStream("my.file");
|
||||
* Functions.tryWithResources(useInputStream(fis), () -> fis.close());
|
||||
* }
|
||||
* final FileInputStream fis = new FileInputStream("my.file");
|
||||
* Functions.tryWithResources(useInputStream(fis), () -> fis.close());
|
||||
* </pre>
|
||||
*
|
||||
* @param action The action to execute. This object <em>will</em> always be invoked.
|
||||
|
|
|
@ -17,25 +17,57 @@
|
|||
|
||||
package org.apache.commons.lang3.function;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* A functional interface like {@link BiConsumer} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <O1> Consumed type 1.
|
||||
* @param <O2> Consumed type 2.
|
||||
* @param <T> Thrown exception.
|
||||
* @param <T> Consumed type 1.
|
||||
* @param <U> Consumed type 2.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableBiConsumer<O1, O2, T extends Throwable> {
|
||||
public interface FailableBiConsumer<T, U, E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableBiConsumer NOP = (t, u) -> {/* NOP */};
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <T> Consumed type 1.
|
||||
* @param <U> Consumed type 2.
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <T, U, E extends Throwable> FailableBiConsumer<T, U, E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts the consumer.
|
||||
*
|
||||
* @param object1 the first parameter for the consumable to accept
|
||||
* @param object2 the second parameter for the consumable to accept
|
||||
* @throws T Thrown when the consumer fails.
|
||||
* @param t the first parameter for the consumable to accept
|
||||
* @param u the second parameter for the consumable to accept
|
||||
* @throws E Thrown when the consumer fails.
|
||||
*/
|
||||
void accept(O1 object1, O2 object2) throws T;
|
||||
void accept(T t, U u) throws E;
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableBiConsumer} like {@link BiConsumer#andThen(BiConsumer)}.
|
||||
*
|
||||
* @param after the operation to perform after this one.
|
||||
* @return a composed {@code FailableBiConsumer} like {@link BiConsumer#andThen(BiConsumer)}.
|
||||
* @throws NullPointerException when {@code after} is null.
|
||||
*/
|
||||
default FailableBiConsumer<T, U, E> andThen(final FailableBiConsumer<? super T, ? super U, E> after) {
|
||||
Objects.requireNonNull(after);
|
||||
return (t, u) -> {
|
||||
accept(t, u);
|
||||
after.accept(t, u);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,19 +17,51 @@
|
|||
|
||||
package org.apache.commons.lang3.function;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* A functional interface like {@link BiFunction} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <O1> Input type 1.
|
||||
* @param <O2> Input type 2.
|
||||
* @param <T> Input type 1.
|
||||
* @param <U> Input type 2.
|
||||
* @param <R> Return type.
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableBiFunction<O1, O2, R, T extends Throwable> {
|
||||
public interface FailableBiFunction<T, U, R, E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableBiFunction NOP = (t, u) -> null;
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <T> Consumed type 1.
|
||||
* @param <U> Consumed type 2.
|
||||
* @param <R> Return type.
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <T, U, R, E extends Throwable> FailableBiFunction<T, U, R, E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableBiFunction} that like {@link BiFunction#andThen(Function)}.
|
||||
*
|
||||
* @param <V> the output type of the {@code after} function, and of the composed function.
|
||||
* @param after the operation to perform after this one.
|
||||
* @return a composed {@code FailableBiFunction} that like {@link BiFunction#andThen(Function)}.
|
||||
* @throws NullPointerException when {@code after} is null.
|
||||
*/
|
||||
default <V> FailableBiFunction<T, U, V, E> andThen(final FailableFunction<? super R, ? extends V, E> after) {
|
||||
Objects.requireNonNull(after);
|
||||
return (final T t, final U u) -> after.apply(apply(t, u));
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function.
|
||||
|
@ -37,7 +69,7 @@ public interface FailableBiFunction<O1, O2, R, T extends Throwable> {
|
|||
* @param input1 the first input for the function
|
||||
* @param input2 the second input for the function
|
||||
* @return the result of the function
|
||||
* @throws T Thrown when the function fails.
|
||||
* @throws E Thrown when the function fails.
|
||||
*/
|
||||
R apply(O1 input1, O2 input2) throws T;
|
||||
R apply(T input1, U input2) throws E;
|
||||
}
|
||||
|
|
|
@ -17,18 +17,84 @@
|
|||
|
||||
package org.apache.commons.lang3.function;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* A functional interface like {@link BiPredicate} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <O1> Predicate type 1.
|
||||
* @param <O2> Predicate type 2.
|
||||
* @param <T> Thrown exception.
|
||||
* @param <T> Predicate type 1.
|
||||
* @param <U> Predicate type 2.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableBiPredicate<O1, O2, T extends Throwable> {
|
||||
public interface FailableBiPredicate<T, U, E extends Throwable> {
|
||||
|
||||
/** FALSE singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableBiPredicate FALSE = (t, u) -> false;
|
||||
|
||||
/** TRUE singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableBiPredicate TRUE = (t, u) -> true;
|
||||
|
||||
/**
|
||||
* Returns The FALSE singleton.
|
||||
*
|
||||
* @param <T> Consumed type 1.
|
||||
* @param <U> Consumed type 2.
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <T, U, E extends Throwable> FailableBiPredicate<T, U, E> falsePredicate() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns The FALSE TRUE.
|
||||
*
|
||||
* @param <T> Consumed type 1.
|
||||
* @param <U> Consumed type 2.
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <T, U, E extends Throwable> FailableBiPredicate<T, U, E> truePredicate() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableBiPredicate} like {@link BiPredicate#and(BiPredicate)}.
|
||||
*
|
||||
* @param other a predicate that will be logically-ANDed with this predicate.
|
||||
* @return a composed {@code FailableBiPredicate} like {@link BiPredicate#and(BiPredicate)}.
|
||||
* @throws NullPointerException if other is null
|
||||
*/
|
||||
default FailableBiPredicate<T, U, E> and(final FailableBiPredicate<? super T, ? super U, E> other) {
|
||||
Objects.requireNonNull(other);
|
||||
return (final T t, final U u) -> test(t, u) && other.test(t, u);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a predicate that negates this predicate.
|
||||
*
|
||||
* @return a predicate that negates this predicate.
|
||||
*/
|
||||
default FailableBiPredicate<T, U, E> negate() {
|
||||
return (final T t, final U u) -> !test(t, u);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableBiPredicate} like {@link BiPredicate#and(BiPredicate)}.
|
||||
*
|
||||
* @param other a predicate that will be logically-ORed with this predicate.
|
||||
* @return a composed {@code FailableBiPredicate} like {@link BiPredicate#and(BiPredicate)}.
|
||||
* @throws NullPointerException if other is null
|
||||
*/
|
||||
default FailableBiPredicate<T, U, E> or(final FailableBiPredicate<? super T, ? super U, E> other) {
|
||||
Objects.requireNonNull(other);
|
||||
return (final T t, final U u) -> test(t, u) || other.test(t, u);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the predicate.
|
||||
|
@ -36,7 +102,7 @@ public interface FailableBiPredicate<O1, O2, T extends Throwable> {
|
|||
* @param object1 the first object to test the predicate on
|
||||
* @param object2 the second object to test the predicate on
|
||||
* @return the predicate's evaluation
|
||||
* @throws T if the predicate fails
|
||||
* @throws E Thrown when this predicate fails.
|
||||
*/
|
||||
boolean test(O1 object1, O2 object2) throws T;
|
||||
boolean test(T object1, U object2) throws E;
|
||||
}
|
||||
|
|
|
@ -22,17 +22,17 @@
|
|||
/**
|
||||
* A functional interface like {@link BooleanSupplier} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableBooleanSupplier<T extends Throwable> {
|
||||
public interface FailableBooleanSupplier<E extends Throwable> {
|
||||
|
||||
/**
|
||||
* Supplies a boolean.
|
||||
*
|
||||
* @return a result
|
||||
* @throws T if the supplier fails
|
||||
* @throws E if the supplier fails
|
||||
*/
|
||||
boolean getAsBoolean() throws T;
|
||||
boolean getAsBoolean() throws E;
|
||||
}
|
||||
|
|
|
@ -21,17 +21,17 @@
|
|||
* A functional interface like {@link java.util.concurrent.Callable} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <R> Return type.
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableCallable<R, T extends Throwable> {
|
||||
public interface FailableCallable<R, E extends Throwable> {
|
||||
|
||||
/**
|
||||
* Calls the callable.
|
||||
*
|
||||
* @return The value returned from the callable
|
||||
* @throws T if the callable fails
|
||||
* @throws E if the callable fails
|
||||
*/
|
||||
R call() throws T;
|
||||
R call() throws E;
|
||||
}
|
||||
|
|
|
@ -17,23 +17,54 @@
|
|||
|
||||
package org.apache.commons.lang3.function;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* A functional interface like {@link Consumer} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <O> Consumed type 1.
|
||||
* @param <T> Thrown exception.
|
||||
* @param <T> Consumed type 1.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableConsumer<O, T extends Throwable> {
|
||||
public interface FailableConsumer<T, E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableConsumer NOP = t -> {/* NOP */};
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <T> Consumed type 1.
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <T, E extends Throwable> FailableConsumer<T, E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts the consumer.
|
||||
*
|
||||
* @param object the parameter for the consumable to accept
|
||||
* @throws T Thrown when the consumer fails.
|
||||
* @throws E Thrown when the consumer fails.
|
||||
*/
|
||||
void accept(O object) throws T;
|
||||
void accept(T object) throws E;
|
||||
|
||||
/**
|
||||
* Returns a composed {@code Consumer} like {@link Consumer#andThen(Consumer)}.
|
||||
*
|
||||
* @param after the operation to perform after this operation
|
||||
* @return a composed {@code Consumer} like {@link Consumer#andThen(Consumer)}.
|
||||
* @throws NullPointerException when {@code after} is null
|
||||
*/
|
||||
default FailableConsumer<T, E> andThen(final FailableConsumer<? super T, E> after) {
|
||||
Objects.requireNonNull(after);
|
||||
return (final T t) -> {
|
||||
accept(t);
|
||||
after.accept(t);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,11 +22,11 @@
|
|||
/**
|
||||
* A functional interface like {@link DoubleBinaryOperator} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableDoubleBinaryOperator<T extends Throwable> {
|
||||
public interface FailableDoubleBinaryOperator<E extends Throwable> {
|
||||
|
||||
/**
|
||||
* Applies this operator to the given operands.
|
||||
|
@ -34,7 +34,7 @@ public interface FailableDoubleBinaryOperator<T extends Throwable> {
|
|||
* @param left the first operand
|
||||
* @param right the second operand
|
||||
* @return the operator result
|
||||
* @throws T if the operation fails
|
||||
* @throws E if the operation fails
|
||||
*/
|
||||
double applyAsDouble(double left, double right) throws T;
|
||||
double applyAsDouble(double left, double right) throws E;
|
||||
}
|
||||
|
|
|
@ -17,22 +17,52 @@
|
|||
|
||||
package org.apache.commons.lang3.function;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.DoubleConsumer;
|
||||
|
||||
/**
|
||||
* A functional interface like {@link DoubleConsumer} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableDoubleConsumer<T extends Throwable> {
|
||||
public interface FailableDoubleConsumer<E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableDoubleConsumer NOP = t -> {/* NOP */};
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableDoubleConsumer<E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts the consumer.
|
||||
*
|
||||
* @param value the parameter for the consumable to accept
|
||||
* @throws T Thrown when the consumer fails.
|
||||
* @throws E Thrown when the consumer fails.
|
||||
*/
|
||||
void accept(double value) throws T;
|
||||
void accept(double value) throws E;
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableDoubleConsumer} like {@link DoubleConsumer#andThen(DoubleConsumer)}.
|
||||
*
|
||||
* @param after the operation to perform after this one.
|
||||
* @return a composed {@code FailableDoubleConsumer} like {@link DoubleConsumer#andThen(DoubleConsumer)}.
|
||||
* @throws NullPointerException when {@code after} is null.
|
||||
*/
|
||||
default FailableDoubleConsumer<E> andThen(final FailableDoubleConsumer<E> after) {
|
||||
Objects.requireNonNull(after);
|
||||
return (final double t) -> {
|
||||
accept(t);
|
||||
after.accept(t);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,18 +23,33 @@
|
|||
* A functional interface like {@link DoubleFunction} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <R> Return type.
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableDoubleFunction<R, T extends Throwable> {
|
||||
public interface FailableDoubleFunction<R, E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableDoubleFunction NOP = t -> null;
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <R> Return type.
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <R, E extends Throwable> FailableDoubleFunction<R, E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function.
|
||||
*
|
||||
* @param input the input for the function
|
||||
* @return the result of the function
|
||||
* @throws T Thrown when the function fails.
|
||||
* @throws E Thrown when the function fails.
|
||||
*/
|
||||
R apply(double input) throws T;
|
||||
R apply(double input) throws E;
|
||||
}
|
||||
|
|
|
@ -17,23 +17,85 @@
|
|||
|
||||
package org.apache.commons.lang3.function;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.DoublePredicate;
|
||||
|
||||
/**
|
||||
* A functional interface like {@link DoublePredicate} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableDoublePredicate<T extends Throwable> {
|
||||
public interface FailableDoublePredicate<E extends Throwable> {
|
||||
|
||||
/** FALSE singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableDoublePredicate FALSE = t -> false;
|
||||
|
||||
/** TRUE singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableDoublePredicate TRUE = t -> true;
|
||||
|
||||
/**
|
||||
* Returns The FALSE singleton.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableDoublePredicate<E> falsePredicate() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns The FALSE TRUE.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableDoublePredicate<E> truePredicate() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableDoublePredicate} like {@link DoublePredicate#and(DoublePredicate)}.
|
||||
*
|
||||
* @param other a predicate that will be logically-ANDed with this predicate.
|
||||
* @return a composed {@code FailableDoublePredicate} like {@link DoublePredicate#and(DoublePredicate)}.
|
||||
* @throws NullPointerException if other is null
|
||||
*/
|
||||
default FailableDoublePredicate<E> and(final FailableDoublePredicate<E> other) {
|
||||
Objects.requireNonNull(other);
|
||||
return t -> test(t) && other.test(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a predicate that negates this predicate.
|
||||
*
|
||||
* @return a predicate that negates this predicate.
|
||||
*/
|
||||
default FailableDoublePredicate<E> negate() {
|
||||
return t -> !test(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableDoublePredicate} like {@link DoublePredicate#and(DoublePredicate)}.
|
||||
*
|
||||
* @param other a predicate that will be logically-ORed with this predicate.
|
||||
* @return a composed {@code FailableDoublePredicate} like {@link DoublePredicate#and(DoublePredicate)}.
|
||||
* @throws NullPointerException if other is null
|
||||
*/
|
||||
default FailableDoublePredicate<E> or(final FailableDoublePredicate<E> other) {
|
||||
Objects.requireNonNull(other);
|
||||
return t -> test(t) || other.test(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the predicate.
|
||||
*
|
||||
* @param value the parameter for the predicate to accept.
|
||||
* @return {@code true} if the input argument matches the predicate, {@code false} otherwise.
|
||||
* @throws T Thrown when the consumer fails.
|
||||
* @throws E Thrown when the consumer fails.
|
||||
*/
|
||||
boolean test(double value) throws T;
|
||||
boolean test(double value) throws E;
|
||||
}
|
||||
|
|
|
@ -22,17 +22,17 @@
|
|||
/**
|
||||
* A functional interface like {@link DoubleSupplier} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableDoubleSupplier<T extends Throwable> {
|
||||
public interface FailableDoubleSupplier<E extends Throwable> {
|
||||
|
||||
/**
|
||||
* Supplies a double.
|
||||
*
|
||||
* @return a result
|
||||
* @throws T if the supplier fails
|
||||
* @throws E if the supplier fails
|
||||
*/
|
||||
double getAsDouble() throws T;
|
||||
double getAsDouble() throws E;
|
||||
}
|
||||
|
|
|
@ -22,18 +22,32 @@
|
|||
/**
|
||||
* A functional interface like {@link DoubleToIntFunction} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableDoubleToIntFunction<T extends Throwable> {
|
||||
public interface FailableDoubleToIntFunction<E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableDoubleToIntFunction NOP = t -> 0;
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableDoubleToIntFunction<E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function to the given argument.
|
||||
*
|
||||
* @param value the function argument
|
||||
* @return the function result
|
||||
* @throws T Thrown when the function fails.
|
||||
* @throws E Thrown when the function fails.
|
||||
*/
|
||||
int applyAsInt(double value) throws T;
|
||||
int applyAsInt(double value) throws E;
|
||||
}
|
||||
|
|
|
@ -22,18 +22,32 @@
|
|||
/**
|
||||
* A functional interface like {@link DoubleToLongFunction} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableDoubleToLongFunction<T extends Throwable> {
|
||||
public interface FailableDoubleToLongFunction<E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableDoubleToLongFunction NOP = t -> 0;
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableDoubleToLongFunction<E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function to the given argument.
|
||||
*
|
||||
* @param value the function argument
|
||||
* @return the function result
|
||||
* @throws T if the operation fails
|
||||
* @throws E if the operation fails
|
||||
*/
|
||||
int applyAsLong(double value) throws T;
|
||||
int applyAsLong(double value) throws E;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.commons.lang3.function;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.DoubleUnaryOperator;
|
||||
|
||||
/**
|
||||
* A functional interface like {@link DoubleUnaryOperator} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
public interface FailableDoubleUnaryOperator<E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableDoubleUnaryOperator NOP = t -> 0d;
|
||||
|
||||
/**
|
||||
* Returns a unary operator that always returns its input argument.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return a unary operator that always returns its input argument
|
||||
*/
|
||||
static <E extends Throwable> FailableDoubleUnaryOperator<E> identity() {
|
||||
return t -> t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableDoubleUnaryOperator<E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableDoubleUnaryOperator} like
|
||||
* {@link DoubleUnaryOperator#andThen(DoubleUnaryOperator)}.
|
||||
*
|
||||
* @param after the operator to apply after this one.
|
||||
* @return a composed {@code FailableDoubleUnaryOperator} like
|
||||
* {@link DoubleUnaryOperator#andThen(DoubleUnaryOperator)}.
|
||||
* @throws NullPointerException if after is null.
|
||||
* @see #compose(FailableDoubleUnaryOperator)
|
||||
*/
|
||||
default FailableDoubleUnaryOperator<E> andThen(final FailableDoubleUnaryOperator<E> after) {
|
||||
Objects.requireNonNull(after);
|
||||
return (final double t) -> after.applyAsDouble(applyAsDouble(t));
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this operator to the given operand.
|
||||
*
|
||||
* @param operand the operand
|
||||
* @return the operator result
|
||||
* @throws E Thrown when a consumer fails.
|
||||
*/
|
||||
double applyAsDouble(double operand) throws E;
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableDoubleUnaryOperator} like
|
||||
* {@link DoubleUnaryOperator#compose(DoubleUnaryOperator)}.
|
||||
*
|
||||
* @param before the operator to apply before this one.
|
||||
* @return a composed {@code FailableDoubleUnaryOperator} like
|
||||
* {@link DoubleUnaryOperator#compose(DoubleUnaryOperator)}.
|
||||
* @throws NullPointerException if before is null.
|
||||
* @see #andThen(FailableDoubleUnaryOperator)
|
||||
*/
|
||||
default FailableDoubleUnaryOperator<E> compose(final FailableDoubleUnaryOperator<E> before) {
|
||||
Objects.requireNonNull(before);
|
||||
return (final double v) -> applyAsDouble(before.applyAsDouble(v));
|
||||
}
|
||||
}
|
|
@ -17,25 +17,80 @@
|
|||
|
||||
package org.apache.commons.lang3.function;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* A functional interface like {@link Function} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <I> Input type 1.
|
||||
* @param <T> Input type 1.
|
||||
* @param <R> Return type.
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableFunction<I, R, T extends Throwable> {
|
||||
public interface FailableFunction<T, R, E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableFunction NOP = t -> null;
|
||||
|
||||
/**
|
||||
* Returns a function that always returns its input argument.
|
||||
*
|
||||
* @param <T> the type of the input and output objects to the function
|
||||
* @param <E> Thrown exception.
|
||||
* @return a function that always returns its input argument
|
||||
*/
|
||||
static <T, E extends Throwable> FailableFunction<T, T, E> identity() {
|
||||
return t -> t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <T> Consumed type 1.
|
||||
* @param <R> Return type.
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <T, R, E extends Throwable> FailableFunction<T, R, E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableFunction} like {@link Function#andThen(Function)}.
|
||||
*
|
||||
* @param <V> the output type of the {@code after} function, and of the composed function.
|
||||
* @return a composed {@code FailableFunction} like {@link Function#andThen(Function)}.
|
||||
* @param after the operation to perform after this one.
|
||||
* @throws NullPointerException when {@code after} is null.
|
||||
*/
|
||||
default <V> FailableFunction<T, V, E> andThen(final FailableFunction<? super R, ? extends V, E> after) {
|
||||
Objects.requireNonNull(after);
|
||||
return (final T t) -> after.apply(apply(t));
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function.
|
||||
*
|
||||
* @param input the input for the function
|
||||
* @return the result of the function
|
||||
* @throws T Thrown when the function fails.
|
||||
* @throws E Thrown when the function fails.
|
||||
*/
|
||||
R apply(I input) throws T;
|
||||
R apply(T input) throws E;
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableFunction} like {@link Function#compose(Function)}.
|
||||
*
|
||||
* @param <V> the input type to the {@code before} function, and to the composed function.
|
||||
* @param before the operator to apply before this one.
|
||||
* @return a a composed {@code FailableFunction} like {@link Function#compose(Function)}.
|
||||
* @throws NullPointerException if before is null.
|
||||
* @see #andThen(FailableFunction)
|
||||
*/
|
||||
default <V> FailableFunction<V, R, E> compose(final FailableFunction<? super V, ? extends T, E> before) {
|
||||
Objects.requireNonNull(before);
|
||||
return (final V v) -> apply(before.apply(v));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,11 +22,11 @@
|
|||
/**
|
||||
* A functional interface like {@link IntBinaryOperator} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableIntBinaryOperator<T extends Throwable> {
|
||||
public interface FailableIntBinaryOperator<E extends Throwable> {
|
||||
|
||||
/**
|
||||
* Applies this operator to the given operands.
|
||||
|
@ -34,7 +34,7 @@ public interface FailableIntBinaryOperator<T extends Throwable> {
|
|||
* @param left the first operand
|
||||
* @param right the second operand
|
||||
* @return the operator result
|
||||
* @throws T if the operation fails
|
||||
* @throws E if the operation fails
|
||||
*/
|
||||
int applyAsInt(int left, int right) throws T;
|
||||
int applyAsInt(int left, int right) throws E;
|
||||
}
|
||||
|
|
|
@ -17,22 +17,53 @@
|
|||
|
||||
package org.apache.commons.lang3.function;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
/**
|
||||
* A functional interface like {@link IntConsumer} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableIntConsumer<T extends Throwable> {
|
||||
public interface FailableIntConsumer<E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableIntConsumer NOP = t -> {/* NOP */};
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableIntConsumer<E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts the consumer.
|
||||
*
|
||||
* @param value the parameter for the consumable to accept
|
||||
* @throws T Thrown when the consumer fails.
|
||||
* @throws E Thrown when the consumer fails.
|
||||
*/
|
||||
void accept(int value) throws T;
|
||||
void accept(int value) throws E;
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableIntConsumer} like {@link IntConsumer#andThen(IntConsumer)}.
|
||||
*
|
||||
* @param after the operation to perform after this one.
|
||||
* @return a composed {@code FailableLongConsumer} like {@link IntConsumer#andThen(IntConsumer)}.
|
||||
* @throws NullPointerException if {@code after} is null
|
||||
*/
|
||||
default FailableIntConsumer<E> andThen(final FailableIntConsumer<E> after) {
|
||||
Objects.requireNonNull(after);
|
||||
return (final int t) -> {
|
||||
accept(t);
|
||||
after.accept(t);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,18 +23,33 @@
|
|||
* A functional interface like {@link IntFunction} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <R> Return type.
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableIntFunction<R, T extends Throwable> {
|
||||
public interface FailableIntFunction<R, E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableIntFunction NOP = t -> null;
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <R> Return type.
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <R, E extends Throwable> FailableIntFunction<R, E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function.
|
||||
*
|
||||
* @param input the input for the function
|
||||
* @return the result of the function
|
||||
* @throws T Thrown when the function fails.
|
||||
* @throws E Thrown when the function fails.
|
||||
*/
|
||||
R apply(int input) throws T;
|
||||
R apply(int input) throws E;
|
||||
}
|
||||
|
|
|
@ -17,23 +17,85 @@
|
|||
|
||||
package org.apache.commons.lang3.function;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.IntPredicate;
|
||||
|
||||
/**
|
||||
* A functional interface like {@link IntPredicate} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableIntPredicate<T extends Throwable> {
|
||||
public interface FailableIntPredicate<E extends Throwable> {
|
||||
|
||||
/** FALSE singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableIntPredicate FALSE = t -> false;
|
||||
|
||||
/** TRUE singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableIntPredicate TRUE = t -> true;
|
||||
|
||||
/**
|
||||
* Returns The FALSE singleton.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableIntPredicate<E> falsePredicate() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns The FALSE TRUE.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableIntPredicate<E> truePredicate() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableIntPredicate} like {@link IntPredicate#and(IntPredicate)}.
|
||||
*
|
||||
* @param other a predicate that will be logically-ANDed with this predicate.
|
||||
* @return a composed {@code FailableIntPredicate} like {@link IntPredicate#and(IntPredicate)}.
|
||||
* @throws NullPointerException if other is null
|
||||
*/
|
||||
default FailableIntPredicate<E> and(final FailableIntPredicate<E> other) {
|
||||
Objects.requireNonNull(other);
|
||||
return t -> test(t) && other.test(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a predicate that negates this predicate.
|
||||
*
|
||||
* @return a predicate that negates this predicate.
|
||||
*/
|
||||
default FailableIntPredicate<E> negate() {
|
||||
return t -> !test(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableIntPredicate} like {@link IntPredicate#and(IntPredicate)}.
|
||||
*
|
||||
* @param other a predicate that will be logically-ORed with this predicate.
|
||||
* @return a composed {@code FailableIntPredicate} like {@link IntPredicate#and(IntPredicate)}.
|
||||
* @throws NullPointerException if other is null
|
||||
*/
|
||||
default FailableIntPredicate<E> or(final FailableIntPredicate<E> other) {
|
||||
Objects.requireNonNull(other);
|
||||
return t -> test(t) || other.test(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the predicate.
|
||||
*
|
||||
* @param value the parameter for the predicate to accept.
|
||||
* @return {@code true} if the input argument matches the predicate, {@code false} otherwise.
|
||||
* @throws T Thrown when the consumer fails.
|
||||
* @throws E Thrown when the consumer fails.
|
||||
*/
|
||||
boolean test(int value) throws T;
|
||||
boolean test(int value) throws E;
|
||||
}
|
||||
|
|
|
@ -22,17 +22,17 @@
|
|||
/**
|
||||
* A functional interface like {@link IntSupplier} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableIntSupplier<T extends Throwable> {
|
||||
public interface FailableIntSupplier<E extends Throwable> {
|
||||
|
||||
/**
|
||||
* Supplies an int.
|
||||
*
|
||||
* @return a result
|
||||
* @throws T if the supplier fails
|
||||
* @throws E if the supplier fails
|
||||
*/
|
||||
int getAsInt() throws T;
|
||||
int getAsInt() throws E;
|
||||
}
|
||||
|
|
|
@ -22,18 +22,32 @@
|
|||
/**
|
||||
* A functional interface like {@link IntToDoubleFunction} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableIntToDoubleFunction<T extends Throwable> {
|
||||
public interface FailableIntToDoubleFunction<E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableIntToDoubleFunction NOP = t -> 0d;
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableIntToDoubleFunction<E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function to the given argument.
|
||||
*
|
||||
* @param value the function argument
|
||||
* @return the function result
|
||||
* @throws T Thrown when the function fails.
|
||||
* @throws E Thrown when the function fails.
|
||||
*/
|
||||
double applyAsDouble(int value) throws T;
|
||||
double applyAsDouble(int value) throws E;
|
||||
}
|
||||
|
|
|
@ -22,18 +22,32 @@
|
|||
/**
|
||||
* A functional interface like {@link IntToLongFunction} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableIntToLongFunction<T extends Throwable> {
|
||||
public interface FailableIntToLongFunction<E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableIntToLongFunction NOP = t -> 0L;
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableIntToLongFunction<E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function to the given argument.
|
||||
*
|
||||
* @param value the function argument
|
||||
* @return the function result
|
||||
* @throws T Thrown when the function fails.
|
||||
* @throws E Thrown when the function fails.
|
||||
*/
|
||||
long applyAsLong(int value) throws T;
|
||||
long applyAsLong(int value) throws E;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.commons.lang3.function;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.IntUnaryOperator;
|
||||
|
||||
/**
|
||||
* A functional interface like {@link IntUnaryOperator} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
public interface FailableIntUnaryOperator<E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableIntUnaryOperator NOP = t -> 0;
|
||||
|
||||
/**
|
||||
* Returns a unary operator that always returns its input argument.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return a unary operator that always returns its input argument
|
||||
*/
|
||||
static <E extends Throwable> FailableIntUnaryOperator<E> identity() {
|
||||
return t -> t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableIntUnaryOperator<E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableDoubleUnaryOperator} like {@link IntUnaryOperator#andThen(IntUnaryOperator)}.
|
||||
*
|
||||
* @param after the operator to apply after this one.
|
||||
* @return a composed {@code FailableIntUnaryOperator} like {@link IntUnaryOperator#andThen(IntUnaryOperator)}.
|
||||
* @throws NullPointerException if after is null.
|
||||
* @see #compose(FailableIntUnaryOperator)
|
||||
*/
|
||||
default FailableIntUnaryOperator<E> andThen(final FailableIntUnaryOperator<E> after) {
|
||||
Objects.requireNonNull(after);
|
||||
return (final int t) -> after.applyAsInt(applyAsInt(t));
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this operator to the given operand.
|
||||
*
|
||||
* @param operand the operand
|
||||
* @return the operator result
|
||||
* @throws E Thrown when a consumer fails.
|
||||
*/
|
||||
int applyAsInt(int operand) throws E;
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableIntUnaryOperator} like {@link IntUnaryOperator#compose(IntUnaryOperator)}.
|
||||
*
|
||||
* @param before the operator to apply before this one.
|
||||
* @return a composed {@code FailableIntUnaryOperator} like {@link IntUnaryOperator#compose(IntUnaryOperator)}.
|
||||
* @throws NullPointerException if before is null.
|
||||
* @see #andThen(FailableIntUnaryOperator)
|
||||
*/
|
||||
default FailableIntUnaryOperator<E> compose(final FailableIntUnaryOperator<E> before) {
|
||||
Objects.requireNonNull(before);
|
||||
return (final int v) -> applyAsInt(before.applyAsInt(v));
|
||||
}
|
||||
}
|
|
@ -22,11 +22,11 @@
|
|||
/**
|
||||
* A functional interface like {@link LongBinaryOperator} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableLongBinaryOperator<T extends Throwable> {
|
||||
public interface FailableLongBinaryOperator<E extends Throwable> {
|
||||
|
||||
/**
|
||||
* Applies this operator to the given operands.
|
||||
|
@ -34,7 +34,7 @@ public interface FailableLongBinaryOperator<T extends Throwable> {
|
|||
* @param left the first operand
|
||||
* @param right the second operand
|
||||
* @return the operator result
|
||||
* @throws T if the operation fails
|
||||
* @throws E if the operation fails
|
||||
*/
|
||||
long applyAsLong(long left, long right) throws T;
|
||||
long applyAsLong(long left, long right) throws E;
|
||||
}
|
||||
|
|
|
@ -17,22 +17,52 @@
|
|||
|
||||
package org.apache.commons.lang3.function;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.LongConsumer;
|
||||
|
||||
/**
|
||||
* A functional interface like {@link LongConsumer} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableLongConsumer<T extends Throwable> {
|
||||
public interface FailableLongConsumer<E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableLongConsumer NOP = t -> {/* NOP */};
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableLongConsumer<E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts the consumer.
|
||||
*
|
||||
* @param object the parameter for the consumable to accept
|
||||
* @throws T Thrown when the consumer fails.
|
||||
* @throws E Thrown when the consumer fails.
|
||||
*/
|
||||
void accept(long object) throws T;
|
||||
void accept(long object) throws E;
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableLongConsumer} like {@link LongConsumer#andThen(LongConsumer)}.
|
||||
*
|
||||
* @param after the operation to perform after this one.
|
||||
* @return a composed {@code FailableLongConsumer} like {@link LongConsumer#andThen(LongConsumer)}.
|
||||
* @throws NullPointerException if {@code after} is null
|
||||
*/
|
||||
default FailableLongConsumer<E> andThen(final FailableLongConsumer<E> after) {
|
||||
Objects.requireNonNull(after);
|
||||
return (final long t) -> {
|
||||
accept(t);
|
||||
after.accept(t);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,18 +23,33 @@
|
|||
* A functional interface like {@link LongFunction} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <R> Return type.
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableLongFunction<R, T extends Throwable> {
|
||||
public interface FailableLongFunction<R, E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableLongFunction NOP = t -> null;
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <R> Return type.
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <R, E extends Throwable> FailableLongFunction<R, E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function.
|
||||
*
|
||||
* @param input the input for the function
|
||||
* @return the result of the function
|
||||
* @throws T Thrown when the function fails.
|
||||
* @throws E Thrown when the function fails.
|
||||
*/
|
||||
R apply(long input) throws T;
|
||||
R apply(long input) throws E;
|
||||
}
|
||||
|
|
|
@ -17,23 +17,85 @@
|
|||
|
||||
package org.apache.commons.lang3.function;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.LongPredicate;
|
||||
|
||||
/**
|
||||
* A functional interface like {@link LongPredicate} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableLongPredicate<T extends Throwable> {
|
||||
public interface FailableLongPredicate<E extends Throwable> {
|
||||
|
||||
/** FALSE singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableLongPredicate FALSE = t -> false;
|
||||
|
||||
/** TRUE singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableLongPredicate TRUE = t -> true;
|
||||
|
||||
/**
|
||||
* Returns The FALSE singleton.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableLongPredicate<E> falsePredicate() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns The FALSE TRUE.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableLongPredicate<E> truePredicate() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableLongPredicate} like {@link LongPredicate#and(LongPredicate)}.
|
||||
*
|
||||
* @param other a predicate that will be logically-ANDed with this predicate.
|
||||
* @return a composed {@code FailableLongPredicate} like {@link LongPredicate#and(LongPredicate)}.
|
||||
* @throws NullPointerException if other is null
|
||||
*/
|
||||
default FailableLongPredicate<E> and(final FailableLongPredicate<E> other) {
|
||||
Objects.requireNonNull(other);
|
||||
return t -> test(t) && other.test(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a predicate that negates this predicate.
|
||||
*
|
||||
* @return a predicate that negates this predicate.
|
||||
*/
|
||||
default FailableLongPredicate<E> negate() {
|
||||
return t -> !test(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableLongPredicate} like {@link LongPredicate#and(LongPredicate)}.
|
||||
*
|
||||
* @param other a predicate that will be logically-ORed with this predicate.
|
||||
* @return a composed {@code FailableLongPredicate} like {@link LongPredicate#and(LongPredicate)}.
|
||||
* @throws NullPointerException if other is null
|
||||
*/
|
||||
default FailableLongPredicate<E> or(final FailableLongPredicate<E> other) {
|
||||
Objects.requireNonNull(other);
|
||||
return t -> test(t) || other.test(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the predicate.
|
||||
*
|
||||
* @param value the parameter for the predicate to accept.
|
||||
* @return {@code true} if the input argument matches the predicate, {@code false} otherwise.
|
||||
* @throws T Thrown when the consumer fails.
|
||||
* @throws E Thrown when the consumer fails.
|
||||
*/
|
||||
boolean test(long value) throws T;
|
||||
boolean test(long value) throws E;
|
||||
}
|
||||
|
|
|
@ -22,17 +22,17 @@
|
|||
/**
|
||||
* A functional interface like {@link LongSupplier} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableLongSupplier<T extends Throwable> {
|
||||
public interface FailableLongSupplier<E extends Throwable> {
|
||||
|
||||
/**
|
||||
* Supplies a long.
|
||||
*
|
||||
* @return a result
|
||||
* @throws T if the supplier fails
|
||||
* @throws E if the supplier fails
|
||||
*/
|
||||
long getAsLong() throws T;
|
||||
long getAsLong() throws E;
|
||||
}
|
||||
|
|
|
@ -22,18 +22,32 @@
|
|||
/**
|
||||
* A functional interface like {@link LongToDoubleFunction} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableLongToDoubleFunction<T extends Throwable> {
|
||||
public interface FailableLongToDoubleFunction<E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableLongToDoubleFunction NOP = t -> 0d;
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableLongToDoubleFunction<E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function to the given argument.
|
||||
*
|
||||
* @param value the function argument
|
||||
* @return the function result
|
||||
* @throws T Thrown when the function fails.
|
||||
* @throws E Thrown when the function fails.
|
||||
*/
|
||||
double applyAsDouble(long value) throws T;
|
||||
double applyAsDouble(long value) throws E;
|
||||
}
|
||||
|
|
|
@ -22,18 +22,32 @@
|
|||
/**
|
||||
* A functional interface like {@link LongToIntFunction} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableLongToIntFunction<T extends Throwable> {
|
||||
public interface FailableLongToIntFunction<E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableLongToIntFunction NOP = t -> 0;
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableLongToIntFunction<E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function to the given argument.
|
||||
*
|
||||
* @param value the function argument
|
||||
* @return the function result
|
||||
* @throws T Thrown when the function fails.
|
||||
* @throws E Thrown when the function fails.
|
||||
*/
|
||||
int applyAsInt(long value) throws T;
|
||||
int applyAsInt(long value) throws E;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.commons.lang3.function;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.LongUnaryOperator;
|
||||
|
||||
/**
|
||||
* A functional interface like {@link LongUnaryOperator} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
public interface FailableLongUnaryOperator<E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableLongUnaryOperator NOP = t -> 0L;
|
||||
|
||||
/**
|
||||
* Returns a unary operator that always returns its input argument.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return a unary operator that always returns its input argument
|
||||
*/
|
||||
static <E extends Throwable> FailableLongUnaryOperator<E> identity() {
|
||||
return t -> t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <E extends Throwable> FailableLongUnaryOperator<E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableDoubleUnaryOperator} like {@link LongUnaryOperator#andThen(LongUnaryOperator)}.
|
||||
*
|
||||
* @param after the operator to apply after this one.
|
||||
* @return a composed {@code FailableLongUnaryOperator} like {@link LongUnaryOperator#andThen(LongUnaryOperator)}.
|
||||
* @throws NullPointerException if after is null.
|
||||
* @see #compose(FailableLongUnaryOperator)
|
||||
*/
|
||||
default FailableLongUnaryOperator<E> andThen(final FailableLongUnaryOperator<E> after) {
|
||||
Objects.requireNonNull(after);
|
||||
return (final long t) -> after.applyAsLong(applyAsLong(t));
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this operator to the given operand.
|
||||
*
|
||||
* @param operand the operand
|
||||
* @return the operator result
|
||||
* @throws E Thrown when a consumer fails.
|
||||
*/
|
||||
long applyAsLong(long operand) throws E;
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailableLongUnaryOperator} like {@link LongUnaryOperator#compose(LongUnaryOperator)}.
|
||||
*
|
||||
* @param before the operator to apply before this one.
|
||||
* @return a composed {@code FailableLongUnaryOperator} like {@link LongUnaryOperator#compose(LongUnaryOperator)}.
|
||||
* @throws NullPointerException if before is null.
|
||||
* @see #andThen(FailableLongUnaryOperator)
|
||||
*/
|
||||
default FailableLongUnaryOperator<E> compose(final FailableLongUnaryOperator<E> before) {
|
||||
Objects.requireNonNull(before);
|
||||
return (final long v) -> applyAsLong(before.applyAsLong(v));
|
||||
}
|
||||
}
|
|
@ -22,19 +22,34 @@
|
|||
/**
|
||||
* A functional interface like {@link ObjDoubleConsumer} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <O> the type of the object argument to the operation.
|
||||
* @param <T> Thrown exception.
|
||||
* @param <T> the type of the object argument to the operation.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableObjDoubleConsumer<O, T extends Throwable> {
|
||||
public interface FailableObjDoubleConsumer<T, E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableObjDoubleConsumer NOP = (t, u) -> {/* NOP */};
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <T> the type of the object argument to the operation.
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <T, E extends Throwable> FailableObjDoubleConsumer<T, E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts the consumer.
|
||||
*
|
||||
* @param object the object parameter for the consumable to accept.
|
||||
* @param value the double parameter for the consumable to accept.
|
||||
* @throws T Thrown when the consumer fails.
|
||||
* @param value the double parameter for the consumable to accept.
|
||||
* @throws E Thrown when the consumer fails.
|
||||
*/
|
||||
void accept(O object, double value) throws T;
|
||||
void accept(T object, double value) throws E;
|
||||
}
|
||||
|
|
|
@ -22,19 +22,34 @@
|
|||
/**
|
||||
* A functional interface like {@link ObjIntConsumer} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <O> the type of the object argument to the operation.
|
||||
* @param <T> Thrown exception.
|
||||
* @param <T> the type of the object argument to the operation.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableObjIntConsumer<O, T extends Throwable> {
|
||||
public interface FailableObjIntConsumer<T, E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableObjIntConsumer NOP = (t, u) -> {/* NOP */};
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <T> the type of the object argument to the operation.
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <T, E extends Throwable> FailableObjIntConsumer<T, E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts the consumer.
|
||||
*
|
||||
* @param object the object parameter for the consumable to accept.
|
||||
* @param value the int parameter for the consumable to accept.
|
||||
* @throws T Thrown when the consumer fails.
|
||||
* @param value the int parameter for the consumable to accept.
|
||||
* @throws E Thrown when the consumer fails.
|
||||
*/
|
||||
void accept(O object, int value) throws T;
|
||||
void accept(T object, int value) throws E;
|
||||
}
|
||||
|
|
|
@ -22,19 +22,34 @@
|
|||
/**
|
||||
* A functional interface like {@link ObjLongConsumer} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <O> the type of the object argument to the operation.
|
||||
* @param <T> Thrown exception.
|
||||
* @param <T> the type of the object argument to the operation.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableObjLongConsumer<O, T extends Throwable> {
|
||||
public interface FailableObjLongConsumer<T, E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableObjLongConsumer NOP = (t, u) -> {/* NOP */};
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <T> the type of the object argument to the operation.
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <T, E extends Throwable> FailableObjLongConsumer<T, E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts the consumer.
|
||||
*
|
||||
* @param object the object parameter for the consumable to accept.
|
||||
* @param value the long parameter for the consumable to accept.
|
||||
* @throws T Thrown when the consumer fails.
|
||||
* @param value the long parameter for the consumable to accept.
|
||||
* @throws E Thrown when the consumer fails.
|
||||
*/
|
||||
void accept(O object, long value) throws T;
|
||||
void accept(T object, long value) throws E;
|
||||
}
|
||||
|
|
|
@ -17,24 +17,88 @@
|
|||
|
||||
package org.apache.commons.lang3.function;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* A functional interface like {@link Predicate} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <I> Predicate type 1.
|
||||
* @param <T> Thrown exception.
|
||||
* @param <T> Predicate type.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailablePredicate<I, T extends Throwable> {
|
||||
public interface FailablePredicate<T, E extends Throwable> {
|
||||
|
||||
/** FALSE singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailablePredicate FALSE = t -> false;
|
||||
|
||||
/** TRUE singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailablePredicate TRUE = t -> true;
|
||||
|
||||
/**
|
||||
* Returns The FALSE singleton.
|
||||
*
|
||||
* @param <T> Predicate type.
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <T, E extends Throwable> FailablePredicate<T, E> falsePredicate() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns The FALSE TRUE.
|
||||
*
|
||||
* @param <T> Predicate type.
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <T, E extends Throwable> FailablePredicate<T, E> truePredicate() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailablePredicate} like {@link Predicate#and(Predicate)}.
|
||||
*
|
||||
* @param other a predicate that will be logically-ANDed with this predicate.
|
||||
* @return a composed {@code FailablePredicate} like {@link Predicate#and(Predicate)}.
|
||||
* @throws NullPointerException if other is null
|
||||
*/
|
||||
default FailablePredicate<T, E> and(final FailablePredicate<? super T, E> other) {
|
||||
Objects.requireNonNull(other);
|
||||
return t -> test(t) && other.test(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a predicate that negates this predicate.
|
||||
*
|
||||
* @return a predicate that negates this predicate.
|
||||
*/
|
||||
default FailablePredicate<T, E> negate() {
|
||||
return t -> !test(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed {@code FailablePredicate} like {@link Predicate#and(Predicate)}.
|
||||
*
|
||||
* @param other a predicate that will be logically-ORed with this predicate.
|
||||
* @return a composed {@code FailablePredicate} like {@link Predicate#and(Predicate)}.
|
||||
* @throws NullPointerException if other is null
|
||||
*/
|
||||
default FailablePredicate<T, E> or(final FailablePredicate<? super T, E> other) {
|
||||
Objects.requireNonNull(other);
|
||||
return t -> test(t) || other.test(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the predicate.
|
||||
*
|
||||
* @param object the object to test the predicate on
|
||||
* @return the predicate's evaluation
|
||||
* @throws T if the predicate fails
|
||||
* @throws E if the predicate fails
|
||||
*/
|
||||
boolean test(I object) throws T;
|
||||
boolean test(T object) throws E;
|
||||
}
|
||||
|
|
|
@ -20,16 +20,16 @@
|
|||
/**
|
||||
* A functional interface like {@link Runnable} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableRunnable<T extends Throwable> {
|
||||
public interface FailableRunnable<E extends Throwable> {
|
||||
|
||||
/**
|
||||
* Runs the function.
|
||||
*
|
||||
* @throws T Thrown when the function fails.
|
||||
* @throws E Thrown when the function fails.
|
||||
*/
|
||||
void run() throws T;
|
||||
void run() throws E;
|
||||
}
|
||||
|
|
|
@ -23,17 +23,17 @@
|
|||
* A functional interface like {@link Supplier} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <R> Return type.
|
||||
* @param <T> Thrown exception.
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableSupplier<R, T extends Throwable> {
|
||||
public interface FailableSupplier<R, E extends Throwable> {
|
||||
|
||||
/**
|
||||
* Supplies an object
|
||||
*
|
||||
* @return a result
|
||||
* @throws T if the supplier fails
|
||||
* @throws E if the supplier fails
|
||||
*/
|
||||
R get() throws T;
|
||||
R get() throws E;
|
||||
}
|
||||
|
|
|
@ -22,13 +22,29 @@
|
|||
/**
|
||||
* A functional interface like {@link ToDoubleBiFunction} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <O1> the type of the first argument to the function
|
||||
* @param <O2> the type of the second argument to the function
|
||||
* @param <T> Thrown exception.
|
||||
* @param <T> the type of the first argument to the function
|
||||
* @param <U> the type of the second argument to the function
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableToDoubleBiFunction<O1, O2, T extends Throwable> {
|
||||
public interface FailableToDoubleBiFunction<T, U, E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableToDoubleBiFunction NOP = (t, u) -> 0d;
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <T> the type of the first argument to the function
|
||||
* @param <U> the type of the second argument to the function
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <T, U, E extends Throwable> FailableToDoubleBiFunction<T, U, E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function to the given arguments.
|
||||
|
@ -36,7 +52,7 @@ public interface FailableToDoubleBiFunction<O1, O2, T extends Throwable> {
|
|||
* @param t the first function argument
|
||||
* @param u the second function argument
|
||||
* @return the function result
|
||||
* @throws T Thrown when the function fails.
|
||||
* @throws E Thrown when the function fails.
|
||||
*/
|
||||
double applyAsDouble(O1 t, O2 u) throws T;
|
||||
double applyAsDouble(T t, U u) throws E;
|
||||
}
|
||||
|
|
|
@ -22,19 +22,34 @@
|
|||
/**
|
||||
* A functional interface like {@link ToDoubleFunction} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <I> the type of the first argument to the function
|
||||
* @param <T> Thrown exception.
|
||||
* @param <T> the type of the argument to the function
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableToDoubleFunction<I, T extends Throwable> {
|
||||
public interface FailableToDoubleFunction<T, E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableToDoubleFunction NOP = t -> 0d;
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <T> the type of the argument to the function
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <T, E extends Throwable> FailableToDoubleFunction<T, E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function to the given arguments.
|
||||
*
|
||||
* @param t the first function argument
|
||||
* @return the function result
|
||||
* @throws T Thrown when the function fails.
|
||||
* @throws E Thrown when the function fails.
|
||||
*/
|
||||
double applyAsDouble(I t) throws T;
|
||||
double applyAsDouble(T t) throws E;
|
||||
}
|
||||
|
|
|
@ -22,13 +22,29 @@
|
|||
/**
|
||||
* A functional interface like {@link ToIntBiFunction} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <O1> the type of the first argument to the function
|
||||
* @param <O2> the type of the second argument to the function
|
||||
* @param <T> Thrown exception.
|
||||
* @param <T> the type of the first argument to the function
|
||||
* @param <U> the type of the second argument to the function
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableToIntBiFunction<O1, O2, T extends Throwable> {
|
||||
public interface FailableToIntBiFunction<T, U, E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableToIntBiFunction NOP = (t, u) -> 0;
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <T> the type of the first argument to the function
|
||||
* @param <U> the type of the second argument to the function
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <T, U, E extends Throwable> FailableToIntBiFunction<T, U, E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function to the given arguments.
|
||||
|
@ -36,7 +52,7 @@ public interface FailableToIntBiFunction<O1, O2, T extends Throwable> {
|
|||
* @param t the first function argument
|
||||
* @param u the second function argument
|
||||
* @return the function result
|
||||
* @throws T Thrown when the function fails.
|
||||
* @throws E Thrown when the function fails.
|
||||
*/
|
||||
int applyAsInt(O1 t, O2 u) throws T;
|
||||
int applyAsInt(T t, U u) throws E;
|
||||
}
|
||||
|
|
|
@ -22,19 +22,34 @@
|
|||
/**
|
||||
* A functional interface like {@link ToIntFunction} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <I> the type of the first argument to the function
|
||||
* @param <T> Thrown exception.
|
||||
* @param <T> the type of the argument to the function
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableToIntFunction<I, T extends Throwable> {
|
||||
public interface FailableToIntFunction<T, E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableToIntFunction NOP = t -> 0;
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <T> the type of the argument to the function
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <T, E extends Throwable> FailableToIntFunction<T, E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function to the given arguments.
|
||||
*
|
||||
* @param t the first function argument
|
||||
* @return the function result
|
||||
* @throws T Thrown when the function fails.
|
||||
* @throws E Thrown when the function fails.
|
||||
*/
|
||||
int applyAsInt(I t) throws T;
|
||||
int applyAsInt(T t) throws E;
|
||||
}
|
||||
|
|
|
@ -22,13 +22,29 @@
|
|||
/**
|
||||
* A functional interface like {@link ToLongBiFunction} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <O1> the type of the first argument to the function
|
||||
* @param <O2> the type of the second argument to the function
|
||||
* @param <T> Thrown exception.
|
||||
* @param <T> the type of the first argument to the function
|
||||
* @param <U> the type of the second argument to the function
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableToLongBiFunction<O1, O2, T extends Throwable> {
|
||||
public interface FailableToLongBiFunction<T, U, E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableToLongBiFunction NOP = (t, u) -> 0;
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <T> the type of the first argument to the function
|
||||
* @param <U> the type of the second argument to the function
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <T, U, E extends Throwable> FailableToLongBiFunction<T, U, E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function to the given arguments.
|
||||
|
@ -36,7 +52,7 @@ public interface FailableToLongBiFunction<O1, O2, T extends Throwable> {
|
|||
* @param t the first function argument
|
||||
* @param u the second function argument
|
||||
* @return the function result
|
||||
* @throws T Thrown when the function fails.
|
||||
* @throws E Thrown when the function fails.
|
||||
*/
|
||||
long applyAsLong(O1 t, O2 u) throws T;
|
||||
long applyAsLong(T t, U u) throws E;
|
||||
}
|
||||
|
|
|
@ -22,19 +22,34 @@
|
|||
/**
|
||||
* A functional interface like {@link ToLongFunction} that declares a {@code Throwable}.
|
||||
*
|
||||
* @param <I> the type of the first argument to the function
|
||||
* @param <T> Thrown exception.
|
||||
* @param <T> the type of the first argument to the function
|
||||
* @param <E> Thrown exception.
|
||||
* @since 3.11
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailableToLongFunction<I, T extends Throwable> {
|
||||
public interface FailableToLongFunction<T, E extends Throwable> {
|
||||
|
||||
/** NOP singleton */
|
||||
@SuppressWarnings("rawtypes")
|
||||
FailableToLongFunction NOP = t -> 0L;
|
||||
|
||||
/**
|
||||
* Returns The NOP singleton.
|
||||
*
|
||||
* @param <T> the type of the argument to the function
|
||||
* @param <E> Thrown exception.
|
||||
* @return The NOP singleton.
|
||||
*/
|
||||
static <T, E extends Throwable> FailableToLongFunction<T, E> nop() {
|
||||
return NOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this function to the given arguments.
|
||||
*
|
||||
* @param t the first function argument
|
||||
* @return the function result
|
||||
* @throws T Thrown when the function fails.
|
||||
* @throws E Thrown when the function fails.
|
||||
*/
|
||||
long applyAsLong(I t) throws T;
|
||||
long applyAsLong(T t) throws E;
|
||||
}
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* Provides functional interfaces to complement those in {@code java.lang.function} and utilities
|
||||
* for working with Java 8 lambdas.
|
||||
* Provides functional interfaces to complement those in {@code java.lang.function} and utilities for working with Java
|
||||
* 8 lambdas.
|
||||
*
|
||||
* <p>Contains failable functional interfaces that address the fact that lambdas are supposed not to
|
||||
* throw Exceptions, at least not checked Exceptions, AKA instances of {@link java.lang.Exception}.
|
||||
* A failable functional interface declares a type of Exception that may be raised if the function
|
||||
* fails.
|
||||
* <p>
|
||||
* Contains failable functional interfaces that address the fact that lambdas are supposed not to throw Exceptions, at
|
||||
* least not checked Exceptions, A.K.A. instances of {@link java.lang.Exception}. A failable functional interface
|
||||
* declares a type of Exception that may be raised if the function fails.
|
||||
*
|
||||
* @since 3.11
|
||||
*/
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
import java.lang.reflect.Array;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
|
|
|
@ -29,8 +29,9 @@
|
|||
* If these do not suffice, you can subclass and implement your own matcher.
|
||||
* <p>
|
||||
* For example, it would be possible to implement a lookup that used the
|
||||
* key as a primary key, and looked up the value on demand from the database
|
||||
* key as a primary key, and looked up the value on demand from the database.
|
||||
*
|
||||
* @param <V> Unused.
|
||||
* @since 2.2
|
||||
* @deprecated as of 3.6, use commons-text
|
||||
* <a href="https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/StringLookupFactory.html">
|
||||
|
|
|
@ -361,14 +361,14 @@ public static Date parseDateStrictly(final String str, final Locale locale, fina
|
|||
* @throws ParseException if none of the date patterns were suitable
|
||||
* @see java.util.Calendar#isLenient()
|
||||
*/
|
||||
private static Date parseDateWithLeniency(
|
||||
final String str, final Locale locale, final String[] parsePatterns, final boolean lenient) throws ParseException {
|
||||
private static Date parseDateWithLeniency(final String str, final Locale locale, final String[] parsePatterns,
|
||||
final boolean lenient) throws ParseException {
|
||||
if (str == null || parsePatterns == null) {
|
||||
throw new IllegalArgumentException("Date and Patterns must not be null");
|
||||
}
|
||||
|
||||
final TimeZone tz = TimeZone.getDefault();
|
||||
final Locale lcl = locale==null ?Locale.getDefault() : locale;
|
||||
final Locale lcl = locale == null ? Locale.getDefault() : locale;
|
||||
final ParsePosition pos = new ParsePosition(0);
|
||||
final Calendar calendar = Calendar.getInstance(tz, lcl);
|
||||
calendar.setLenient(lenient);
|
||||
|
@ -377,10 +377,10 @@ private static Date parseDateWithLeniency(
|
|||
final FastDateParser fdp = new FastDateParser(parsePattern, tz, lcl);
|
||||
calendar.clear();
|
||||
try {
|
||||
if (fdp.parse(str, pos, calendar) && pos.getIndex()==str.length()) {
|
||||
if (fdp.parse(str, pos, calendar) && pos.getIndex() == str.length()) {
|
||||
return calendar.getTime();
|
||||
}
|
||||
} catch(final IllegalArgumentException ignore) {
|
||||
} catch (final IllegalArgumentException ignore) {
|
||||
// leniency is preventing calendar from being set
|
||||
}
|
||||
pos.setIndex(0);
|
||||
|
|
|
@ -69,6 +69,22 @@ public static <L, R> ImmutablePair<L, R>[] emptyArray() {
|
|||
return (ImmutablePair<L, R>[]) EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Creates an immutable pair of two objects inferring the generic types.</p>
|
||||
*
|
||||
* <p>This factory allows the pair to be created using inference to
|
||||
* obtain the generic types.</p>
|
||||
*
|
||||
* @param <L> the left element type
|
||||
* @param <R> the right element type
|
||||
* @param left the left element, may be null
|
||||
* @return a pair formed from the two parameters, not null
|
||||
* @since 3.11
|
||||
*/
|
||||
public static <L, R> Pair<L, R> left(final L left) {
|
||||
return ImmutablePair.of(left, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an immutable pair of nulls.
|
||||
*
|
||||
|
@ -122,6 +138,22 @@ public static <L, R> ImmutablePair<L, R> of(final Map.Entry<L, R> pair) {
|
|||
return new ImmutablePair<>(left, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Creates an immutable pair of two objects inferring the generic types.</p>
|
||||
*
|
||||
* <p>This factory allows the pair to be created using inference to
|
||||
* obtain the generic types.</p>
|
||||
*
|
||||
* @param <L> the left element type
|
||||
* @param <R> the right element type
|
||||
* @param right the right element, may be null
|
||||
* @return a pair formed from the two parameters, not null
|
||||
* @since 3.11
|
||||
*/
|
||||
public static <L, R> Pair<L, R> right(final R right) {
|
||||
return ImmutablePair.of(null, right);
|
||||
}
|
||||
|
||||
/** Left object */
|
||||
public final L left;
|
||||
|
||||
|
|
|
@ -40,8 +40,8 @@
|
|||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
|
|
@ -16,17 +16,17 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.apache.commons.lang3.arch.Processor;
|
||||
import org.apache.commons.lang3.arch.Processor.Arch;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
/**
|
||||
* Test class for {@link ArchUtils}.
|
||||
*/
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests CharEncoding.
|
||||
*
|
||||
|
|
|
@ -16,13 +16,15 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import org.apache.commons.lang3.ClassUtils.Interfaces;
|
||||
import org.apache.commons.lang3.reflect.testbed.GenericConsumer;
|
||||
import org.apache.commons.lang3.reflect.testbed.GenericParent;
|
||||
import org.apache.commons.lang3.reflect.testbed.StringParameterizedChild;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
@ -35,15 +37,13 @@
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import org.apache.commons.lang3.ClassUtils.Interfaces;
|
||||
import org.apache.commons.lang3.reflect.testbed.GenericConsumer;
|
||||
import org.apache.commons.lang3.reflect.testbed.GenericParent;
|
||||
import org.apache.commons.lang3.reflect.testbed.StringParameterizedChild;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.ClassUtils}.
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
@ -77,17 +76,17 @@ static boolean failingBool() throws SomeException {
|
|||
return true;
|
||||
}
|
||||
|
||||
static boolean testDouble(double value) throws SomeException {
|
||||
static boolean testDouble(final double value) throws SomeException {
|
||||
throwOnOdd();
|
||||
return true;
|
||||
}
|
||||
|
||||
static boolean testInt(int value) throws SomeException {
|
||||
static boolean testInt(final int value) throws SomeException {
|
||||
throwOnOdd();
|
||||
return true;
|
||||
}
|
||||
|
||||
static boolean testLong(long value) throws SomeException {
|
||||
static boolean testLong(final long value) throws SomeException {
|
||||
throwOnOdd();
|
||||
return true;
|
||||
}
|
||||
|
@ -160,7 +159,7 @@ public void test() throws Throwable {
|
|||
test(throwable);
|
||||
}
|
||||
|
||||
public Object test(Object input1, Object input2) throws Throwable {
|
||||
public Object test(final Object input1, final Object input2) throws Throwable {
|
||||
test(throwable);
|
||||
return acceptedObject;
|
||||
}
|
||||
|
@ -226,41 +225,41 @@ public long testAsLongPrimitive(final Throwable throwable) throws Throwable {
|
|||
return 0;
|
||||
}
|
||||
|
||||
public void testDouble(double i) throws Throwable {
|
||||
public void testDouble(final double i) throws Throwable {
|
||||
test(throwable);
|
||||
acceptedPrimitiveObject1 = (P) ((Double) i);
|
||||
}
|
||||
|
||||
public double testDoubleDouble(double i, double j) throws Throwable {
|
||||
public double testDoubleDouble(final double i, final double j) throws Throwable {
|
||||
test(throwable);
|
||||
acceptedPrimitiveObject1 = (P) ((Double) i);
|
||||
acceptedPrimitiveObject2 = (P) ((Double) j);
|
||||
return 3d;
|
||||
}
|
||||
|
||||
public void testInt(int i) throws Throwable {
|
||||
public void testInt(final int i) throws Throwable {
|
||||
test(throwable);
|
||||
acceptedPrimitiveObject1 = (P) ((Integer) i);
|
||||
}
|
||||
|
||||
public void testLong(long i) throws Throwable {
|
||||
public void testLong(final long i) throws Throwable {
|
||||
test(throwable);
|
||||
acceptedPrimitiveObject1 = (P) ((Long) i);
|
||||
}
|
||||
|
||||
public void testObjDouble(T object, double i) throws Throwable {
|
||||
public void testObjDouble(final T object, final double i) throws Throwable {
|
||||
test(throwable);
|
||||
acceptedObject = object;
|
||||
acceptedPrimitiveObject1 = (P) ((Double) i);
|
||||
}
|
||||
|
||||
public void testObjInt(T object, int i) throws Throwable {
|
||||
public void testObjInt(final T object, final int i) throws Throwable {
|
||||
test(throwable);
|
||||
acceptedObject = object;
|
||||
acceptedPrimitiveObject1 = (P) ((Integer) i);
|
||||
}
|
||||
|
||||
public void testObjLong(T object, long i) throws Throwable {
|
||||
public void testObjLong(final T object, final long i) throws Throwable {
|
||||
test(throwable);
|
||||
acceptedObject = object;
|
||||
acceptedPrimitiveObject1 = (P) ((Long) i);
|
||||
|
@ -510,19 +509,6 @@ public void testApplyBiFunction() {
|
|||
assertEquals(0, i.intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyDoubleBinaryOperator() {
|
||||
final IllegalStateException ise = new IllegalStateException();
|
||||
final Testable<?, Double> testable = new Testable<>(ise);
|
||||
Throwable e = assertThrows(IllegalStateException.class,
|
||||
() -> Functions.applyAsDouble(testable::testDoubleDouble, 1d, 2d));
|
||||
assertSame(ise, e);
|
||||
|
||||
final Testable<?, Double> testable2 = new Testable<>(null);
|
||||
final double i = Functions.applyAsDouble(testable2::testDoubleDouble, 1d, 2d);
|
||||
assertEquals(3d, i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyFunction() {
|
||||
final IllegalStateException ise = new IllegalStateException();
|
||||
|
@ -736,103 +722,6 @@ public void testFunction() {
|
|||
assertEquals(0, function.apply(null).intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAsBooleanSupplier() {
|
||||
final IllegalStateException ise = new IllegalStateException();
|
||||
final Testable<?, ?> testable = new Testable<>(ise);
|
||||
Throwable e = assertThrows(IllegalStateException.class,
|
||||
() -> Functions.getAsBoolean(testable::testAsBooleanPrimitive));
|
||||
assertSame(ise, e);
|
||||
|
||||
final Error error = new OutOfMemoryError();
|
||||
testable.setThrowable(error);
|
||||
e = assertThrows(OutOfMemoryError.class, () -> Functions.getAsBoolean(testable::testAsBooleanPrimitive));
|
||||
assertSame(error, e);
|
||||
|
||||
final IOException ioe = new IOException("Unknown I/O error");
|
||||
testable.setThrowable(ioe);
|
||||
e = assertThrows(UncheckedIOException.class, () -> Functions.getAsBoolean(testable::testAsBooleanPrimitive));
|
||||
final Throwable t = e.getCause();
|
||||
assertNotNull(t);
|
||||
assertSame(ioe, t);
|
||||
|
||||
testable.setThrowable(null);
|
||||
assertFalse(Functions.getAsBoolean(testable::testAsBooleanPrimitive));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAsDoubleSupplier() {
|
||||
final IllegalStateException ise = new IllegalStateException();
|
||||
final Testable<?, ?> testable = new Testable<>(ise);
|
||||
Throwable e = assertThrows(IllegalStateException.class,
|
||||
() -> Functions.getAsDouble(testable::testAsDoublePrimitive));
|
||||
assertSame(ise, e);
|
||||
|
||||
final Error error = new OutOfMemoryError();
|
||||
testable.setThrowable(error);
|
||||
e = assertThrows(OutOfMemoryError.class, () -> Functions.getAsDouble(testable::testAsDoublePrimitive));
|
||||
assertSame(error, e);
|
||||
|
||||
final IOException ioe = new IOException("Unknown I/O error");
|
||||
testable.setThrowable(ioe);
|
||||
e = assertThrows(UncheckedIOException.class, () -> Functions.getAsDouble(testable::testAsDoublePrimitive));
|
||||
final Throwable t = e.getCause();
|
||||
assertNotNull(t);
|
||||
assertSame(ioe, t);
|
||||
|
||||
testable.setThrowable(null);
|
||||
assertEquals(0, Functions.getAsDouble(testable::testAsDoublePrimitive));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAsIntSupplier() {
|
||||
final IllegalStateException ise = new IllegalStateException();
|
||||
final Testable<?, ?> testable = new Testable<>(ise);
|
||||
Throwable e = assertThrows(IllegalStateException.class, () -> Functions.getAsInt(testable::testAsIntPrimitive));
|
||||
assertSame(ise, e);
|
||||
|
||||
final Error error = new OutOfMemoryError();
|
||||
testable.setThrowable(error);
|
||||
e = assertThrows(OutOfMemoryError.class, () -> Functions.getAsInt(testable::testAsIntPrimitive));
|
||||
assertSame(error, e);
|
||||
|
||||
final IOException ioe = new IOException("Unknown I/O error");
|
||||
testable.setThrowable(ioe);
|
||||
e = assertThrows(UncheckedIOException.class, () -> Functions.getAsInt(testable::testAsIntPrimitive));
|
||||
final Throwable t = e.getCause();
|
||||
assertNotNull(t);
|
||||
assertSame(ioe, t);
|
||||
|
||||
testable.setThrowable(null);
|
||||
final int i = Functions.getAsInt(testable::testAsInteger);
|
||||
assertEquals(0, i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAsLongSupplier() {
|
||||
final IllegalStateException ise = new IllegalStateException();
|
||||
final Testable<?, ?> testable = new Testable<>(ise);
|
||||
Throwable e = assertThrows(IllegalStateException.class,
|
||||
() -> Functions.getAsLong(testable::testAsLongPrimitive));
|
||||
assertSame(ise, e);
|
||||
|
||||
final Error error = new OutOfMemoryError();
|
||||
testable.setThrowable(error);
|
||||
e = assertThrows(OutOfMemoryError.class, () -> Functions.getAsLong(testable::testAsLongPrimitive));
|
||||
assertSame(error, e);
|
||||
|
||||
final IOException ioe = new IOException("Unknown I/O error");
|
||||
testable.setThrowable(ioe);
|
||||
e = assertThrows(UncheckedIOException.class, () -> Functions.getAsLong(testable::testAsLongPrimitive));
|
||||
final Throwable t = e.getCause();
|
||||
assertNotNull(t);
|
||||
assertSame(ioe, t);
|
||||
|
||||
testable.setThrowable(null);
|
||||
final long i = Functions.getAsLong(testable::testAsLongPrimitive);
|
||||
assertEquals(0, i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFromSupplier() {
|
||||
FailureOnOddInvocations.invocations = 0;
|
||||
|
@ -911,7 +800,7 @@ public void testThrows_FailableBiConsumer_Object_Throwable() {
|
|||
new Functions.FailableBiConsumer<Object, Object, Throwable>() {
|
||||
|
||||
@Override
|
||||
public void accept(Object object1, Object object2) throws Throwable {
|
||||
public void accept(final Object object1, final Object object2) throws Throwable {
|
||||
throw new IOException("test");
|
||||
}
|
||||
};
|
||||
|
@ -926,7 +815,7 @@ public void testThrows_FailableBiConsumer_String_IOException() {
|
|||
new Functions.FailableBiConsumer<String, String, IOException>() {
|
||||
|
||||
@Override
|
||||
public void accept(String object1, String object2) throws IOException {
|
||||
public void accept(final String object1, final String object2) throws IOException {
|
||||
throw new IOException("test");
|
||||
|
||||
}
|
||||
|
@ -942,7 +831,7 @@ public void testThrows_FailableBiFunction_Object_Throwable() {
|
|||
new Functions.FailableBiFunction<Object, Object, Object, Throwable>() {
|
||||
|
||||
@Override
|
||||
public Object apply(Object input1, Object input2) throws Throwable {
|
||||
public Object apply(final Object input1, final Object input2) throws Throwable {
|
||||
throw new IOException("test");
|
||||
}
|
||||
};
|
||||
|
@ -957,7 +846,7 @@ public void testThrows_FailableBiFunction_String_IOException() {
|
|||
new Functions.FailableBiFunction<String, String, String, IOException>() {
|
||||
|
||||
@Override
|
||||
public String apply(String input1, String input2) throws IOException {
|
||||
public String apply(final String input1, final String input2) throws IOException {
|
||||
throw new IOException("test");
|
||||
}
|
||||
};
|
||||
|
@ -972,7 +861,7 @@ public void testThrows_FailableBiPredicate_Object_Throwable() {
|
|||
new Functions.FailableBiPredicate<Object, Object, Throwable>() {
|
||||
|
||||
@Override
|
||||
public boolean test(Object object1, Object object2) throws Throwable {
|
||||
public boolean test(final Object object1, final Object object2) throws Throwable {
|
||||
throw new IOException("test");
|
||||
}
|
||||
};
|
||||
|
@ -987,7 +876,7 @@ public void testThrows_FailableBiPredicate_String_IOException() {
|
|||
new Functions.FailableBiPredicate<String, String, IOException>() {
|
||||
|
||||
@Override
|
||||
public boolean test(String object1, String object2) throws IOException {
|
||||
public boolean test(final String object1, final String object2) throws IOException {
|
||||
throw new IOException("test");
|
||||
}
|
||||
};
|
||||
|
@ -1032,7 +921,7 @@ public void testThrows_FailableConsumer_Object_Throwable() {
|
|||
new Functions.FailableConsumer<Object, Throwable>() {
|
||||
|
||||
@Override
|
||||
public void accept(Object object) throws Throwable {
|
||||
public void accept(final Object object) throws Throwable {
|
||||
throw new IOException("test");
|
||||
|
||||
}
|
||||
|
@ -1048,7 +937,7 @@ public void testThrows_FailableConsumer_String_IOException() {
|
|||
new Functions.FailableConsumer<String, IOException>() {
|
||||
|
||||
@Override
|
||||
public void accept(String object) throws IOException {
|
||||
public void accept(final String object) throws IOException {
|
||||
throw new IOException("test");
|
||||
|
||||
}
|
||||
|
@ -1064,7 +953,7 @@ public void testThrows_FailableFunction_Object_Throwable() {
|
|||
new Functions.FailableFunction<Object, Object, Throwable>() {
|
||||
|
||||
@Override
|
||||
public Object apply(Object input) throws Throwable {
|
||||
public Object apply(final Object input) throws Throwable {
|
||||
throw new IOException("test");
|
||||
}
|
||||
};
|
||||
|
@ -1079,7 +968,7 @@ public void testThrows_FailableFunction_String_IOException() {
|
|||
new Functions.FailableFunction<String, String, IOException>() {
|
||||
|
||||
@Override
|
||||
public String apply(String input) throws IOException {
|
||||
public String apply(final String input) throws IOException {
|
||||
throw new IOException("test");
|
||||
}
|
||||
};
|
||||
|
@ -1094,7 +983,7 @@ public void testThrows_FailablePredicate_Object_Throwable() {
|
|||
new Functions.FailablePredicate<Object, Throwable>() {
|
||||
|
||||
@Override
|
||||
public boolean test(Object object) throws Throwable {
|
||||
public boolean test(final Object object) throws Throwable {
|
||||
throw new IOException("test");
|
||||
}
|
||||
};
|
||||
|
@ -1109,7 +998,7 @@ public void testThrows_FailablePredicate_String_IOException() {
|
|||
new Functions.FailablePredicate<String, IOException>() {
|
||||
|
||||
@Override
|
||||
public boolean test(String object) throws IOException {
|
||||
public boolean test(final String object) throws IOException {
|
||||
throw new IOException("test");
|
||||
}
|
||||
};
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_0_9;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_10;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_11;
|
||||
|
@ -27,6 +25,7 @@
|
|||
import static org.apache.commons.lang3.JavaVersion.JAVA_13;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_14;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_15;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_16;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_1;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_2;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_3;
|
||||
|
@ -43,6 +42,8 @@
|
|||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.JavaVersion}.
|
||||
*/
|
||||
|
@ -66,10 +67,11 @@ public void testGetJavaVersion() {
|
|||
assertEquals(JAVA_13, get("13"), "13 failed");
|
||||
assertEquals(JAVA_14, get("14"), "14 failed");
|
||||
assertEquals(JAVA_15, get("15"), "15 failed");
|
||||
assertEquals(JAVA_16, get("16"), "16 failed");
|
||||
assertEquals(JAVA_RECENT, get("1.10"), "1.10 failed");
|
||||
// assertNull("2.10 unexpectedly worked", get("2.10"));
|
||||
assertEquals(get("1.5"), getJavaVersion("1.5"), "Wrapper method failed");
|
||||
assertEquals(JAVA_RECENT, get("16"), "Unhandled"); // LANG-1384
|
||||
assertEquals(JAVA_RECENT, get("17"), "Unhandled"); // LANG-1384
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -16,10 +16,11 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.NotImplementedException}.
|
||||
*/
|
||||
|
|
|
@ -361,6 +361,15 @@ public void testToString_ObjectString() {
|
|||
assertEquals(Boolean.TRUE.toString(), ObjectUtils.toString(Boolean.TRUE, BAR) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString_SupplierString() {
|
||||
assertEquals(null, ObjectUtils.toString(null, (Supplier<String>) null));
|
||||
assertEquals(null, ObjectUtils.toString(null, () -> null));
|
||||
// Pretend computing BAR is expensive.
|
||||
assertEquals(BAR, ObjectUtils.toString(null, () -> BAR));
|
||||
assertEquals(Boolean.TRUE.toString(), ObjectUtils.toString(Boolean.TRUE, () -> BAR));
|
||||
}
|
||||
|
||||
@SuppressWarnings("cast") // 1 OK, because we are checking for code change
|
||||
@Test
|
||||
public void testNull() {
|
||||
|
|
|
@ -23,11 +23,11 @@
|
|||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests for {@link RandomUtils}
|
||||
*/
|
||||
|
|
|
@ -232,27 +232,20 @@ public void testContainsAny_StringStringArray() {
|
|||
public void testContainsIgnoreCase_LocaleIndependence() {
|
||||
final Locale[] locales = { Locale.ENGLISH, new Locale("tr"), Locale.getDefault() };
|
||||
|
||||
final String[][] tdata = {
|
||||
{ "i", "I" },
|
||||
{ "I", "i" },
|
||||
{ "\u03C2", "\u03C3" },
|
||||
{ "\u03A3", "\u03C2" },
|
||||
{ "\u03A3", "\u03C3" },
|
||||
};
|
||||
final String[][] tdata = { { "i", "I" }, { "I", "i" }, { "\u03C2", "\u03C3" }, { "\u03A3", "\u03C2" },
|
||||
{ "\u03A3", "\u03C3" }, };
|
||||
|
||||
final String[][] fdata = {
|
||||
{ "\u00DF", "SS" },
|
||||
};
|
||||
final String[][] fdata = { { "\u00DF", "SS" }, };
|
||||
|
||||
for (final Locale testLocale : locales) {
|
||||
Locale.setDefault(testLocale);
|
||||
for (int j = 0; j < tdata.length; j++) {
|
||||
assertTrue(StringUtils.containsIgnoreCase(tdata[j][0], tdata[j][1]),
|
||||
Locale.getDefault() + ": " + j + " " + tdata[j][0] + " " + tdata[j][1]);
|
||||
Locale.getDefault() + ": " + j + " " + tdata[j][0] + " " + tdata[j][1]);
|
||||
}
|
||||
for (int j = 0; j < fdata.length; j++) {
|
||||
assertFalse(StringUtils.containsIgnoreCase(fdata[j][0], fdata[j][1]),
|
||||
Locale.getDefault() + ": " + j + " " + fdata[j][0] + " " + fdata[j][1]);
|
||||
Locale.getDefault() + ": " + j + " " + fdata[j][0] + " " + fdata[j][1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.StringUtils} - StartsWith/EndsWith methods
|
||||
|
|
|
@ -60,11 +60,11 @@ public class StringUtilsTest {
|
|||
static final String NON_TRIMMABLE;
|
||||
|
||||
static {
|
||||
StringBuilder ws = new StringBuilder();
|
||||
StringBuilder nws = new StringBuilder();
|
||||
final StringBuilder ws = new StringBuilder();
|
||||
final StringBuilder nws = new StringBuilder();
|
||||
final String hs = String.valueOf(((char) 160));
|
||||
StringBuilder tr = new StringBuilder();
|
||||
StringBuilder ntr = new StringBuilder();
|
||||
final StringBuilder tr = new StringBuilder();
|
||||
final StringBuilder ntr = new StringBuilder();
|
||||
for (int i = 0; i < Character.MAX_VALUE; i++) {
|
||||
if (Character.isWhitespace((char) i)) {
|
||||
ws.append(String.valueOf((char) i));
|
||||
|
@ -3279,12 +3279,12 @@ public void testToRootLowerCase() {
|
|||
assertEquals("title", "TITLE".toLowerCase(Locale.ROOT));
|
||||
assertEquals("title", StringUtils.toRootLowerCase("TITLE"));
|
||||
// Make sure we are not using the default Locale:
|
||||
final Locale defaultLocales = Locale.getDefault();
|
||||
final Locale defaultLocale = Locale.getDefault();
|
||||
try {
|
||||
Locale.setDefault(TURKISH);
|
||||
assertEquals("title", StringUtils.toRootLowerCase("TITLE"));
|
||||
} finally {
|
||||
Locale.setDefault(defaultLocales);
|
||||
Locale.setDefault(defaultLocale);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3299,36 +3299,36 @@ public void testToRootUpperCase() {
|
|||
assertEquals("TITLE", "title".toUpperCase(Locale.ROOT));
|
||||
assertEquals("TITLE", StringUtils.toRootUpperCase("title"));
|
||||
// Make sure we are not using the default Locale:
|
||||
final Locale defaultLocales = Locale.getDefault();
|
||||
final Locale defaultLocale = Locale.getDefault();
|
||||
try {
|
||||
Locale.setDefault(TURKISH);
|
||||
assertEquals("TITLE", StringUtils.toRootUpperCase("title"));
|
||||
} finally {
|
||||
Locale.setDefault(defaultLocales);
|
||||
Locale.setDefault(defaultLocale);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeorgianSample() {
|
||||
char[] arrayI = new char[]{
|
||||
final char[] arrayI = new char[]{
|
||||
//Latin Small Letter dotless I
|
||||
(char) 0x0131,
|
||||
//Greek Capital Letter Theta
|
||||
(char) 0x03F4
|
||||
};
|
||||
char[] arrayJ = new char[]{
|
||||
final char[] arrayJ = new char[]{
|
||||
//Latin Capital Letter I with dot above
|
||||
(char) 0x0130,
|
||||
//Greek Theta Symbol
|
||||
(char) 0x03D1
|
||||
};
|
||||
for (char i : arrayI) {
|
||||
for (char j : arrayJ) {
|
||||
String si = String.valueOf(i);
|
||||
String sj = String.valueOf(j);
|
||||
boolean res1 = si.equalsIgnoreCase(sj);
|
||||
CharSequence ci = new StringBuilder(si);
|
||||
CharSequence cj = new StringBuilder(sj);
|
||||
for (final char i : arrayI) {
|
||||
for (final char j : arrayJ) {
|
||||
final String si = String.valueOf(i);
|
||||
final String sj = String.valueOf(j);
|
||||
final boolean res1 = si.equalsIgnoreCase(sj);
|
||||
final CharSequence ci = new StringBuilder(si);
|
||||
final CharSequence cj = new StringBuilder(sj);
|
||||
boolean res2 = StringUtils.startsWithIgnoreCase(ci, cj);
|
||||
assertEquals(res1, res2, "si : " + si + " sj : " + sj);
|
||||
res2 = StringUtils.endsWithIgnoreCase(ci, cj);
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_10;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_11;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_12;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_13;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_1;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_2;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_3;
|
||||
|
@ -28,10 +32,6 @@
|
|||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_7;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_8;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_9;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_10;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_11;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_12;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_13;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
|
|
@ -323,7 +323,7 @@ public void testComplexThreadGroups() throws Exception {
|
|||
assertEquals(1, ThreadUtils.findThreadsByName(t4.getName(), threadGroup3.getName()).size());
|
||||
assertEquals(0, ThreadUtils.findThreadsByName(t4.getName(), threadGroup2.getName()).size());
|
||||
assertEquals(2, ThreadUtils.findThreadsByName(t11.getName(), threadGroup7.getName()).size());
|
||||
}finally {
|
||||
} finally {
|
||||
for (final Thread thread : threads) {
|
||||
thread.interrupt();
|
||||
thread.join();
|
||||
|
|
|
@ -18,8 +18,12 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
@ -29,12 +33,8 @@
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.Validate}.
|
||||
|
|
|
@ -20,8 +20,11 @@
|
|||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringStyleTest.Person;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
@ -181,6 +184,73 @@ public void testObject() {
|
|||
.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testList() {
|
||||
final Student student = new Student();
|
||||
final ArrayList<Hobby> objects = new ArrayList<>();
|
||||
|
||||
objects.add(Hobby.BOOK);
|
||||
objects.add(Hobby.SPORT);
|
||||
objects.add(Hobby.MUSIC);
|
||||
|
||||
student.setHobbies(objects);
|
||||
|
||||
assertEquals(student.toString(), "{\"hobbies\":[\"BOOK\",\"SPORT\",\"MUSIC\"]}");
|
||||
student.setHobbies(new ArrayList<>());
|
||||
assertEquals(student.toString(), "{\"hobbies\":[]}");
|
||||
student.setHobbies(null);
|
||||
assertEquals(student.toString(), "{\"hobbies\":null}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayEnum() {
|
||||
final Teacher teacher = new Teacher();
|
||||
final Hobby[] hobbies = new Hobby[3];
|
||||
hobbies[0] = Hobby.BOOK;
|
||||
hobbies[1] = Hobby.SPORT;
|
||||
hobbies[2] = Hobby.MUSIC;
|
||||
|
||||
teacher.setHobbies(hobbies);
|
||||
|
||||
assertEquals(teacher.toString(), "{\"hobbies\":[\"BOOK\",\"SPORT\",\"MUSIC\"]}");
|
||||
teacher.setHobbies(new Hobby[0]);
|
||||
assertEquals(teacher.toString(), "{\"hobbies\":[]}");
|
||||
teacher.setHobbies(null);
|
||||
assertEquals(teacher.toString(), "{\"hobbies\":null}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombineListAndEnum() {
|
||||
final Teacher teacher = new Teacher();
|
||||
|
||||
final Hobby[] teacherHobbies = new Hobby[3];
|
||||
teacherHobbies[0] = Hobby.BOOK;
|
||||
teacherHobbies[1] = Hobby.SPORT;
|
||||
teacherHobbies[2] = Hobby.MUSIC;
|
||||
|
||||
teacher.setHobbies(teacherHobbies);
|
||||
|
||||
final Student john = new Student();
|
||||
john.setHobbies(Arrays.asList(Hobby.BOOK, Hobby.MUSIC));
|
||||
|
||||
final Student alice = new Student();
|
||||
alice.setHobbies(new ArrayList<>());
|
||||
|
||||
final Student bob = new Student();
|
||||
bob.setHobbies(Collections.singletonList(Hobby.BOOK));
|
||||
|
||||
final ArrayList<Student> students = new ArrayList<>();
|
||||
students.add(john);
|
||||
students.add(alice);
|
||||
students.add(bob);
|
||||
|
||||
final AcademyClass academyClass = new AcademyClass();
|
||||
academyClass.setStudents(students);
|
||||
academyClass.setTeacher(teacher);
|
||||
|
||||
assertEquals(academyClass.toString(), "{\"students\":[{\"hobbies\":[\"BOOK\",\"MUSIC\"]},{\"hobbies\":[]},{\"hobbies\":[\"BOOK\"]}],\"teacher\":{\"hobbies\":[\"BOOK\",\"SPORT\",\"MUSIC\"]}}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerson() {
|
||||
final Person p = new Person();
|
||||
|
@ -477,4 +547,73 @@ static class NestingPerson {
|
|||
*/
|
||||
Person person;
|
||||
}
|
||||
|
||||
enum Hobby {
|
||||
SPORT,
|
||||
BOOK,
|
||||
MUSIC
|
||||
}
|
||||
|
||||
enum EmptyEnum {
|
||||
}
|
||||
|
||||
static class Student {
|
||||
List<Hobby> hobbies;
|
||||
|
||||
public List<Hobby> getHobbies() {
|
||||
return hobbies;
|
||||
}
|
||||
|
||||
public void setHobbies(final List<Hobby> hobbies) {
|
||||
this.hobbies = hobbies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this);
|
||||
}
|
||||
}
|
||||
|
||||
static class Teacher {
|
||||
Hobby[] hobbies;
|
||||
|
||||
public Hobby[] getHobbies() {
|
||||
return hobbies;
|
||||
}
|
||||
|
||||
public void setHobbies(final Hobby[] hobbies) {
|
||||
this.hobbies = hobbies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this);
|
||||
}
|
||||
}
|
||||
|
||||
static class AcademyClass {
|
||||
Teacher teacher;
|
||||
List<Student> students;
|
||||
|
||||
public void setTeacher(final Teacher teacher) {
|
||||
this.teacher = teacher;
|
||||
}
|
||||
|
||||
public void setStudents(final List<Student> students) {
|
||||
this.students = students;
|
||||
}
|
||||
|
||||
public Teacher getTeacher() {
|
||||
return teacher;
|
||||
}
|
||||
|
||||
public List<Student> getStudents() {
|
||||
return students;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,15 +16,15 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.builder;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringStyleTest.Person;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.apache.commons.lang3.builder.ToStringStyleTest.Person;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link ToStringStyle#NO_CLASS_NAME_STYLE}.
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
|
||||
package org.apache.commons.lang3.builder;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.builder;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ReflectionToStringBuilderSummaryTest {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.builder;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ReflectionToStringBuilderTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.concurrent;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
@ -32,6 +30,8 @@
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class BackgroundInitializerTest {
|
||||
/**
|
||||
* Helper method for checking whether the initialize() method was correctly
|
||||
|
|
|
@ -16,14 +16,14 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.concurrent;
|
||||
|
||||
import org.apache.commons.lang3.exception.AbstractExceptionTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.apache.commons.lang3.exception.AbstractExceptionTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
/**
|
||||
* JUnit tests for {@link CircuitBreakingException}.
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
|
|
@ -44,7 +44,7 @@ public void testWriteLock() throws Exception {
|
|||
runTest(DELAY, true, l -> assertTrue(l >= NUMBER_OF_THREADS*DELAY));
|
||||
}
|
||||
|
||||
private void runTest(long delay, boolean exclusiveLock, LongConsumer runTimeCheck) throws InterruptedException {
|
||||
private void runTest(final long delay, final boolean exclusiveLock, final LongConsumer runTimeCheck) throws InterruptedException {
|
||||
final boolean[] booleanValues = new boolean[10];
|
||||
final Lock<boolean[]> lock = Locks.lock(booleanValues);
|
||||
final boolean[] runningValues = new boolean[10];
|
||||
|
@ -60,9 +60,9 @@ private void runTest(long delay, boolean exclusiveLock, LongConsumer runTimeChec
|
|||
};
|
||||
final Thread t = new Thread(() -> {
|
||||
if (exclusiveLock) {
|
||||
lock.runWriteLocked(consumer);
|
||||
lock.acceptWriteLocked(consumer);
|
||||
} else {
|
||||
lock.runReadLocked(consumer);
|
||||
lock.acceptReadLocked(consumer);
|
||||
}
|
||||
});
|
||||
modify(runningValues, i, true);
|
||||
|
@ -78,13 +78,13 @@ private void runTest(long delay, boolean exclusiveLock, LongConsumer runTimeChec
|
|||
runTimeCheck.accept(endTime-startTime);
|
||||
}
|
||||
|
||||
protected void modify(boolean[] booleanArray, int offset, boolean value) {
|
||||
protected void modify(final boolean[] booleanArray, final int offset, final boolean value) {
|
||||
synchronized(booleanArray) {
|
||||
booleanArray[offset] = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean someValueIsTrue(boolean[] booleanArray) {
|
||||
protected boolean someValueIsTrue(final boolean[] booleanArray) {
|
||||
synchronized(booleanArray) {
|
||||
for (int i = 0; i < booleanArray.length; i++) {
|
||||
if (booleanArray[i]) {
|
||||
|
|
|
@ -16,15 +16,15 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.concurrent;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class MemoizerTest {
|
||||
|
||||
private Computable<Integer, Integer> computable;
|
||||
|
|
|
@ -16,9 +16,6 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.exception;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
@ -33,6 +30,8 @@
|
|||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.exception;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* JUnit tests for {@link CloneFailedExceptionTest}.
|
||||
*/
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -27,8 +27,8 @@
|
|||
import java.lang.reflect.Modifier;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,14 +17,14 @@
|
|||
|
||||
package org.apache.commons.lang3.mutable;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* JUnit tests.
|
||||
*
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.mutable;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* JUnit tests.
|
||||
*
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.mutable;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* JUnit tests.
|
||||
*
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.mutable;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* JUnit tests.
|
||||
*
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.mutable;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* JUnit tests.
|
||||
*
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.mutable;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* JUnit tests.
|
||||
*
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.mutable;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* JUnit tests.
|
||||
*
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue