This commit is contained in:
Gary Gregory 2020-03-29 17:30:29 -04:00
parent 8c1153d371
commit 36c4cc67a1
6 changed files with 34 additions and 36 deletions

View File

@ -3663,7 +3663,7 @@ public static boolean isSorted(final short[] array) {
* @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);
}
/**

View File

@ -445,7 +445,7 @@ public ArrayCollector(final Class<O> elementType) {
@Override
public Supplier<List<O>> supplier() {
return () -> new ArrayList<>();
return ArrayList::new;
}
@Override
@ -465,7 +465,7 @@ public BinaryOperator<List<O>> combiner() {
@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);

View File

@ -152,7 +152,7 @@ void testRunnable() {
@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 @@ void testCallable() {
@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 @@ void testAcceptConsumer() {
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 @@ public void testApplyFunction() {
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 @@ public void testGetFromSupplier() {
@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 @@ public void testAsBiPredicate() {
@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();

View File

@ -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 @@ void testSimpleStreamMap() {
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 @@ void testSimpleStreamMapFailing() {
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 @@ void testToArray() {
}
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 @@ void testSimpleStreamForEachFailing() {
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 @@ private void assertEvenNumbers(final List<Integer> output) {
}
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 @@ protected <T extends Throwable> FailablePredicate<Integer, T> asIntPredicate(fin
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 @@ void testSimpleStreamFilterFailing() {
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 @@ void testSimpleStreamFilterFailing() {
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 @@ void testSimpleStreamFilterFailing() {
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");

View File

@ -62,7 +62,7 @@ public void testEnforceExceptions() {
assertThrows(
IllegalArgumentException.class,
() -> IEEE754rUtils.min(),
IEEE754rUtils::min,
"IllegalArgumentException expected for empty input");
assertThrows(
@ -82,7 +82,7 @@ public void testEnforceExceptions() {
assertThrows(
IllegalArgumentException.class,
() -> IEEE754rUtils.min(),
IEEE754rUtils::min,
"IllegalArgumentException expected for empty input");
assertThrows(
@ -92,7 +92,7 @@ public void testEnforceExceptions() {
assertThrows(
IllegalArgumentException.class,
() -> IEEE754rUtils.max(),
IEEE754rUtils::max,
"IllegalArgumentException expected for empty input");
}

View File

@ -691,7 +691,7 @@ public void testMinLong_nullArray() {
@Test
public void testMinLong_emptyArray() {
assertThrows(IllegalArgumentException.class, () -> NumberUtils.min());
assertThrows(IllegalArgumentException.class, NumberUtils::min);
}
@Test
@ -710,7 +710,7 @@ public void testMinInt_nullArray() {
@Test
public void testMinInt_emptyArray() {
assertThrows(IllegalArgumentException.class, () -> NumberUtils.min());
assertThrows(IllegalArgumentException.class, NumberUtils::min);
}
@Test
@ -729,7 +729,7 @@ public void testMinShort_nullArray() {
@Test
public void testMinShort_emptyArray() {
assertThrows(IllegalArgumentException.class, () -> NumberUtils.min());
assertThrows(IllegalArgumentException.class, NumberUtils::min);
}
@Test
@ -767,7 +767,7 @@ public void testMinDouble_nullArray() {
@Test
public void testMinDouble_emptyArray() {
assertThrows(IllegalArgumentException.class, () -> NumberUtils.min());
assertThrows(IllegalArgumentException.class, NumberUtils::min);
}
@Test
@ -786,7 +786,7 @@ public void testMinFloat_nullArray() {
@Test
public void testMinFloat_emptyArray() {
assertThrows(IllegalArgumentException.class, () -> NumberUtils.min());
assertThrows(IllegalArgumentException.class, NumberUtils::min);
}
@Test
@ -805,7 +805,7 @@ public void testMaxLong_nullArray() {
@Test
public void testMaxLong_emptyArray() {
assertThrows(IllegalArgumentException.class, () -> NumberUtils.max());
assertThrows(IllegalArgumentException.class, NumberUtils::max);
}
@Test
@ -824,7 +824,7 @@ public void testMaxInt_nullArray() {
@Test
public void testMaxInt_emptyArray() {
assertThrows(IllegalArgumentException.class, () -> NumberUtils.max());
assertThrows(IllegalArgumentException.class, NumberUtils::max);
}
@Test
@ -843,7 +843,7 @@ public void testMaxShort_nullArray() {
@Test
public void testMaxShort_emptyArray() {
assertThrows(IllegalArgumentException.class, () -> NumberUtils.max());
assertThrows(IllegalArgumentException.class, NumberUtils::max);
}
@Test
@ -881,7 +881,7 @@ public void testMaxDouble_nullArray() {
@Test
public void testMaxDouble_emptyArray() {
assertThrows(IllegalArgumentException.class, () -> NumberUtils.max());
assertThrows(IllegalArgumentException.class, NumberUtils::max);
}
@Test
@ -892,7 +892,7 @@ public void testMaxDouble() {
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 void testMaxFloat_nullArray() {
@Test
public void testMaxFloat_emptyArray() {
assertThrows(IllegalArgumentException.class, () -> NumberUtils.max());
assertThrows(IllegalArgumentException.class, NumberUtils::max);
}
@Test