changeset 4716:09a69a0111ba

Convert extension methods to implmentation in the interfaces.
author mduigou
date Fri, 16 Dec 2011 16:26:32 -0800
parents ce7be1db15b3
children 085fb9c9164f
files src/share/classes/java/lang/Iterable.java src/share/classes/java/util/Collection.java src/share/classes/java/util/Comparator.java src/share/classes/java/util/Iterables.java src/share/classes/java/util/Iterator.java src/share/classes/java/util/List.java src/share/classes/java/util/ParallelIterable.java src/share/classes/java/util/functions/Block.java src/share/classes/java/util/functions/Mapper.java src/share/classes/java/util/functions/Predicate.java test/java/lang/Iterables/LambdasTests.java test/java/util/Iterators/LambdasTests.java
diffstat 12 files changed, 283 insertions(+), 105 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/lang/Iterable.java	Tue Nov 29 10:44:18 2011 -0800
+++ b/src/share/classes/java/lang/Iterable.java	Fri Dec 16 16:26:32 2011 -0800
@@ -57,7 +57,7 @@
      *
      * @return {@code true} if this Iterable contains no elements.
      */
-    boolean isEmpty() default Iterables.isEmpty;
+    boolean isEmpty() default { return Iterables.isEmpty(this); };
 
     /**
      * Filter elements according to the provided {@code predicate} and return a
@@ -71,7 +71,9 @@
      * included in the resulting view.
      * @return An Iterable view of the filtered elements.
      */
-    Iterable<T> filter(Predicate<? super T> predicate) default Iterables.filter;
+    Iterable<T> filter(Predicate<? super T> predicate) default {
+        return Iterables.filter(this, predicate);
+    }
 
     /**
      * Performs the operation specified by {@code block} upon each element.
@@ -81,7 +83,9 @@
      * @param block The operation to be performed upon each each element.
      * @return This Iterable.
      */
-    Iterable<T> forEach(Block<? super T> block) default Iterables.forEach;
+    Iterable<T> forEach(Block<? super T> block) default {
+        return Iterables.forEach(this, block);
+    }
 
     /**
      * Map elements using the provided {@code mapper} and return an Iterable
@@ -95,7 +99,13 @@
      * and elements of type {@code U}.
      * @return An Iterable view consisting of the mapped elements.
      */
-     <U> Iterable<U> map(Mapper<? super T, ? extends U> mapper) default Iterables.map;
+     <U> Iterable<U> map(Mapper<? super T, ? extends U> mapper) default {
+         return Iterables.map(this, mapper);
+     }
+
+     <U> Iterable<U> filterMap(Predicate<? super T> predicate, Mapper<? super T, ? extends U> mapper) default {
+         return Iterables.filterMap(this, predicate, mapper);
+     }
 
     /**
      * Reduce elements to a single value.
@@ -106,12 +116,27 @@
      * @param base Initial value for reducer.
      * @return The reduced value of the elements.
      */
-    T reduce(T base, Operator<T> reducer) default Iterables.reduce;
+    T reduce(T base, Operator<T> reducer) default {
+        return Iterables.reduce(this, base, reducer);
+    }
 
-    <U> U mapReduce(Mapper<? super T, ? extends U> mapper, U base, Operator<U> reducer) default Iterables.mapReduce;
-    int mapReduce(IntMapper<? super T> mapper, int base, IntOperator reducer) default Iterables.mapReduce;
-    long mapReduce(LongMapper<? super T> mapper, long base, LongOperator reducer) default Iterables.mapReduce;
-    double mapReduce(DoubleMapper<? super T> mapper, double base, DoubleOperator reducer) default Iterables.mapReduce;
+    <U> U mapReduce(Mapper<? super T, ? extends U> mapper, U base, Operator<U> reducer) default {
+        return Iterables.mapReduce(this, mapper, base, reducer);
+    }
+    int mapReduce(IntMapper<? super T> mapper, int base, IntOperator reducer) default {
+        return Iterables.mapReduce(this, mapper, base, reducer);
+    }
+    long mapReduce(LongMapper<? super T> mapper, long base, LongOperator reducer) default {
+        return Iterables.mapReduce(this, mapper, base, reducer);
+    }
+    double mapReduce(DoubleMapper<? super T> mapper, double base, DoubleOperator reducer) default {
+        return Iterables.mapReduce(this, mapper, base, reducer);
+    }
+
+     <U> U filterMapReduce(Predicate<? super T> predicate, Mapper<? super T, ? extends U> mapper,U base, Operator<U> reducer) default {
+         return Iterables.filterMapReduce(this, predicate, mapper, base, reducer);
+     }
+
 
     /**
      * All elements are added to the specified collection.
@@ -122,7 +147,9 @@
      *
      * @since 1.8
      */
-    <A extends Fillable<? super T>> A into(A target) default Iterables.into;
+    <A extends Fillable<? super T>> A into(A target) default {
+        return Iterables.into(this, target);
+    }
 
     /**
      * Returns {@code true} if any of the elements match the provided predicate.
@@ -132,7 +159,9 @@
      * @return {@code true} if any elements returned {@code true} for the
      * provided predicate.
      */
-    public boolean anyMatch(Predicate<? super T> filter) default Iterables.anyMatch;
+    public boolean anyMatch(Predicate<? super T> filter) default {
+        return Iterables.anyMatch(this, filter);
+    }
 
     /**
      * Returns {@code true} if none of the elements match the provided predicate.
@@ -142,7 +171,9 @@
      * @return {@code true} if all elements of this collection returned
      * {@code true} for the provided predicate.
      */
-    public boolean noneMatch(Predicate<? super T> filter) default Iterables.noneMatch;
+    public boolean noneMatch(Predicate<? super T> filter) default {
+        return Iterables.noneMatch(this, filter);
+    }
 
     /**
      * Returns {@code true} if all of the elements match the provided predicate.
@@ -151,11 +182,17 @@
      * matching elements.
      * @return {@code true} if all elements returned {@code true} for the provided predicate.
      */
-    public boolean allMatch(Predicate<? super T> filter) default Iterables.allMatch;
+    public boolean allMatch(Predicate<? super T> filter) default {
+        return Iterables.allMatch(this, filter);
+    }
 
     // public Iterable<T> sorted() default Iterables.sorted;
 
-    public Iterable<T> sorted(Comparator<? super T> comparator) default Iterables.sorted;
+    public Iterable<T> sorted(Comparator<? super T> comparator) default {
+        return Iterables.sorted(this, comparator);
+    }
 
-    public Iterable<T> uniqueElements() default Iterables.uniqueElements;
+    public Iterable<T> uniqueElements() default {
+        return Iterables.uniqueElements(this);
+    }
 }
--- a/src/share/classes/java/util/Collection.java	Tue Nov 29 10:44:18 2011 -0800
+++ b/src/share/classes/java/util/Collection.java	Fri Dec 16 16:26:32 2011 -0800
@@ -464,7 +464,9 @@
      * @return {@code true} if any elements were retained.
      */
     // XXX potential source incompatibility with retainAll(null) now being ambiguous
-    boolean retainAll(Predicate<? super E> filter) default CollectionHelpers.retainAll;
+    boolean retainAll(Predicate<? super E> filter) default {
+        return CollectionHelpers.retainAll(this, filter);
+    }
 
     /**
      * Removes all of the elements of this collection which match the provided
@@ -475,7 +477,11 @@
      * @return {@code true} if any elements were removed.
      */
     // XXX potential source incompatibility with removeAll(null) now being ambiguous
-    boolean removeAll(Predicate<? super E> filter) default CollectionHelpers.removeAll;
+    boolean removeAll(Predicate<? super E> filter) default {
+        return CollectionHelpers.removeAll(this, filter);
+    }
 
-    void addAll(Iterable<? extends E> source) default CollectionHelpers.addAll;
+    void addAll(Iterable<? extends E> source) default {
+        CollectionHelpers.addAll(this, source);
+    }
 }
--- a/src/share/classes/java/util/Comparator.java	Tue Nov 29 10:44:18 2011 -0800
+++ b/src/share/classes/java/util/Comparator.java	Fri Dec 16 16:26:32 2011 -0800
@@ -166,7 +166,11 @@
      */
     boolean equals(Object obj);
 
-    Comparator<T> reverse() default Collections.reverseOrder;
+    Comparator<T> reverse() default {
+        return Collections.reverseOrder(this);
+    }
 
-    Comparator<T> compose(Comparator<? super T> other) default Comparators.compose;
+    Comparator<T> compose(Comparator<? super T> other) default {
+        return Comparators.compose(this, other);
+    }
 }
--- a/src/share/classes/java/util/Iterables.java	Tue Nov 29 10:44:18 2011 -0800
+++ b/src/share/classes/java/util/Iterables.java	Fri Dec 16 16:26:32 2011 -0800
@@ -101,6 +101,64 @@
         };
     }
 
+
+    /**
+     * Filter elements according to the provided {@code predicate} and return a
+     * an Iterable view of the filtered elements. The filtered view will reflect
+     * changes in the provided {@code iterable}.
+     *
+     * @param <T> Type of elements.
+     * @param <U> Type of the returned elements.
+     * @param iterable The source of elements.
+     * @param predicate Decides which elements should be included in the
+     * resulting Iterable view. Each element with a {@code true} result will be
+     * included in the resulting view.
+     * @param mapper Performs the mapping between elements of type {@code T}
+     * and type {@code U}.
+     * @return An Iterable view of the filtered elements.
+     */
+    public static <T, U> Iterable<U> filterMap(final Iterable<T> iterable,
+            final Predicate<? super T> predicate,
+            final Mapper<? super T, ? extends U> mapper) {
+        Objects.requireNonNull(iterable);
+        Objects.requireNonNull(predicate);
+        return new BaseIterable<U>() {
+            @Override
+            public Iterator<U> iterator() {
+                return Iterators.map(Iterators.filter(iterable.iterator(), predicate),mapper);
+            }
+        };
+    }
+
+        /**
+     * Filter elements according to the provided {@code predicate} and return a
+     * an Iterable view of the filtered elements. The filtered view will reflect
+     * changes in the provided {@code iterable}.
+     *
+     * @param <T> Type of elements.
+     * @param <U> Type of the returned elements.
+     * @param iterable The source of elements.
+     * @param predicate Decides which elements should be included in the
+     * resulting Iterable view. Each element with a {@code true} result will be
+     * included in the resulting view.
+     * @param mapper Performs the mapping between elements of type {@code T}
+     * and type {@code U}.
+     * @param operator Reduces elements to a result of type {@code U}.
+     * @param base Initial value for reducer.
+     * @return reduced value of the elements.
+     */
+    public static <T, U> U filterMapReduce(final Iterable<T> iterable,
+            final Predicate<? super T> predicate,
+            final Mapper<? super T, ? extends U> mapper,
+            U base,
+            Operator<U> operator) {
+        Objects.requireNonNull(iterable);
+        Objects.requireNonNull(predicate);
+        Objects.requireNonNull(mapper);
+        Objects.requireNonNull(operator);
+        return Iterators.reduce(Iterators.map(Iterators.filter(iterable.iterator(), predicate), mapper), base, operator);
+    }
+
     /**
      * Performs the operation specified by {@code block} upon each element.
      *
--- a/src/share/classes/java/util/Iterator.java	Tue Nov 29 10:44:18 2011 -0800
+++ b/src/share/classes/java/util/Iterator.java	Fri Dec 16 16:26:32 2011 -0800
@@ -83,5 +83,7 @@
      *         been called after the last call to the {@code next}
      *         method
      */
-    void remove() default Iterators.removeUnsupported;
+    void remove() default {
+        throw new UnsupportedOperationException("remove");
+    }
 }
--- a/src/share/classes/java/util/List.java	Tue Nov 29 10:44:18 2011 -0800
+++ b/src/share/classes/java/util/List.java	Fri Dec 16 16:26:32 2011 -0800
@@ -607,8 +607,9 @@
      * @return index of the matching element or {@code -1} if no element
      * matched.
      */
-    int firstIndexOf(Predicate<? super E> match)
-        default ListHelpers.<E>firstIndexOf;
+    int firstIndexOf(Predicate<? super E> match) default {
+        return ListHelpers.<E>firstIndexOf(this, match);
+     }
 
     /**
      * Return index of the first element matching the provided predicate.
@@ -619,8 +620,9 @@
      * @return index of the matching element or {@code -1} if no element
      * matched.
      */
-    int nextIndexOf(Predicate<? super E> match, int pos)
-        default ListHelpers.<E>nextIndexOf;
+    int nextIndexOf(Predicate<? super E> match, int pos) default {
+        return ListHelpers.<E>nextIndexOf(this, match, pos);
+    }
 
     /**
      * Return index of the last element matching the provided predicate
@@ -632,8 +634,9 @@
      * @return index of the matching element or {@code -1} if no element
      * matched.
      */
-    int priorIndexOf(Predicate<? super E> match, int pos)
-        default ListHelpers.<E>priorIndexOf;
+    int priorIndexOf(Predicate<? super E> match, int pos) default {
+        return ListHelpers.<E>priorIndexOf(this, match, pos);
+            }
 
     /**
      * Return index of the last element matching the provided predicate.
@@ -642,16 +645,21 @@
      * @return index of the first matching element or {@code -1} if no element
      * matched.
      */
-    int lastIndexOf(Predicate<? super E> match)
-        default ListHelpers.<E>lastIndexOf;
+    int lastIndexOf(Predicate<? super E> match) default {
+        return ListHelpers.<E>lastIndexOf(this, match);
+    }
 
     // public void sort() default Collections.<E>sort;
 
-    public void sort(Comparator<? super E> c) default Collections.<E>sort;
+    public void sort(Comparator<? super E> c) default {
+        Collections.<E>sort(this, c);
+    }
 
     // public void parallelSort() default Collections.<E>sort;
 
-    public void parallelSort(Comparator<? super E> c) default Collections.<E>sort;
+    public void parallelSort(Comparator<? super E> c) default {
+        Collections.<E>sort(this,c);
+    }
 
 
 }
--- a/src/share/classes/java/util/ParallelIterable.java	Tue Nov 29 10:44:18 2011 -0800
+++ b/src/share/classes/java/util/ParallelIterable.java	Fri Dec 16 16:26:32 2011 -0800
@@ -16,7 +16,9 @@
      *
      * @return {@code true} if this Iterable contains no elements.
      */
-    boolean isEmpty() default ParallelIterables.isEmpty;
+    boolean isEmpty() default {
+        return ParallelIterables.isEmpty(this);
+    }
 
     /**
      * Filter elements according to the provided {@code predicate} and return a
@@ -30,7 +32,9 @@
      * included in the resulting view.
      * @return An Iterable view of the filtered elements.
      */
-    ParallelIterable<T> filter(Predicate<? super T> predicate) default ParallelIterables.filter;
+    ParallelIterable<T> filter(Predicate<? super T> predicate) default {
+        return ParallelIterables.filter(this, predicate);
+    }
 
     /**
      * Performs the operation specified by {@code block} upon each element.
@@ -39,7 +43,9 @@
      *
      * @param block The operation to be performed upon each each element.
      */
-    void forEach(Block<? super T> block) default ParallelIterables.forEach;
+    void forEach(Block<? super T> block) default {
+        ParallelIterables.forEach(this, block);
+    }
 
     /**
      * Map elements using the provided {@code mapper} and return an Iterable
@@ -53,7 +59,9 @@
      * and elements of type {@code U}.
      * @return An Iterable view consisting of the mapped elements.
      */
-     <U> ParallelIterable<U> map(Mapper<? super T, ? extends U> mapper) default ParallelIterables.map;
+     <U> ParallelIterable<U> map(Mapper<? super T, ? extends U> mapper) default {
+         return ParallelIterables.map(this, mapper);
+     }
 
     /**
      * Reduce elements to a single value.
@@ -64,12 +72,22 @@
      * @param base Initial value for reducer.
      * @return The reduced value of the elements.
      */
-     T reduce(T base, Operator<T> reducer) default ParallelIterables.reduce;
+     T reduce(T base, Operator<T> reducer) default {
+         return ParallelIterables.reduce(this, base, reducer);
+     }
 
-    <U> U mapReduce(Mapper<? super T, U> mapper, U base, Operator<U> reducer) default ParallelIterables.mapReduce;
-    int mapReduce(IntMapper<? super T> mapper, int base, IntOperator reducer) default ParallelIterables.mapReduce;
-    long mapReduce(LongMapper<? super T> mapper, long base, LongOperator reducer) default ParallelIterables.mapReduce;
-    double mapReduce(DoubleMapper<? super T> mapper, double base, DoubleOperator reducer) default ParallelIterables.mapReduce;
+    <U> U mapReduce(Mapper<? super T, U> mapper, U base, Operator<U> reducer) default {
+        return ParallelIterables.mapReduce(this, mapper, base, reducer);
+    }
+    int mapReduce(IntMapper<? super T> mapper, int base, IntOperator reducer) default {
+        return ParallelIterables.mapReduce(this, mapper, base, reducer);
+    }
+    long mapReduce(LongMapper<? super T> mapper, long base, LongOperator reducer) default {
+        return ParallelIterables.mapReduce(this, mapper, base, reducer);
+    }
+    double mapReduce(DoubleMapper<? super T> mapper, double base, DoubleOperator reducer) default {
+        return ParallelIterables.mapReduce(this, mapper, base, reducer);
+    }
 
     /**
      * All elements are added to the specified collection.
@@ -79,7 +97,9 @@
      * @param target The collection to which the elements are added.
      * @return The provided collection.
      */
-    <A extends Fillable<? super T>> A into(A target) default ParallelIterables.into;
+    <A extends Fillable<? super T>> A into(A target) default {
+        return ParallelIterables.into(this, target);
+}
 
     /**
      * Returns {@code true} if any of the elements match the provided predicate.
@@ -88,7 +108,9 @@
      * matching elements.
      * @return {@code true} if any elements returned {@code true} for the provided predicate.
      */
-    public boolean anyMatch(Predicate<? super T> filter) default ParallelIterables.anyMatch;
+    public boolean anyMatch(Predicate<? super T> filter) default {
+        return ParallelIterables.anyMatch(this, filter);
+    }
 
     /**
      * Returns {@code true} if none of the elements match the provided predicate.
@@ -98,7 +120,9 @@
      * @return {@code true} if all elements of this collection returned
      * {@code true} for the provided predicate.
      */
-    public boolean noneMatch(Predicate<? super T> filter) default ParallelIterables.noneMatch;
+    public boolean noneMatch(Predicate<? super T> filter) default {
+        return ParallelIterables.noneMatch(this, filter);
+    }
 
     /**
      * Returns {@code true} if all of the elements match the provided predicate.
@@ -107,11 +131,17 @@
      * matching elements.
      * @return {@code true} if all elements returned {@code true} for the provided predicate.
      */
-    public boolean allMatch(Predicate<? super T> filter) default ParallelIterables.allMatch;
+    public boolean allMatch(Predicate<? super T> filter) default {
+        return ParallelIterables.allMatch(this, filter);
+    }
 
     // public ParallelIterable<T> sorted() default Iterables.sorted;
 
-    public ParallelIterable<T> sorted(Comparator<? super T> comparator) default ParallelIterables.sorted;
+    public ParallelIterable<T> sorted(Comparator<? super T> comparator) default {
+        return ParallelIterables.sorted(this, comparator);
+    }
 
-    public ParallelIterable<T> uniqueElements() default ParallelIterables.uniqueElements;
+    public ParallelIterable<T> uniqueElements() default {
+        return ParallelIterables.uniqueElements(this);
+    }
 }
--- a/src/share/classes/java/util/functions/Block.java	Tue Nov 29 10:44:18 2011 -0800
+++ b/src/share/classes/java/util/functions/Block.java	Fri Dec 16 16:26:32 2011 -0800
@@ -56,7 +56,9 @@
      * @return a Block which performs in sequence the {@code apply} method of
      * this Block and the {@code apply} method of the specified Block operation
      */
-    Block<T> chain(Block<? super T> second) default Blocks.chain;
+    Block<T> chain(Block<? super T> second) default {
+        return Blocks.chain(this, second);
+    }
 
     /**
      * Returns a Block which performs in sequence the {@code apply} methods of
@@ -68,7 +70,9 @@
      * this Block and the {@code apply} methods of the specified Block
      * operations
      */
-    Block<T> chain(Block<? super T>... sequence) default Blocks.chain;
+    Block<T> chain(Block<? super T>... sequence) default {
+        return Blocks.chain(this, sequence);
+    }
 
     /**
      * Returns a Block which performs in sequence the {@code apply} methods of
@@ -80,7 +84,9 @@
      * this Block and the {@code apply} methods of the specified Block
      * operations
      */
-    Block<T> chain(Iterable<? extends Block<? super T>> sequence) default Blocks.chain;
+    Block<T> chain(Iterable<? extends Block<? super T>> sequence) default {
+        return Blocks.chain(this, sequence);
+    }
 
     /**
      * Returns a Block which repeatedly performs the {@code apply} method of
@@ -90,7 +96,9 @@
      * @return a Block which repeatedly performs the {@code apply} method of
      * this Block.
      */
-    Block<T> repeat(int count) default Blocks.repeat;
+    Block<T> repeat(int count) default {
+        return Blocks.repeat(this, count);
+    }
 
     /**
      * Returns a Block which repeatedly performs the {@code apply} method of
@@ -101,7 +109,9 @@
      * @return a Block which repeatedly performs the {@code apply} method of
      * this Block.
      */
-    Block<T> whileRepeat(Predicate<? super T> decider) default Blocks.whileRepeat;
+    Block<T> whileRepeat(Predicate<? super T> decider) default {
+        return Blocks.whileRepeat(this, decider);
+    }
 
     /**
      * Returns a Block which repeatedly performs the {@code apply} method of
@@ -112,5 +122,7 @@
      * @return a Block which repeatedly performs the {@code apply} method of
      * this Block.
      */
-    Block<T> repeatUntil(Predicate<? super T> decider) default Blocks.repeatUntil;
+    Block<T> repeatUntil(Predicate<? super T> decider) default {
+        return Blocks.repeatUntil(this, decider);
+    }
 }
--- a/src/share/classes/java/util/functions/Mapper.java	Tue Nov 29 10:44:18 2011 -0800
+++ b/src/share/classes/java/util/functions/Mapper.java	Fri Dec 16 16:26:32 2011 -0800
@@ -78,5 +78,7 @@
      * @return A mapper which performs both the original mapping followed by
      * a second mapping.
      */
-    public <V> Mapper<T, V> compose(Mapper<? super U, ? extends V> after) default Mappers.chain;
+    public <V> Mapper<T, V> compose(Mapper<? super U, ? extends V> after) default {
+        return Mappers.chain(this, after);
+    }
 }
--- a/src/share/classes/java/util/functions/Predicate.java	Tue Nov 29 10:44:18 2011 -0800
+++ b/src/share/classes/java/util/functions/Predicate.java	Fri Dec 16 16:26:32 2011 -0800
@@ -73,7 +73,9 @@
      * @return a new predicate which returns {@code true} only if both
      * predicates return {@code true}.
      */
-    Predicate<T> and(Predicate<? super T> p) default Predicates.and;
+    Predicate<T> and(Predicate<? super T> p) default {
+        return Predicates.and(this, p);
+    }
 
     /**
      * Create a predicate which evaluates to {@code true} only if this predicate
@@ -84,14 +86,18 @@
      * @return a new predicate which returns {@code true} only if all
      * predicates return {@code true}.
      */
-    Predicate<T> and(Predicate<? super T> ... p) default Predicates.and;
+    Predicate<T> and(Predicate<? super T> ... p) default {
+        return Predicates.and(this, p);
+    }
 
     /**
      * Create a predicate which negates the result of this predicate.
      *
      * @return a new predicate who's result is always the opposite of this predicate.
      */
-    Predicate<T> negate() default Predicates.negate;
+    Predicate<T> negate() default {
+        return Predicates.negate(this);
+    }
 
     /**
      * Create a predicate which evaluates to {@code true} if either this
@@ -102,7 +108,9 @@
      * @return a new predicate which returns {@code true} if either predicate
      * returns {@code true}.
      */
-    Predicate<T> or(Predicate<? super T> p) default Predicates.or;
+    Predicate<T> or(Predicate<? super T> p) default {
+        return Predicates.or(this, p);
+    }
 
     /**
      * Create a predicate which evaluates to {@code true} if this predicate
@@ -113,7 +121,9 @@
      * @return a new predicate which returns {@code true} if any component
      * predicate returns {@code true}.
      */
-    Predicate<T> or(Predicate<? super T> ... p) default Predicates.or;
+    Predicate<T> or(Predicate<? super T> ... p) default {
+        return Predicates.or(this, p);
+    }
 
     /**
      * Creates a predicate that evaluates to {@code true} if all or none of the
@@ -124,7 +134,9 @@
      * @return  a predicate that evaluates to {@code true} if all or none of the
      * component predicates evaluate to {@code true}
      */
-    Predicate<T> xor(Predicate<? super T> p) default Predicates.xor;
+    Predicate<T> xor(Predicate<? super T> p) default {
+        return Predicates.xor(this, p);
+    }
 
     /**
      * Creates a predicate that evaluates to {@code true} if all or none of the
@@ -135,5 +147,7 @@
      * @return  a predicate that evaluates to {@code true} if all or none of the
      * component predicates evaluate to {@code true}
      */
-    Predicate<T> xor(Predicate<? super T> ... p) default Predicates.xor;
+    Predicate<T> xor(Predicate<? super T> ... p) default {
+        return Predicates.xor(this, p);
+    }
 }
--- a/test/java/lang/Iterables/LambdasTests.java	Tue Nov 29 10:44:18 2011 -0800
+++ b/test/java/lang/Iterables/LambdasTests.java	Fri Dec 16 16:26:32 2011 -0800
@@ -41,55 +41,55 @@
    public static void testForEach() {
        AtomicInteger result = new AtomicInteger();
        List<Integer> list = Arrays.asList(1,2,3,4);
-       
+
        list.forEach(x -> {result.getAndIncrement();});
-       
+
        equal(list.size(), result.get());
    }
-   
+
    public static void testFilter() {
        List<Integer> list = Arrays.asList(1,1,2,2);
-       
+
        Iterator<Integer> filtered= list.filter(x -> 0 == x % 2).iterator();
-       
+
        int count = 0;
        while(filtered.hasNext()) {
            Integer each = filtered.next();
            check(0 == (each % 2));
            count++;
        }
-       
+
        equal(2, count);
    }
-   
+
    public static void testMap() {
        List<Integer> list = Arrays.asList(1,1,2,2);
-       
+
        Iterator<Integer> mapped= list.map(x -> x * 2).iterator();
-       
+
        int count = 0;
        while(mapped.hasNext()) {
            Integer each = mapped.next();
            check(0 == (each % 2));
            count++;
        }
-       
+
        equal(4, count);
    }
-   
+
    public static void testReduce() {
        List<Integer> list = Arrays.asList(1,1,1,1);
-       
+
        Integer result = list.reduce(0, (base, x) -> base + x);
-                    
+
        equal(4, result);
    }
-   
+
    public static void testFilterMap() {
        List<Integer> list = Arrays.asList(1,1,2,2);
-       
+
        Iterator<Integer> mapped= list.filterMap(x -> 1 == x, x -> x * 2).iterator();
-       
+
        int count = 0;
        while(mapped.hasNext()) {
            Integer each = mapped.next();
@@ -97,28 +97,28 @@
            check(1 == (each / 2));
            count++;
        }
-       
+
        equal(2, count);
    }
-   
+
    public static void testMapReduce() {
        List<Integer> list = Arrays.asList(1,1,1,1);
-       
-       Integer result = list.mapReduce(x -> x * 2, 0, (base, x) -> base + x);
-                    
+
+       int result = list.mapReduce((Integer x) -> x * 2, 0, (int base, int x) -> base + x);
+
        equal(8, result);
    }
-   
+
    public static void testFilterMapReduce() {
        List<Integer> list = Arrays.asList(1,1,1,1,2,2,2,2);
-       
+
        Predicate<Integer> filter = x -> 0 == x % 2;
        Mapper<Integer,Integer> mapper = x -> x * 2;
        Operator<Integer> reducer = (base, x) -> base + x;
-       
-       Integer result = list.filterMapReduce(filter, mapper, Integer.valueOf(0), reducer);
-                    
-       equal(8, result);
+
+       int result = list.filterMapReduce(filter, mapper, Integer.valueOf(0), reducer);
+
+       equal(16, result);
    }
 
    public static void RealMain(String ... args) {
--- a/test/java/util/Iterators/LambdasTests.java	Tue Nov 29 10:44:18 2011 -0800
+++ b/test/java/util/Iterators/LambdasTests.java	Fri Dec 16 16:26:32 2011 -0800
@@ -41,58 +41,63 @@
    public static void testForEach() {
        AtomicInteger result = new AtomicInteger();
        List<Integer> list = Arrays.asList(1,2,3,4);
-       
+
        Iterators.forEach(list.iterator(), x -> {result.getAndIncrement();});
-       
+
        equal(list.size(), result.get());
    }
-   
+
    public static void testFilter() {
        List<Integer> list = Arrays.asList(1,1,2,2);
-       
+
        Iterator<Integer> filtered= Iterators.filter(list.iterator(), x -> 0 == x % 2);
-       
+
        int count = 0;
        while(filtered.hasNext()) {
            Integer each = filtered.next();
            check(0 == (each % 2));
            count++;
        }
-       
+
        equal(2, count);
    }
-   
+
    public static void testMap() {
        List<Integer> list = Arrays.asList(1,1,2,2);
-       
+
        Iterator<Integer> mapped= Iterators.map(list.iterator(), x -> x * 2);
-       
+
        int count = 0;
        while(mapped.hasNext()) {
            Integer each = mapped.next();
            check(0 == (each % 2));
            count++;
        }
-       
+
        equal(4, count);
    }
-   
+
    public static void testReduce() {
        List<Integer> list = Arrays.asList(1,1,1,1);
-       
+
        Integer result = Iterators.reduce(list.iterator(), 0, (base, x) -> base + x);
-                    
+
        equal(4, result);
+
+
+
+
+
    }
-   
+
    public static void testMapReduce() {
        List<Integer> list = Arrays.asList(1,1,1,1);
-       
-       Integer result = Iterators.mapReduce(list.iterator(), x -> x * 2, 0, (base, x) -> base + x);
-                    
+
+       int result = Iterators.mapReduce(list.iterator(), (Integer x) -> x * 2, 0, (Integer base, Integer x) -> base + x);
+
        equal(8, result);
    }
-   
+
    public static void RealMain(String ... args) {
         testForEach();
         testFilter();