Lambdas.
This commit is contained in:
parent
8c1153d371
commit
36c4cc67a1
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue