WeakLogic { public static <T> BinaryOperator<T> weakBinaryOperator(BinaryOperator<T> op) { return (T x, T y) -> { if ((x == null) && (y != null)) { return y; } else if (x == null) { return null; } else if (y == null) { return x; } else { return op.apply(x, y); } }; } private  WeakLogic(); static Comparator<T> weakComparator(Comparator<? super T> comparator); static Comparator<T> weakComparator(); static BinaryOperator<T> weakBinaryOperator(BinaryOperator<T> op); static UnaryOperator<T> weakUnaryOperator(UnaryOperator<T> op); static Function<F, T> weakFunction(Function<F, T> f); static boolean weakEquals(T x, T y);  }
@Test public void testWeakBinaryOperator() { BinaryOperator<Integer> weakAdd = weakBinaryOperator((Integer a, Integer b) -> a + b); Integer sum; sum = weakAdd.apply(null, null); assertNull(sum); sum = weakAdd.apply(7, null); assertEquals(Integer.valueOf(7), sum); sum = weakAdd.apply(null, 8); assertEquals(Integer.valueOf(8), sum); sum = weakAdd.apply(7, 8); assertEquals(Integer.valueOf(15), sum); }