/** * Returns a new predicate that negates the result of this predicate. * * @return the predicate, "NOT this" */ public default ObjLongPredicate<T> negate() { return (obj, value) -> !test(obj, value); }
public void test_and() { ObjLongPredicate<String> fn1 = (a, b) -> b > 3; ObjLongPredicate<String> fn2 = (a, b) -> a.length() > 3; ObjLongPredicate<String> and = fn1.and(fn2); assertEquals(fn1.test("a", 2L), false); assertEquals(fn1.test("a", 4L), true); assertEquals(fn2.test("a", 4L), false); assertEquals(fn2.test("abcd", 4L), true); assertEquals(and.test("a", 2L), false); assertEquals(and.test("a", 4L), false); assertEquals(and.test("abcd", 2L), false); assertEquals(and.test("abcd", 4L), true); }
public void test_or() { ObjLongPredicate<String> fn1 = (a, b) -> b > 3; ObjLongPredicate<String> fn2 = (a, b) -> a.length() > 3; ObjLongPredicate<String> or = fn1.or(fn2); assertEquals(fn1.test("a", 2L), false); assertEquals(fn1.test("a", 4L), true); assertEquals(fn2.test("a", 4L), false); assertEquals(fn2.test("abcd", 4L), true); assertEquals(or.test("a", 2L), false); assertEquals(or.test("a", 4L), true); assertEquals(or.test("abcd", 2L), true); assertEquals(or.test("abcd", 4L), true); }
@Test(expectedExceptions = NullPointerException.class) public void test_and_null() { ObjLongPredicate<String> fn1 = (a, b) -> b > 3; fn1.and(null); }
@Test(expectedExceptions = NullPointerException.class) public void test_or_null() { ObjLongPredicate<String> fn1 = (a, b) -> b > 3; fn1.or(null); }
/** * Returns a new predicate that returns true if both predicates return true. * <p> * The second predicate is only invoked if the first returns true. * * @param other the second predicate * @return the combined predicate, "this AND that" * @throws NullPointerException if the other predicate is null */ public default ObjLongPredicate<T> and(ObjLongPredicate<? super T> other) { Objects.requireNonNull(other); return (obj, value) -> test(obj, value) && other.test(obj, value); }
/** * Returns a new predicate that returns true if either predicates returns true. * <p> * The second predicate is only invoked if the first returns false. * * @param other the second predicate * @return the combined predicate, "this OR that" * @throws NullPointerException if the other predicate is null */ public default ObjLongPredicate<T> or(ObjLongPredicate<? super T> other) { Objects.requireNonNull(other); return (obj, value) -> test(obj, value) || other.test(obj, value); }