[LANG-1568] Predicate or.
This commit is contained in:
parent
180d948d7f
commit
268d4936d4
|
@ -84,6 +84,18 @@ public interface FailableBiPredicate<T, U, E extends Throwable> {
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -78,6 +78,18 @@ public interface FailableDoublePredicate<E extends Throwable> {
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -78,6 +78,18 @@ public interface FailableIntPredicate<E extends Throwable> {
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -78,6 +78,18 @@ public interface FailableLongPredicate<E extends Throwable> {
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -81,6 +81,18 @@ public interface FailablePredicate<T, E extends Throwable> {
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -719,8 +719,10 @@ public class FailableFunctionsTest {
|
|||
assertFalse(FailableBiPredicate.FALSE.and(FailableBiPredicate.TRUE).test(null, null));
|
||||
assertFalse(FailableBiPredicate.FALSE.and(FailableBiPredicate.FALSE).test(null, null));
|
||||
// null tests
|
||||
assertThrows(NullPointerException.class, () -> assertFalse(FailableBiPredicate.FALSE.and(null).test(null, null)));
|
||||
assertThrows(NullPointerException.class, () -> assertTrue(FailableBiPredicate.TRUE.and(null).test(null, null)));
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> assertFalse(FailableBiPredicate.falsePredicate().and(null).test(null, null)));
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> assertTrue(FailableBiPredicate.truePredicate().and(null).test(null, null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -731,6 +733,19 @@ public class FailableFunctionsTest {
|
|||
assertTrue(FailableBiPredicate.falsePredicate().negate().test(null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBiPredicateOr() throws Throwable {
|
||||
assertTrue(FailableBiPredicate.TRUE.or(FailableBiPredicate.TRUE).test(null, null));
|
||||
assertTrue(FailableBiPredicate.TRUE.or(FailableBiPredicate.FALSE).test(null, null));
|
||||
assertTrue(FailableBiPredicate.FALSE.or(FailableBiPredicate.TRUE).test(null, null));
|
||||
assertFalse(FailableBiPredicate.FALSE.or(FailableBiPredicate.FALSE).test(null, null));
|
||||
// null tests
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> assertFalse(FailableBiPredicate.falsePredicate().or(null).test(null, null)));
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> assertTrue(FailableBiPredicate.truePredicate().or(null).test(null, null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCallable() {
|
||||
FailureOnOddInvocations.invocations = 0;
|
||||
|
@ -793,8 +808,10 @@ public class FailableFunctionsTest {
|
|||
assertFalse(FailableDoublePredicate.FALSE.and(FailableDoublePredicate.TRUE).test(0));
|
||||
assertFalse(FailableDoublePredicate.FALSE.and(FailableDoublePredicate.FALSE).test(0));
|
||||
// null tests
|
||||
assertThrows(NullPointerException.class, () -> assertFalse(FailableDoublePredicate.FALSE.and(null).test(0)));
|
||||
assertThrows(NullPointerException.class, () -> assertTrue(FailableDoublePredicate.TRUE.and(null).test(0)));
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> assertFalse(FailableDoublePredicate.falsePredicate().and(null).test(0)));
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> assertTrue(FailableDoublePredicate.truePredicate().and(null).test(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -805,6 +822,19 @@ public class FailableFunctionsTest {
|
|||
assertTrue(FailableDoublePredicate.falsePredicate().negate().test(0d));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoublePredicateOr() throws Throwable {
|
||||
assertTrue(FailableDoublePredicate.TRUE.or(FailableDoublePredicate.TRUE).test(0));
|
||||
assertTrue(FailableDoublePredicate.TRUE.or(FailableDoublePredicate.FALSE).test(0));
|
||||
assertTrue(FailableDoublePredicate.FALSE.or(FailableDoublePredicate.TRUE).test(0));
|
||||
assertFalse(FailableDoublePredicate.FALSE.or(FailableDoublePredicate.FALSE).test(0));
|
||||
// null tests
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> assertFalse(FailableDoublePredicate.falsePredicate().or(null).test(0)));
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> assertTrue(FailableDoublePredicate.truePredicate().or(null).test(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleUnaryOperatorAndThen() throws Throwable {
|
||||
final Testable<?, ?> testable = new Testable<>(null);
|
||||
|
@ -1083,8 +1113,10 @@ public class FailableFunctionsTest {
|
|||
assertFalse(FailableIntPredicate.FALSE.and(FailableIntPredicate.TRUE).test(0));
|
||||
assertFalse(FailableIntPredicate.FALSE.and(FailableIntPredicate.FALSE).test(0));
|
||||
// null tests
|
||||
assertThrows(NullPointerException.class, () -> assertFalse(FailableIntPredicate.FALSE.and(null).test(0)));
|
||||
assertThrows(NullPointerException.class, () -> assertTrue(FailableIntPredicate.TRUE.and(null).test(0)));
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> assertFalse(FailableIntPredicate.falsePredicate().and(null).test(0)));
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> assertTrue(FailableIntPredicate.truePredicate().and(null).test(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1095,6 +1127,19 @@ public class FailableFunctionsTest {
|
|||
assertTrue(FailableIntPredicate.falsePredicate().negate().test(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntPredicateOr() throws Throwable {
|
||||
assertTrue(FailableIntPredicate.TRUE.or(FailableIntPredicate.TRUE).test(0));
|
||||
assertTrue(FailableIntPredicate.TRUE.or(FailableIntPredicate.FALSE).test(0));
|
||||
assertTrue(FailableIntPredicate.FALSE.or(FailableIntPredicate.TRUE).test(0));
|
||||
assertFalse(FailableIntPredicate.FALSE.or(FailableIntPredicate.FALSE).test(0));
|
||||
// null tests
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> assertFalse(FailableIntPredicate.falsePredicate().or(null).test(0)));
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> assertTrue(FailableIntPredicate.truePredicate().or(null).test(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntUnaryOperatorAndThen() throws Throwable {
|
||||
final Testable<?, ?> testable = new Testable<>(null);
|
||||
|
@ -1175,8 +1220,8 @@ public class FailableFunctionsTest {
|
|||
assertFalse(FailableLongPredicate.FALSE.and(FailableLongPredicate.TRUE).test(0));
|
||||
assertFalse(FailableLongPredicate.FALSE.and(FailableLongPredicate.FALSE).test(0));
|
||||
// null tests
|
||||
assertThrows(NullPointerException.class, () -> assertFalse(FailableLongPredicate.FALSE.and(null).test(0)));
|
||||
assertThrows(NullPointerException.class, () -> assertTrue(FailableLongPredicate.TRUE.and(null).test(0)));
|
||||
assertThrows(NullPointerException.class, () -> assertFalse(FailableLongPredicate.falsePredicate().and(null).test(0)));
|
||||
assertThrows(NullPointerException.class, () -> assertTrue(FailableLongPredicate.truePredicate().and(null).test(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1187,6 +1232,17 @@ public class FailableFunctionsTest {
|
|||
assertTrue(FailableLongPredicate.falsePredicate().negate().test(0L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongPredicateOr() throws Throwable {
|
||||
assertTrue(FailableLongPredicate.TRUE.or(FailableLongPredicate.TRUE).test(0));
|
||||
assertTrue(FailableLongPredicate.TRUE.or(FailableLongPredicate.FALSE).test(0));
|
||||
assertTrue(FailableLongPredicate.FALSE.or(FailableLongPredicate.TRUE).test(0));
|
||||
assertFalse(FailableLongPredicate.FALSE.or(FailableLongPredicate.FALSE).test(0));
|
||||
// null tests
|
||||
assertThrows(NullPointerException.class, () -> assertFalse(FailableLongPredicate.falsePredicate().or(null).test(0)));
|
||||
assertThrows(NullPointerException.class, () -> assertTrue(FailableLongPredicate.truePredicate().or(null).test(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongUnaryOperatorAndThen() throws Throwable {
|
||||
final Testable<?, ?> testable = new Testable<>(null);
|
||||
|
|
Loading…
Reference in New Issue