This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push: new 36c4cc6 Lambdas. 36c4cc6 is described below commit 36c4cc67a17b51256096f0a33427071b3cc1194e Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sun Mar 29 17:30:29 2020 -0400 Lambdas. --- .../java/org/apache/commons/lang3/ArrayUtils.java | 2 +- .../java/org/apache/commons/lang3/Streams.java | 4 ++-- .../org/apache/commons/lang3/FunctionsTest.java | 14 ++++++-------- .../java/org/apache/commons/lang3/StreamsTest.java | 22 +++++++++++----------- .../commons/lang3/math/IEEE754rUtilsTest.java | 6 +++--- .../apache/commons/lang3/math/NumberUtilsTest.java | 22 +++++++++++----------- 6 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java index 7f369fa..010d8c1 100644 --- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java +++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java @@ -3663,7 +3663,7 @@ public static int indexOf(final int[] array, final int valueToFind) { * @since 3.4 */ public static <T extends Comparable<? super T>> boolean isSorted(final T[] array) { - return isSorted(array, (o1, o2) -> o1.compareTo(o2)); + return isSorted(array, Comparable::compareTo); } /** diff --git a/src/main/java/org/apache/commons/lang3/Streams.java b/src/main/java/org/apache/commons/lang3/Streams.java index b5e7d43..337a0fd 100644 --- a/src/main/java/org/apache/commons/lang3/Streams.java +++ b/src/main/java/org/apache/commons/lang3/Streams.java @@ -445,7 +445,7 @@ public class Streams { @Override public Supplier<List<O>> supplier() { - return () -> new ArrayList<>(); + return ArrayList::new; } @Override @@ -465,7 +465,7 @@ public class Streams { @Override public Function<List<O>, O[]> finisher() { - return (list) -> { + return list -> { @SuppressWarnings("unchecked") final O[] array = (O[]) Array.newInstance(elementType, list.size()); return list.toArray(array); diff --git a/src/test/java/org/apache/commons/lang3/FunctionsTest.java b/src/test/java/org/apache/commons/lang3/FunctionsTest.java index bec8a44..50c3e18 100644 --- a/src/test/java/org/apache/commons/lang3/FunctionsTest.java +++ b/src/test/java/org/apache/commons/lang3/FunctionsTest.java @@ -152,7 +152,7 @@ class FunctionsTest { @Test void testAsRunnable() { FailureOnOddInvocations.invocation = 0; - final Runnable runnable = Functions.asRunnable(() -> new FailureOnOddInvocations()); + final Runnable runnable = Functions.asRunnable(FailureOnOddInvocations::new); final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> runnable.run()); final Throwable cause = e.getCause(); assertNotNull(cause); @@ -178,9 +178,7 @@ class FunctionsTest { @Test void testAsCallable() { FailureOnOddInvocations.invocation = 0; - final FailableCallable<FailureOnOddInvocations, SomeException> failableCallable = () -> { - return new FailureOnOddInvocations(); - }; + final FailableCallable<FailureOnOddInvocations, SomeException> failableCallable = () -> new FailureOnOddInvocations(); final Callable<FailureOnOddInvocations> callable = Functions.asCallable(failableCallable); final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> callable.call()); final Throwable cause = e.getCause(); @@ -223,7 +221,7 @@ class FunctionsTest { void testAsConsumer() { final IllegalStateException ise = new IllegalStateException(); final Testable testable = new Testable(ise); - final Consumer<Testable> consumer = Functions.asConsumer((t) -> t.test()); + final Consumer<Testable> consumer = Functions.asConsumer(t -> t.test()); Throwable e = assertThrows(IllegalStateException.class, () -> consumer.accept(testable)); assertSame(ise, e); @@ -319,7 +317,7 @@ class FunctionsTest { public void testAsFunction() { final IllegalStateException ise = new IllegalStateException(); final Testable testable = new Testable(ise); - final FailableFunction<Throwable, Integer, Throwable> failableFunction = (th) -> { + final FailableFunction<Throwable, Integer, Throwable> failableFunction = th -> { testable.setThrowable(th); return Integer.valueOf(testable.testInt()); }; @@ -407,7 +405,7 @@ class FunctionsTest { @DisplayName("Test that asPredicate(FailablePredicate) is converted to -> Predicate ") public void testAsPredicate() { FailureOnOddInvocations.invocation = 0; - final Functions.FailablePredicate<Object, Throwable> failablePredicate = (t) -> FailureOnOddInvocations.failingBool(); + final Functions.FailablePredicate<Object, Throwable> failablePredicate = t -> FailureOnOddInvocations.failingBool(); final Predicate<?> predicate = Functions.asPredicate(failablePredicate); final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> predicate.test(null)); final Throwable cause = e.getCause(); @@ -436,7 +434,7 @@ class FunctionsTest { @Test public void testAsSupplier() { FailureOnOddInvocations.invocation = 0; - final FailableSupplier<FailureOnOddInvocations, Throwable> failableSupplier = () -> new FailureOnOddInvocations(); + final FailableSupplier<FailureOnOddInvocations, Throwable> failableSupplier = FailureOnOddInvocations::new; final Supplier<FailureOnOddInvocations> supplier = Functions.asSupplier(failableSupplier); final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> supplier.get()); final Throwable cause = e.getCause(); diff --git a/src/test/java/org/apache/commons/lang3/StreamsTest.java b/src/test/java/org/apache/commons/lang3/StreamsTest.java index 48f7818..0f618b6 100644 --- a/src/test/java/org/apache/commons/lang3/StreamsTest.java +++ b/src/test/java/org/apache/commons/lang3/StreamsTest.java @@ -36,7 +36,7 @@ class StreamsTest { @Test void testSimpleStreamMap() { final List<String> input = Arrays.asList("1", "2", "3", "4", "5", "6"); - final List<Integer> output = Functions.stream(input).map((s) -> Integer.valueOf(s)).collect(Collectors.toList()); + final List<Integer> output = Functions.stream(input).map(s -> Integer.valueOf(s)).collect(Collectors.toList()); assertEquals(6, output.size()); for (int i = 0; i < 6; i++) { assertEquals(i+1, output.get(i).intValue()); @@ -47,7 +47,7 @@ class StreamsTest { void testSimpleStreamMapFailing() { final List<String> input = Arrays.asList("1", "2", "3", "4 ", "5", "6"); try { - Functions.stream(input).map((s) -> Integer.valueOf(s)).collect(Collectors.toList()); + Functions.stream(input).map(s -> Integer.valueOf(s)).collect(Collectors.toList()); fail("Expected Exception"); } catch (final NumberFormatException nfe) { assertEquals("For input string: \"4 \"", nfe.getMessage()); @@ -58,7 +58,7 @@ class StreamsTest { void testSimpleStreamForEach() { final List<String> input = Arrays.asList("1", "2", "3", "4", "5", "6"); final List<Integer> output = new ArrayList<>(); - Functions.stream(input).forEach((s) -> output.add(Integer.valueOf(s))); + Functions.stream(input).forEach(s -> output.add(Integer.valueOf(s))); assertEquals(6, output.size()); for (int i = 0; i < 6; i++) { assertEquals(i+1, output.get(i).intValue()); @@ -76,7 +76,7 @@ class StreamsTest { } protected <T extends Throwable> FailableConsumer<String, T> asIntConsumer(final T pThrowable) { - return (s) -> { + return s -> { final Integer i = Integer.valueOf(s); if (i.intValue() == 4) { throw pThrowable; @@ -117,8 +117,8 @@ class StreamsTest { void testSimpleStreamFilter() { final List<String> input = Arrays.asList("1", "2", "3", "4", "5", "6"); final List<Integer> output = Functions.stream(input) - .map((s) -> Integer.valueOf(s)) - .filter((i) -> { + .map(s -> Integer.valueOf(s)) + .filter(i -> { return i.intValue() %2 == 0; }) .collect(Collectors.toList()); @@ -133,7 +133,7 @@ class StreamsTest { } protected <T extends Throwable> FailablePredicate<Integer, T> asIntPredicate(final T pThrowable) { - return (i) -> { + return i -> { if (i.intValue() == 5) { if (pThrowable != null) { throw pThrowable; @@ -147,7 +147,7 @@ class StreamsTest { void testSimpleStreamFilterFailing() { final List<String> input = Arrays.asList("1", "2", "3", "4", "5", "6"); final List<Integer> output = Functions.stream(input) - .map((s) -> Integer.valueOf(s)) + .map(s -> Integer.valueOf(s)) .filter(asIntPredicate(null)) .collect(Collectors.toList()); assertEvenNumbers(output); @@ -156,7 +156,7 @@ class StreamsTest { final IllegalArgumentException iae = new IllegalArgumentException("Invalid argument: " + 5); try { Functions.stream(input) - .map((s) -> Integer.valueOf(s)) + .map(s -> Integer.valueOf(s)) .filter(asIntPredicate(iae)) .collect(Collectors.toList()); fail("Expected Exception"); @@ -168,7 +168,7 @@ class StreamsTest { final OutOfMemoryError oome = new OutOfMemoryError(); try { Functions.stream(input) - .map((s) -> Integer.valueOf(s)) + .map(s -> Integer.valueOf(s)) .filter(asIntPredicate(oome)) .collect(Collectors.toList()); fail("Expected Exception"); @@ -180,7 +180,7 @@ class StreamsTest { final SAXException se = new SAXException(); try { Functions.stream(input) - .map((s) -> Integer.valueOf(s)) + .map(s -> Integer.valueOf(s)) .filter(asIntPredicate(se)) .collect(Collectors.toList()); fail("Expected Exception"); diff --git a/src/test/java/org/apache/commons/lang3/math/IEEE754rUtilsTest.java b/src/test/java/org/apache/commons/lang3/math/IEEE754rUtilsTest.java index 39fe5cd..8312f03 100644 --- a/src/test/java/org/apache/commons/lang3/math/IEEE754rUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/math/IEEE754rUtilsTest.java @@ -62,7 +62,7 @@ public class IEEE754rUtilsTest { assertThrows( IllegalArgumentException.class, - () -> IEEE754rUtils.min(), + IEEE754rUtils::min, "IllegalArgumentException expected for empty input"); assertThrows( @@ -82,7 +82,7 @@ public class IEEE754rUtilsTest { assertThrows( IllegalArgumentException.class, - () -> IEEE754rUtils.min(), + IEEE754rUtils::min, "IllegalArgumentException expected for empty input"); assertThrows( @@ -92,7 +92,7 @@ public class IEEE754rUtilsTest { assertThrows( IllegalArgumentException.class, - () -> IEEE754rUtils.max(), + IEEE754rUtils::max, "IllegalArgumentException expected for empty input"); } diff --git a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java index 3e32c90..922120b 100644 --- a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java @@ -691,7 +691,7 @@ public class NumberUtilsTest { @Test public void testMinLong_emptyArray() { - assertThrows(IllegalArgumentException.class, () -> NumberUtils.min()); + assertThrows(IllegalArgumentException.class, NumberUtils::min); } @Test @@ -710,7 +710,7 @@ public class NumberUtilsTest { @Test public void testMinInt_emptyArray() { - assertThrows(IllegalArgumentException.class, () -> NumberUtils.min()); + assertThrows(IllegalArgumentException.class, NumberUtils::min); } @Test @@ -729,7 +729,7 @@ public class NumberUtilsTest { @Test public void testMinShort_emptyArray() { - assertThrows(IllegalArgumentException.class, () -> NumberUtils.min()); + assertThrows(IllegalArgumentException.class, NumberUtils::min); } @Test @@ -767,7 +767,7 @@ public class NumberUtilsTest { @Test public void testMinDouble_emptyArray() { - assertThrows(IllegalArgumentException.class, () -> NumberUtils.min()); + assertThrows(IllegalArgumentException.class, NumberUtils::min); } @Test @@ -786,7 +786,7 @@ public class NumberUtilsTest { @Test public void testMinFloat_emptyArray() { - assertThrows(IllegalArgumentException.class, () -> NumberUtils.min()); + assertThrows(IllegalArgumentException.class, NumberUtils::min); } @Test @@ -805,7 +805,7 @@ public class NumberUtilsTest { @Test public void testMaxLong_emptyArray() { - assertThrows(IllegalArgumentException.class, () -> NumberUtils.max()); + assertThrows(IllegalArgumentException.class, NumberUtils::max); } @Test @@ -824,7 +824,7 @@ public class NumberUtilsTest { @Test public void testMaxInt_emptyArray() { - assertThrows(IllegalArgumentException.class, () -> NumberUtils.max()); + assertThrows(IllegalArgumentException.class, NumberUtils::max); } @Test @@ -843,7 +843,7 @@ public class NumberUtilsTest { @Test public void testMaxShort_emptyArray() { - assertThrows(IllegalArgumentException.class, () -> NumberUtils.max()); + assertThrows(IllegalArgumentException.class, NumberUtils::max); } @Test @@ -881,7 +881,7 @@ public class NumberUtilsTest { @Test public void testMaxDouble_emptyArray() { - assertThrows(IllegalArgumentException.class, () -> NumberUtils.max()); + assertThrows(IllegalArgumentException.class, NumberUtils::max); } @Test @@ -892,7 +892,7 @@ public class NumberUtilsTest { assertThrows( IllegalArgumentException.class, - () -> NumberUtils.max(), + NumberUtils::max, "No exception was thrown for empty input."); assertEquals(5.1f, NumberUtils.max(5.1f), "max(double[]) failed for array length 1"); @@ -909,7 +909,7 @@ public class NumberUtilsTest { @Test public void testMaxFloat_emptyArray() { - assertThrows(IllegalArgumentException.class, () -> NumberUtils.max()); + assertThrows(IllegalArgumentException.class, NumberUtils::max); } @Test