changeset 7787:62d2a1511961

Add missing NPE declarations. Remove low weight Functions and Predicates methods. Javadoc cleanups
author mduigou
date Mon, 01 Apr 2013 13:45:28 -0700
parents 34443a93970a
children 1b67c524ecb9
files src/share/classes/java/util/function/Function.java src/share/classes/java/util/function/Functions.java src/share/classes/java/util/function/Predicate.java src/share/classes/java/util/function/Predicates.java test/java/util/function/FunctionsTest.java test/java/util/function/PredicateTest.java test/java/util/function/PredicatesTest.java test/java/util/stream/Stream/EmployeeStreamTest.java test/java/util/stream/Stream/IntegerStreamTest.java test/java/util/stream/Stream/StringBuilderStreamTest.java
diffstat 10 files changed, 66 insertions(+), 622 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/function/Function.java	Mon Apr 01 13:41:33 2013 -0700
+++ b/src/share/classes/java/util/function/Function.java	Mon Apr 01 13:45:28 2013 -0700
@@ -48,17 +48,36 @@
     public R apply(T t);
 
     /**
-     * Compose a new function from a provided function and this function.
+     * Compose a new function which applies the provided function before this
+     * function.
      *
      * @param <V> Type of input objects to the combined function. May be the
-     * same type as {@code <T>}.
-     * @param inner An additional function to be applied before this function is
-     * applied.
+     * same type as {@code <T>} or {@code <R>}
+     * @param before An additional function to be applied before this function is
+     * applied
      * @return A function which performs the provided function followed by this
-     * function.
+     * function
+     * @throws NullPointerException if inner is null
      */
-    public default <V > Function<V, R> compose(Function<? super V, ? extends T> inner) {
-        Objects.requireNonNull(inner);
-        return (V v) -> apply(inner.apply(v));
+    public default <V > Function<V, R> compose(Function<? super V, ? extends T> before) {
+        Objects.requireNonNull(before);
+        return (V v) -> apply(before.apply(v));
+    }
+
+    /**
+     * Compose a new function which applies this function followed by the
+     * provided function.
+     *
+     * @param <V> Type of output objects to the combined function. May be the
+     * same type as {@code <T>} or {@code <R>}
+     * @param after An additional function to be applied before this function is
+     * applied
+     * @return A function which performs the provided function followed by this
+     * function
+     * @throws NullPointerException if after is null
+     */
+    public default <V > Function<T, V> andThen(Function<? super R, ? extends V> after) {
+        Objects.requireNonNull(after);
+        return (T t) -> after.apply(apply(t));
     }
 }
--- a/src/share/classes/java/util/function/Functions.java	Mon Apr 01 13:41:33 2013 -0700
+++ b/src/share/classes/java/util/function/Functions.java	Mon Apr 01 13:45:28 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,8 +24,6 @@
  */
 package java.util.function;
 
-import java.lang.reflect.Constructor;
-import java.lang.reflect.UndeclaredThrowableException;
 import java.util.Map;
 import java.util.Objects;
 
@@ -53,41 +51,6 @@
         return t -> t;
     }
 
-//    /**
-//     * Returns a function which whose {@code apply} method returns a clone of the
-//     * provided input.
-//     */
-//    public static <T> Function<T, T> cloneOf() {
-//        return t -> {
-//            try {
-//                return t.clone();
-//            } catch (CloneNotSupportedException ex) {
-//                throw new UndeclaredThrowableException(ex);
-//            }
-//        };
-//    }
-//
-    /**
-     * Returns a function which performs the first function followed by the
-     * second function.
-     *
-     * @param <T> Type for inputs to the first function.
-     * @param <U> Type for results from first function and inputs to the second
-     * function. May be the same type as {@code <T>}.
-     * @param <R> Type for results from the second function. May be the same
-     * type as * {@code <U>}.
-     * @param first Initial function from {@code <T>} to {@code <U>}.
-     * @param second additional function from {@code <U>} to {@code <R>}.
-     */
-    public static <T, U, R> Function<T, R> chain(
-            Function<? super T, ? extends U> first,
-            Function<? super U, ? extends R> second) {
-        Objects.requireNonNull(first);
-        Objects.requireNonNull(second);
-
-        return t -> second.apply(first.apply(t));
-    }
-
     /**
      * Returns a constant output regardless of input.
      *
@@ -113,46 +76,11 @@
     }
 
     /**
-     * Returns a new instance of {@code <R>} constructed with provided
-     * {@code <T>}.
-     *
-     * @param <R> Type of output values from mapping
-     * @param <T> Type of input values to mapping
-     * @param clazzT The {@code Class} which defines objects of type {@code <T>}
-     * @param clazzR The {@code Class} which defines objects of type {@code <U>}
-     * @return a function which creates instances of {@code <R>} using {@code <T>}
-     * as the constructor parameter.
-     * @throws NoSuchMethodException when {@code <R>} has no constructor which
-     * takes a {@code <T>} as a parameter.
-     */
-    public static <T, R> Function<T, R> instantiate(Class<? extends T> clazzT, Class<? extends R> clazzR) {
-        Objects.requireNonNull(clazzT);
-        Objects.requireNonNull(clazzR);
-
-        final Constructor<? extends R> constructor;
-        try {
-            constructor = clazzR.getConstructor(clazzT);
-        } catch(NoSuchMethodException noConstructor) {
-            throw new IllegalArgumentException("no constructor for "+ clazzR.getSimpleName() + "(" + clazzT.getSimpleName() + ")", noConstructor);
-        }
-
-        return t -> {
-            try {
-                return constructor.newInstance(t);
-            } catch (ReflectiveOperationException ex) {
-                // XXX mduigou argument for exception transparency?
-                throw new UndeclaredThrowableException(ex);
-            }
-        };
-    }
-
-    /**
      * Returns a function which maps inputs according to the provided mapping.
      * Attempting to apply a value not from the given map will cause an
      * {@code IllegalArgumentException} to be thrown. A copy is
      * <strong>not</strong> made of the map. Care should be taken to avoid
-     * changes to the map during operation may produce results which violate
-     * the {@code apply} method contract.
+     * changes to the map during use of the function.
      *
      * @param <R> output type from mapping operation
      * @param <T> input type to mapping operation
@@ -176,9 +104,7 @@
     /**
      * Returns a function which maps inputs according to the provided mapping.
      * The provided default value is returned for all {@code <T>} keys not found
-     * in the map. A copy is <strong>not</strong> made of the apply and care
-     * should be taken to avoid changes to the apply during operation may
-     * produce results which violate the {@code apply} method contract.
+     * in the map. A copy is <strong>not</strong> made of the map.
      *
      * @param <T> input type to mapping function
      * @param <R> output type from mapping function
--- a/src/share/classes/java/util/function/Predicate.java	Mon Apr 01 13:41:33 2013 -0700
+++ b/src/share/classes/java/util/function/Predicate.java	Mon Apr 01 13:45:28 2013 -0700
@@ -54,6 +54,7 @@
      * @param p a predicate which will be logically-ANDed with this predicate.
      * @return a new predicate which returns {@code true} only if both
      * predicates return {@code true}.
+     * @throws NullPointerException if p is null
      */
     public default Predicate<T> and(Predicate<? super T> p) {
         Objects.requireNonNull(p);
@@ -79,6 +80,7 @@
      * @param p a predicate which will be logically-ORed with this predicate.
      * @return a new predicate which returns {@code true} if either predicate
      * returns {@code true}.
+     * @throws NullPointerException if p is null
      */
     public default Predicate<T> or(Predicate<? super T> p) {
         Objects.requireNonNull(p);
@@ -89,9 +91,10 @@
      * Returns a predicate that evaluates to {@code true} if both or neither of
      * the component predicates evaluate to {@code true}.
      *
-     * @param p a predicate which will be logically-XORed with this predicte.
+     * @param p a predicate which will be logically-XORed with this predicate
      * @return a predicate that evaluates to {@code true} if both or neither of
-     * the component predicates evaluate to {@code true}.
+     * the component predicates evaluate to {@code true}
+     * @throws NullPointerException if p is null
      */
     public default Predicate<T> xor(Predicate<? super T> p) {
         Objects.requireNonNull(p);
--- a/src/share/classes/java/util/function/Predicates.java	Mon Apr 01 13:41:33 2013 -0700
+++ b/src/share/classes/java/util/function/Predicates.java	Mon Apr 01 13:45:28 2013 -0700
@@ -24,9 +24,6 @@
  */
 package java.util.function;
 
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
 import java.util.Objects;
 
 /**
@@ -44,17 +41,6 @@
     }
 
     /**
-     * Returns a predicate that who's result is {@code target == object}.
-     *
-     * @param <T> the type of values evaluated by the predicate.
-     * @param target The target value to be compared for identity equality.
-     * @return a predicate that who's result is {@code target == object}.
-     */
-    public static <T> Predicate<T> isSame(Object target) {
-        return obj -> obj == target;
-    }
-
-    /**
      * Returns a predicate who's result matches
      * {@code Objects.equals(target, t)}.
      *
@@ -68,278 +54,4 @@
                 ? Objects::isNull
                 : object -> target.equals(object);
     }
-
-    /**
-     * Returns a predicate that evaluates to {@code true} if all of the
-     * component predicates evaluate to {@code true}. The components are
-     * evaluated in order, and evaluation will end upon the first {@code false}
-     * predicate.
-     *
-     * @param <T> the type of values evaluated by the predicates.
-     * @param predicates The predicates to be evaluated.
-     * @return A predicate who's result is {@code true} iff all component
-     * predicates are {@code true}.
-     */
-    public static <T> Predicate<T> and(
-            Iterable<? extends Predicate<? super T>> predicates) {
-        Objects.requireNonNull(predicates);
-
-        return t
-                    -> {
-            for (Predicate<? super T> predicate : predicates) {
-                        if (!predicate.test(t)) {
-                            return false;
-                        }
-                    }
-                    return true;
-                };
-    }
-
-    /**
-     * Returns a predicate that evaluates to {@code true} if all of the
-     * component predicates evaluate to {@code true}. The components are
-     * evaluated in order, and evaluation will end upon the first {@code false}
-     * predicate.
-     *
-     * @param <T> the type of values evaluated by the predicates.
-     * @param first An initial predicate to be evaluated before the others.
-     * @param predicates The predicates to be evaluated.
-     * @return A predicate who's result is {@code true} iff all component
-     * predicates are {@code true}.
-     */
-    static <T> Predicate<T> and(
-            Predicate<? super T> first, Iterable<? extends Predicate<? super T>> predicates) {
-        Objects.requireNonNull(first);
-        Objects.requireNonNull(predicates);
-
-        return t
-                    -> {
-            if (!first.test(t)) {
-                        return false;
-                    }
-                    for (Predicate<? super T> predicate : predicates) {
-                        if (!predicate.test(t)) {
-                            return false;
-                        }
-                    }
-                    return true;
-                };
-    }
-
-    /**
-     * Returns a predicate that evaluates to {@code true} if all of the
-     * component predicates evaluate to {@code true}. The components are
-     * evaluated in order, and evaluation will end upon the first {@code false}
-     * predicate.
-     *
-     * @param <T> the type of values evaluated by the predicates.
-     * @param predicates The predicates to be evaluated.
-     * @return A predicate who's result is {@code true} iff all component
-     * predicates are {@code true}.
-     */
-    @SafeVarargs
-    public static <T> Predicate<T> and(
-            Predicate<? super T>... predicates) {
-        return and(Arrays.asList(predicates));
-    }
-
-    /**
-     * Returns a predicate that evaluates to {@code true} if all of the
-     * component predicates evaluate to {@code true}. The components are
-     * evaluated in order, and evaluation will end upon the first {@code false}
-     * predicate.
-     *
-     * @param <T> the type of values evaluated by the predicates.
-     * @param first An initial predicate to be evaluated.
-     * @param predicates The predicates to be evaluated.
-     * @return A predicate who's result is {@code true} iff all component
-     * predicates are {@code true}.
-     */
-    @SafeVarargs
-    static <T> Predicate<T> and(
-            Predicate<? super T> first, Predicate<? super T>... predicates) {
-        return and(first, Arrays.asList(predicates));
-    }
-
-    /**
-     * Returns a predicate that evaluates to {@code true} if any of the
-     * component predicates evaluate to {@code true}. The components are
-     * evaluated in order, and evaluation will end upon the first {@code true}
-     * predicate.
-     *
-     * @param <T> the type of values evaluated by the predicates.
-     * @param predicates The predicates to be evaluated.
-     * @return A predicate who's result is {@code true} if any component
-     * predicate's result is {@code true}.
-     */
-    public static <T> Predicate<T> or(
-            Iterable<? extends Predicate<? super T>> predicates) {
-        Objects.requireNonNull(predicates);
-
-        return t
-                    -> {
-            for (Predicate<? super T> predicate : predicates) {
-                        if (predicate.test(t)) {
-                            return true;
-                        }
-                    }
-                    return false;
-                };
-    }
-
-    /**
-     * Returns a predicate that evaluates to {@code true} if any of the
-     * component predicates evaluate to {@code true}. The components are
-     * evaluated in order, and evaluation will end upon the first {@code true}
-     * predicate.
-     *
-     * @param <T> the type of values evaluated by the predicates.
-     * @param predicates The predicates to be evaluated.
-     * @return A predicate who's result is {@code true} if any component
-     * predicate's result is {@code true}.
-     */
-    static <T> Predicate<T> or(
-            Predicate<? super T> first, Iterable<? extends Predicate<? super T>> predicates) {
-        Objects.requireNonNull(first);
-        Objects.requireNonNull(predicates);
-
-        return t
-                    -> {
-            if (first.test(t)) {
-                        return true;
-                    }
-                    for (Predicate<? super T> predicate : predicates) {
-                        if (predicate.test(t)) {
-                            return true;
-                        }
-                    }
-                    return false;
-                };
-    }
-
-    /**
-     * Returns a predicate that evaluates to {@code true} if any of the
-     * component predicates evaluate to {@code true}. The components are
-     * evaluated in order, and evaluation will terminate upon the first
-     * {@code true} predicate.
-     *
-     * @param <T> the type of values evaluated by the predicates.
-     * @param predicates The predicates to be evaluated.
-     * @return A predicate who's result is {@code true} if any component
-     * predicate's result is {@code true}.
-     */
-    @SafeVarargs
-    public static <T> Predicate<T> or(
-            Predicate<? super T>... predicates) {
-        return or(Arrays.asList(predicates));
-    }
-
-    /**
-     * Returns a predicate that evaluates to {@code true} if any of the
-     * component predicates evaluate to {@code true}. The components are
-     * evaluated in order, and evaluation will terminate upon the first
-     * {@code true} predicate.
-     *
-     * @param <T> the type of values evaluated by the predicates.
-     * @param predicates The predicates to be evaluated.
-     * @return A predicate who's result is {@code true} if any component
-     * predicate's result is {@code true}.
-     */
-    @SafeVarargs
-    static <T> Predicate<T> or(
-            Predicate<? super T> first, Predicate<? super T>... predicates) {
-        return or(first, Arrays.asList(predicates));
-    }
-
-    /**
-     * Returns a predicate that evaluates to {@code false} if all or none of the
-     * component predicates evaluate to {@code true}. The components are
-     * evaluated in order, and evaluation will end if a predicate result fails
-     * to match the first predicate's result.
-     *
-     * @param <T> the type of values evaluated by the predicates.
-     * @param predicates The predicates to be evaluated.
-     * @return a predicate that evaluates to {@code false} if all or none of the
-     * component predicates evaluate to {@code true}
-     */
-    public static <T> Predicate<T> xor(
-            Iterable<? extends Predicate<? super T>> predicates) {
-        Objects.requireNonNull(predicates);
-
-        return t -> {
-            Iterator<? extends Predicate<? super T>> iterator = predicates.iterator();
-                    if (!iterator.hasNext()) {
-                        return false;
-                    }
-                    boolean initial = iterator.next().test(t);
-                    while (iterator.hasNext()) {
-                        boolean current = iterator.next().test(t);
-                        if (!(initial ^ current)) {
-                            return false;
-                        }
-                    }
-                    return true;
-                };
-    }
-
-    /**
-     * Returns a predicate that evaluates to {@code false} if all or none of the
-     * component predicates evaluate to {@code true}. The components are
-     * evaluated in order, and evaluation will end if a predicate result fails
-     * to match the first predicate's result.
-     *
-     * @param <T> the type of values evaluated by the predicates.
-     * @param predicates The predicates to be evaluated.
-     * @return a predicate that evaluates to {@code false} if all or none of the
-     * component predicates evaluate to {@code true}
-     */
-    static <T> Predicate<T> xor(
-            Predicate<? super T> first, Iterable<? extends Predicate<? super T>> predicates) {
-        Objects.requireNonNull(first);
-        Objects.requireNonNull(predicates);
-
-        return t
-                    -> {
-            boolean initial = first.test(t);
-                    for (Predicate<? super T> predicate : predicates) {
-                        if (!(initial ^ predicate.test(t))) {
-                            return false;
-                        }
-                    }
-                    return true;
-                };
-    }
-
-    /**
-     * Returns a predicate that evaluates to {@code false} if all or none of the
-     * component predicates evaluate to {@code true}. The components are
-     * evaluated in order, and evaluation will terminate if a predicate result
-     * fails to match the first predicate's result.
-     *
-     * @param <T> the type of values evaluated by the predicates.
-     * @param predicates The predicates to be evaluated.
-     * @return a predicate that evaluates to {@code false} if all or none of the
-     * component predicates evaluate to {@code true}
-     */
-    @SafeVarargs
-    public static <T> Predicate<T> xor(Predicate<? super T>... predicates) {
-        return xor(Arrays.asList(predicates));
-    }
-
-    /**
-     * Returns a predicate that evaluates to {@code false} if all or none of the
-     * component predicates evaluate to {@code true}. The components are
-     * evaluated in order, and evaluation will end if a predicate result fails
-     * to match the first predicate's result.
-     *
-     * @param <T> the type of values evaluated by the predicates.
-     * @param predicates The predicates to be evaluated.
-     * @return a predicate that evaluates to {@code false} if all or none of the
-     * component predicates evaluate to {@code true}
-     */
-    @SafeVarargs
-    static <T> Predicate<T> xor(
-            Predicate<? super T> first, Predicate<? super T>... predicates) {
-        return xor(first, Arrays.asList(predicates));
-    }
 }
--- a/test/java/util/function/FunctionsTest.java	Mon Apr 01 13:41:33 2013 -0700
+++ b/test/java/util/function/FunctionsTest.java	Mon Apr 01 13:45:28 2013 -0700
@@ -32,6 +32,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.function.Function;
+import java.util.function.IntFunction;
 import java.util.function.Functions;
 
 import org.testng.annotations.Test;
@@ -90,8 +91,10 @@
 
     @Test
     public void testInstantiate() {
-        assertEquals(1, Functions.instantiate(Integer.class, Goomba.class).apply(1).value);
-        assertEquals(2, Functions.instantiate(Integer.class, Goomba.class).apply(2).value);
+        IntFunction<Integer> f = Integer::valueOf;
+
+        assertEquals(1, f.apply(1).intValue());
+        assertEquals(2, f.apply(2).intValue());
     }
 
     @Test
@@ -130,21 +133,6 @@
     }
 
     @Test
-    public void testChain() {
-        Function<Integer, Boolean> first = Functions.forPredicate(x -> x != 0, true, false);
-        Function<Boolean, String> second = Functions.forPredicate(x -> !x, "false", "true");
-        Function<Integer, String> mapper = Functions.chain(first, second);
-        Function<Integer, Integer> f = x ->  x % 3;
-        Function<Integer, Integer> f1 = x -> x + 3;
-        Function<Integer, Integer> f2 = x -> x * 3;
-
-        assertEquals(mapper.apply(0), "false");
-        assertEquals(mapper.apply(1), "true");
-        assertEquals((int) f.compose(f1).apply(7), 1);
-        assertEquals((int) f1.compose(f2).apply(1), 6);
-    }
-
-    @Test
     public void testSubstitute() {
         Function<Integer, Integer> ints = Functions.substitute(3, 999);
         Function<String, String> strings = Functions.substitute("hello", "bonjour");
@@ -162,20 +150,6 @@
     }
 
     @Test(expectedExceptions = {NullPointerException.class})
-    void testChainNPE() {
-        @SuppressWarnings("unchecked")
-        Function<Boolean, Boolean> f = Functions.chain(null, fFalse);
-        boolean result = f.apply(true);
-    }
-
-    @Test(expectedExceptions = {NullPointerException.class})
-    void testComposeNPE() {
-        @SuppressWarnings("unchecked")
-        Function<Boolean, Boolean> f = Functions.chain(fFalse, fFalse).compose(null);
-        boolean result = f.apply(true);
-    }
-
-    @Test(expectedExceptions = {NullPointerException.class})
     void testForPredicateNPE() {
         @SuppressWarnings("unchecked")
         Function<Boolean, Boolean> f = Functions.forPredicate(null, true, false);
--- a/test/java/util/function/PredicateTest.java	Mon Apr 01 13:41:33 2013 -0700
+++ b/test/java/util/function/PredicateTest.java	Mon Apr 01 13:45:28 2013 -0700
@@ -31,6 +31,9 @@
 
 import org.testng.annotations.Test;
 
+import java.util.HashSet;
+import java.util.function.Predicate;
+import java.util.function.Predicates;
 import java.util.function.DoublePredicate;
 import java.util.function.IntPredicate;
 import java.util.function.LongPredicate;
@@ -194,4 +197,13 @@
         assertFalse(pMagic.test(new Double(1.8675390)));
         assertFalse(pMagic.test(1.8675390));
     }
+
+    @Test
+    public void testIsEqual() {
+        HashSet<Long> s1 = new HashSet<>();
+        HashSet<Long> s2 = (HashSet<Long>) s1.clone();
+        assertTrue(Predicates.isEqual(null).test(null));
+        assertTrue(Predicates.isEqual(s2).test(s1));
+    }
+
 }
--- a/test/java/util/function/PredicatesTest.java	Mon Apr 01 13:41:33 2013 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,199 +0,0 @@
-/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test Basic test for Predicates functional utils
- * @author  Mike Duigou
- * @run testng PredicatesTest
- */
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Stack;
-import java.util.function.Function;
-import java.util.function.Predicate;
-import java.util.function.Predicates;
-
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-/*
- * Basic test for Predicates functional utils
- */
-public class PredicatesTest {
-
-    private static final Predicate<Integer> p = x -> 0 == x % 2;
-    private static final Function<Integer, Integer> f1 = x -> x * 2;
-    private static final Function<Integer, Integer> f2 = x -> x * 3;
-
-    @Test
-    public void testIsSame() {
-        List<Object> l = new ArrayList<>();
-        HashSet<Long> s1 = new HashSet<>();
-        HashSet<Long> s2 = (HashSet<Long>) s1.clone();
-        assertTrue(Predicates.isSame(null).test(null));
-        assertTrue(!Predicates.isSame(s2).test(s1));
-        assertTrue(Predicates.isSame(l).test(l));
-        assertTrue(!Predicates.isSame(List.class).test(l));
-    }
-
-    @Test
-    public void testIsEqual() {
-        HashSet<Long> s1 = new HashSet<>();
-        HashSet<Long> s2 = (HashSet<Long>) s1.clone();
-        assertTrue(Predicates.isEqual(null).test(null));
-        assertTrue(Predicates.isEqual(s2).test(s1));
-    }
-
-    @Test
-    public void testAnd() {
-        Predicate<Integer> first = x->x != 0;
-        Predicate<Integer> second = x->x == 0;
-
-        assertTrue(!Predicates.and(first, first).test(0));
-        assertTrue(Predicates.and(first, first).test(1));
-        assertTrue(!Predicates.and(first, second).test(0));
-        assertTrue(!Predicates.and(first, second).test(1));
-    }
-
-    @Test
-    public void testAndVarArgs() {
-        Predicate<Integer> first = x->x != 0;
-        Predicate<Integer> second = x->x == 0;
-
-        @SuppressWarnings("unchecked")
-        Predicate<Integer> predicates1[] = (Predicate<Integer>[]) new Predicate<?>[]{first, first};
-
-        @SuppressWarnings("unchecked")
-        Predicate<Integer> predicates2[] = (Predicate<Integer>[]) new Predicate<?>[]{first, second};
-
-        //THROWS(NullPointerException.class, () -> { Predicates.and(new Predicate[] {null}); });
-        assertTrue(!Predicates.and(predicates1).test(0));
-        assertTrue(Predicates.and(predicates1).test(1));
-        assertTrue(!Predicates.and(predicates2).test(0));
-        assertTrue(!Predicates.and(predicates2).test(1));
-    }
-
-    @Test
-    public void testOr() {
-        Predicate<Integer> first = x->x != 0;
-        Predicate<Integer> second = x->x == 0;
-
-        assertTrue(!Predicates.or(first, first).test(0));
-        assertTrue(Predicates.or(first, first).test(1));
-        assertTrue(Predicates.or(first, second).test(0));
-        assertTrue(Predicates.or(first, second).test(1));
-    }
-
-
-    @Test
-    public void testOrVarArgs() {
-        Predicate<Integer> first = x->x != 0;
-        Predicate<Integer> second = x->x == 0;
-
-        @SuppressWarnings("unchecked")
-        Predicate<Integer> predicates1[] = (Predicate<Integer>[]) new Predicate<?>[]{first, first};
-
-        @SuppressWarnings("unchecked")
-        Predicate<Integer> predicates2[] = (Predicate<Integer>[]) new Predicate<?>[]{first, second};
-
-        //THROWS(NullPointerException.class, () -> { Predicates.or(new Predicate[] {null}); });
-        assertTrue(!Predicates.or(predicates1).test(0));
-        assertTrue(Predicates.or(predicates1).test(1));
-        assertTrue(Predicates.or(predicates2).test(0));
-        assertTrue(Predicates.or(predicates2).test(1));
-    }
-
-    @Test
-    public void testXor() {
-        Predicate<Integer> first = x->x != 0;
-        Predicate<Integer> second = x->x == 0;
-
-        assertTrue(!Predicates.xor(first, first).test(0));
-        assertTrue(!Predicates.xor(first, first).test(1));
-        assertTrue(Predicates.xor(first, second).test(0));
-        assertTrue(Predicates.xor(first, second).test(1));
-    }
-
-    @Test
-    public void testXorVarArgs() {
-        Predicate<Integer> first = x->x != 0;
-        Predicate<Integer> second = x->x == 0;
-
-        @SuppressWarnings("unchecked")
-        Predicate<Integer> predicates1[] = (Predicate<Integer>[]) new Predicate<?>[]{
-                first, first
-        };
-
-        @SuppressWarnings("unchecked")
-        Predicate<Integer> predicates2[] = (Predicate<Integer>[]) new Predicate<?>[]{
-                first, second
-        };
-
-        boolean onesZero = Predicates.xor(predicates1).test(0);
-        boolean onesOne = Predicates.xor(predicates1).test(1);
-        boolean twosZero = Predicates.xor(predicates2).test(0);
-        boolean twosOne = Predicates.xor(predicates2).test(1);
-
-        assertTrue(!onesZero);
-        assertTrue(!onesOne);
-        assertTrue(twosZero);
-        assertTrue(twosOne);
-    }
-
-    @Test(expectedExceptions = {NullPointerException.class})
-    void testXorNPE() {
-        @SuppressWarnings("unchecked")
-        Predicate<String>[] predicates = (Predicate<String>[]) new Predicate<?>[1];
-        predicates[0] = null;
-        Predicate<String> p = Predicates.xor(predicates);
-        boolean result = p.test("");
-    }
-
-    @Test(expectedExceptions = {NullPointerException.class})
-    void testOrNPE() {
-        @SuppressWarnings("unchecked")
-        Predicate<String>[] predicates = (Predicate<String>[]) new Predicate<?>[1];
-        predicates[0] = null;
-        Predicate<String> p = Predicates.or(predicates);
-        boolean result = p.test("");
-    }
-
-    @Test(expectedExceptions = {NullPointerException.class})
-    void testAndNPE() {
-        @SuppressWarnings("unchecked")
-        Predicate<String>[] predicates = (Predicate<String>[]) new Predicate<?>[1];
-        predicates[0] = null;
-        Predicate<String> p = Predicates.and(predicates);
-        boolean result = p.test("");
-    }
-
-    private interface Fun {
-        void f() throws Throwable;
-    }
-
-}
--- a/test/java/util/stream/Stream/EmployeeStreamTest.java	Mon Apr 01 13:41:33 2013 -0700
+++ b/test/java/util/stream/Stream/EmployeeStreamTest.java	Mon Apr 01 13:45:28 2013 -0700
@@ -36,7 +36,6 @@
 import java.util.function.BiFunction;
 import java.util.function.Function;
 import java.util.function.Predicate;
-import java.util.function.Predicates;
 import java.util.stream.Collectors;
 import java.util.stream.FlatMapper;
 import java.util.stream.Stream;
@@ -389,7 +388,7 @@
             List<Employee> result2 = stream.filter(p1).filter(p2).collect(Collectors.toCollection(ArrayList<Employee>::new));
             stream = (type == ParallelType.Parallel) ? l.parallelStream() : ((type == ParallelType.Sequential) ? l
                     .stream().sequential() : l.stream());
-            List<Employee> result3 = stream.filter(Predicates.and(p1, p2)).collect(Collectors.toCollection(ArrayList<Employee>::new));
+            List<Employee> result3 = stream.filter(p1.and( p2)).collect(Collectors.toCollection(ArrayList<Employee>::new));
             Collections.sort(result2, rule.getComparator());
             Collections.sort(result3, rule.getComparator());
             assertEquals(result2, result3);
@@ -400,11 +399,11 @@
             List<Employee> concatList = new ArrayList<>();
             stream = (type == ParallelType.Parallel) ? l.parallelStream() : ((type == ParallelType.Sequential) ? l
                     .stream().sequential() : l.stream());
-            result2 = stream.filter(Predicates.and(p1, p2)).collect(Collectors.toCollection(ArrayList<Employee>::new));
+            result2 = stream.filter(p1.and(p2)).collect(Collectors.toCollection(ArrayList<Employee>::new));
             stream = (type == ParallelType.Parallel) ? l.parallelStream() : ((type == ParallelType.Sequential) ? l
                     .stream().sequential() : l.stream());
-            result3 = stream.filter(Predicates.or(p1, p2)).collect(Collectors.toCollection(ArrayList<Employee>::new));
-            
+            result3 = stream.filter(p1.or(p2)).collect(Collectors.toCollection(ArrayList<Employee>::new));
+
             concatList.addAll(result2);
             concatList.addAll(result3);
             result3.clear();
@@ -801,7 +800,7 @@
                 String salaryKey = (String)keyiter.next();
                 List<Employee> salarayEmList = result.get(salaryKey);
                 for(Employee e: salarayEmList) {
-                    assertEquals(e.salary <= 6000 ? "LOW" : 
+                    assertEquals(e.salary <= 6000 ? "LOW" :
                             (e.salary > 15000 ? "HIGH" : "MEDIUM"), salaryKey);
                 }
                 break;
@@ -1074,8 +1073,8 @@
                 };
         }
     }
-    
-    
+
+
     public static Function<Employee, Object> employeeGenericFunction(Employee.Rule rule) {
         switch (rule) {
             case AGE:
--- a/test/java/util/stream/Stream/IntegerStreamTest.java	Mon Apr 01 13:41:33 2013 -0700
+++ b/test/java/util/stream/Stream/IntegerStreamTest.java	Mon Apr 01 13:45:28 2013 -0700
@@ -36,7 +36,6 @@
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.BiFunction;
 import java.util.function.Predicate;
-import java.util.function.Predicates;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import java.util.stream.Streams;
@@ -285,7 +284,7 @@
             stream = (type == ParallelType.Parallel) ? l.parallelStream():
                     ((type == ParallelType.Sequential) ? l.stream().sequential() :
                     l.stream());
-            List<Integer> result3 = stream.filter(Predicates.and(p1,p2)).collect(Collectors.toCollection(ArrayList<Integer>::new));
+            List<Integer> result3 = stream.filter(p1.and(p2)).collect(Collectors.toCollection(ArrayList<Integer>::new));
             Comparator<Integer> c = (Comparator<Integer>)Comparators.naturalOrder();
             Collections.sort(result2, c);
             Collections.sort(result3, c);
@@ -296,11 +295,11 @@
             stream = (type == ParallelType.Parallel) ? l.parallelStream():
                     ((type == ParallelType.Sequential) ? l.stream().sequential() :
                     l.stream());
-            result2 = stream.filter(Predicates.and(p1,p2)).collect(Collectors.toCollection(ArrayList<Integer>::new));
+            result2 = stream.filter(p1.and(p2)).collect(Collectors.toCollection(ArrayList<Integer>::new));
             stream = (type == ParallelType.Parallel) ? l.parallelStream():
                     ((type == ParallelType.Sequential) ? l.stream().sequential() :
                     l.stream());
-            result3 = stream.filter(Predicates.or(p1,p2)).collect(Collectors.toCollection(ArrayList<Integer>::new));
+            result3 = stream.filter(p1.or(p2)).collect(Collectors.toCollection(ArrayList<Integer>::new));
             result2.addAll(result3);
 
             stream = (type == ParallelType.Parallel) ? l.parallelStream():
--- a/test/java/util/stream/Stream/StringBuilderStreamTest.java	Mon Apr 01 13:41:33 2013 -0700
+++ b/test/java/util/stream/Stream/StringBuilderStreamTest.java	Mon Apr 01 13:45:28 2013 -0700
@@ -35,7 +35,6 @@
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.BiFunction;
 import java.util.function.Predicate;
-import java.util.function.Predicates;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import java.util.stream.Streams;
@@ -328,8 +327,8 @@
             stream = (type == ParallelType.Parallel) ? l.parallelStream():
                     ((type == ParallelType.Sequential) ? l.stream().sequential() :
                     l.stream());
-            List<StringBuilder> result3 = stream.filter(Predicates.and(p1,p2)).collect(Collectors.toCollection(ArrayList<StringBuilder>::new));
-            
+            List<StringBuilder> result3 = stream.filter(p1.and(p2)).collect(Collectors.toCollection(ArrayList<StringBuilder>::new));
+
             if(result2.isEmpty()) {
                 assertEquals(result2.size(), result3.size());
             } else {
@@ -344,11 +343,11 @@
             stream = (type == ParallelType.Parallel) ? l.parallelStream():
                     ((type == ParallelType.Sequential) ? l.stream().sequential() :
                     l.stream());
-            result2 = stream.filter(Predicates.and(p1,p2)).collect(Collectors.toCollection(ArrayList<StringBuilder>::new));
+            result2 = stream.filter(p1.and(p2)).collect(Collectors.toCollection(ArrayList<StringBuilder>::new));
             stream = (type == ParallelType.Parallel) ? l.parallelStream():
                     ((type == ParallelType.Sequential) ? l.stream().sequential() :
                     l.stream());
-            result3 = stream.filter(Predicates.or(p1,p2)).collect(Collectors.toCollection(ArrayList<StringBuilder>::new));
+            result3 = stream.filter(p1.or(p2)).collect(Collectors.toCollection(ArrayList<StringBuilder>::new));
             result2.addAll(result3);
             result3.clear();
             stream = (type == ParallelType.Parallel) ? l.parallelStream():