OpenJDK / lambda / lambda / jdk
changeset 6412:ef5e16bf1045
rename java.util.functions -> java.util.function
line wrap: on
line diff
--- a/make/docs/CORE_PKGS.gmk Thu Nov 15 13:36:22 2012 -0500 +++ b/make/docs/CORE_PKGS.gmk Thu Nov 15 10:55:22 2012 -0800 @@ -131,7 +131,7 @@ java.util.concurrent \ java.util.concurrent.atomic \ java.util.concurrent.locks \ - java.util.functions \ + java.util.function \ java.util.jar \ java.util.logging \ java.util.prefs \
--- a/make/java/java/Makefile Thu Nov 15 13:36:22 2012 -0500 +++ b/make/java/java/Makefile Thu Nov 15 10:55:22 2012 -0800 @@ -63,7 +63,7 @@ include FILES_java.gmk include Exportedfiles.gmk -AUTO_FILES_JAVA_DIRS = java/util/concurrent java/util/functions java/util/streams +AUTO_FILES_JAVA_DIRS = java/util/concurrent java/util/function java/util/streams ifeq ($(PLATFORM),windows) FILES_java += java/io/Win32FileSystem.java \
--- a/makefiles/docs/CORE_PKGS.gmk Thu Nov 15 13:36:22 2012 -0500 +++ b/makefiles/docs/CORE_PKGS.gmk Thu Nov 15 10:55:22 2012 -0800 @@ -131,7 +131,7 @@ java.util.concurrent \ java.util.concurrent.atomic \ java.util.concurrent.locks \ - java.util.functions \ + java.util.function \ java.util.jar \ java.util.logging \ java.util.prefs \
--- a/src/share/classes/java/lang/CharSequence.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/lang/CharSequence.java Thu Nov 15 10:55:22 2012 -0800 @@ -28,7 +28,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Sized; -import java.util.functions.Block; +import java.util.function.Block; import java.util.streams.Stream; import java.util.streams.StreamOpFlags; import java.util.streams.Streams; @@ -134,7 +134,7 @@ * ordinary BMP characters, unpaired surrogates, and undefined code units, * are zero-extended to @{code int} values which are then passed * to the stream. - * + * * If the sequence is mutated while the stream is being read, the result * is undefined. *
--- a/src/share/classes/java/lang/Iterable.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/lang/Iterable.java Thu Nov 15 10:55:22 2012 -0800 @@ -24,8 +24,8 @@ */ package java.lang; -import java.util.*; -import java.util.functions.*; +import java.util.Iterator; +import java.util.function.Block; /** * Implementing this interface allows an object to be the target of
--- a/src/share/classes/java/lang/ThreadLocal.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/lang/ThreadLocal.java Thu Nov 15 10:55:22 2012 -0800 @@ -27,7 +27,7 @@ import java.lang.ref.*; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; -import java.util.functions.Factory; +import java.util.function.Factory; /** * This class provides thread-local variables. These variables differ from @@ -68,15 +68,15 @@ * thread-local instances are subject to garbage collection (unless other * references to these copies exist). * - * The initial value of the variable is set by (1) calling the - * {@code initialValue method}, (2) obtaining it from a {@code Factory<T>} + * The initial value of the variable is set by (1) calling the + * {@code initialValue method}, (2) obtaining it from a {@code Factory<T>} * which has been provided via the * constructor, or (3) by calling the {@code set} method. - * - * If (1) is used and an initial value other than the default of null is required, - * the {@code initialValue} method is typically overridden with an + * + * If (1) is used and an initial value other than the default of null is required, + * the {@code initialValue} method is typically overridden with an * anonymous-inner class. - * + * * @author Josh Bloch and Doug Lea * @since 1.2 */ @@ -122,7 +122,7 @@ /** * Returns the current thread's "initial value" for this * thread-local variable unless a @{code Factory<T}} has been passed - * to the constructor, in which case the Factory is consulted in + * to the constructor, in which case the Factory is consulted in * preference to this method. This method will be invoked the first * time a thread accesses the variable with the {@link #get} * method, unless the thread previously invoked the {@link #set} @@ -148,16 +148,16 @@ /** * Creates a thread local variable using the supplied factory. When - * this constructor is used, the initial value is determined by + * this constructor is used, the initial value is determined by * invoking the @{code make} method on the factory. - * + * * @param factory the factory to be used to determine the initial value */ public ThreadLocal( Factory<T> factory ) { Objects.requireNonNull( factory ); this.factory = factory; } - + /** * Returns the value in the current thread's copy of this * thread-local variable. If the variable has no value for the
--- a/src/share/classes/java/util/Collection.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/Collection.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,7 +25,7 @@ package java.util; -import java.util.functions.Predicate; +import java.util.function.Predicate; import java.util.streams.Stream; import java.util.streams.StreamOpFlags; import java.util.streams.Streamable;
--- a/src/share/classes/java/util/Comparators.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/Comparators.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,10 +25,10 @@ package java.util; import java.io.Serializable; -import java.util.functions.DoubleMapper; -import java.util.functions.IntMapper; -import java.util.functions.LongMapper; -import java.util.functions.Mapper; +import java.util.function.DoubleMapper; +import java.util.function.IntMapper; +import java.util.function.LongMapper; +import java.util.function.Mapper; /** * This class consists of {@code static} utility methods for comparators. Mostly
--- a/src/share/classes/java/util/Iterables.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/Iterables.java Thu Nov 15 10:55:22 2012 -0800 @@ -24,7 +24,6 @@ */ package java.util; -import java.util.functions.*; import java.util.streams.ops.FilterOp; /**
--- a/src/share/classes/java/util/Iterator.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/Iterator.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,7 +25,7 @@ package java.util; -import java.util.functions.Block; +import java.util.function.Block; /** * An iterator over a collection. {@code Iterator} takes the place of
--- a/src/share/classes/java/util/Iterators.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/Iterators.java Thu Nov 15 10:55:22 2012 -0800 @@ -24,7 +24,8 @@ */ package java.util; -import java.util.functions.*; +import java.util.function.Predicate; +import java.util.function.Mapper; /** * Utilities for Iterators. All of these methods consume elements from the iterators passed to them!
--- a/src/share/classes/java/util/Map.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/Map.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,7 +25,7 @@ package java.util; -import java.util.functions.BiBlock; +import java.util.function.BiBlock; import java.util.streams.Streamable; import java.util.streams.Streams;
--- a/src/share/classes/java/util/Optional.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/Optional.java Thu Nov 15 10:55:22 2012 -0800 @@ -24,8 +24,8 @@ */ package java.util; -import java.util.functions.Block; -import java.util.functions.Factory; +import java.util.function.Block; +import java.util.function.Factory; /** * A return object which may or may not contain a value. If a value is present
--- a/src/share/classes/java/util/concurrent/atomic/AtomicInteger.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/concurrent/atomic/AtomicInteger.java Thu Nov 15 10:55:22 2012 -0800 @@ -34,7 +34,7 @@ */ package java.util.concurrent.atomic; -import java.util.functions.IntUnaryOperator; +import java.util.function.IntUnaryOperator; import sun.misc.Unsafe; /** @@ -139,10 +139,10 @@ /** * Sets the value by applying the supplied operator to the old value, * and updating it atomically as in {@link #compareAndSet(int, int)}. - * - * If the update results in a collision, we back off and retry the update - * (using the new current value) until successful. - * + * + * If the update results in a collision, we back off and retry the update + * (using the new current value) until successful. + * * @param op the operator to use to compute the new value * @return the old value */ @@ -158,10 +158,10 @@ /** * Sets the value by applying the supplied operator to the old value, * and updating it atomically as in {@link #compareAndSet(int, int)}. - * - * If the update results in a collision, we back off and retry the update - * (using the new current value) until successful. - * + * + * If the update results in a collision, we back off and retry the update + * (using the new current value) until successful. + * * @param op the operator to use to compute the new value * @return the new value */ @@ -173,7 +173,7 @@ } while (!compareAndSet(oldValue, newValue)); return newValue; } - + /** * Atomically sets the value to the given updated value * if the current value {@code ==} the expected value.
--- a/src/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java Thu Nov 15 10:55:22 2012 -0800 @@ -40,8 +40,8 @@ import java.security.AccessController; import java.security.PrivilegedExceptionAction; import java.security.PrivilegedActionException; -import java.util.functions.IntUnaryOperator; -import java.util.functions.UnaryOperator; +import java.util.function.IntUnaryOperator; +import java.util.function.UnaryOperator; /** * A reflection-based utility that enables atomic updates to
--- a/src/share/classes/java/util/concurrent/atomic/AtomicLong.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/concurrent/atomic/AtomicLong.java Thu Nov 15 10:55:22 2012 -0800 @@ -34,7 +34,7 @@ */ package java.util.concurrent.atomic; -import java.util.functions.LongUnaryOperator; +import java.util.function.LongUnaryOperator; import sun.misc.Unsafe; /** @@ -149,14 +149,14 @@ public final boolean compareAndSet(long expect, long update) { return unsafe.compareAndSwapLong(this, valueOffset, expect, update); } - + /** * Sets the value by applying the supplied operator to the old value, * and updating it atomically as in {@link #compareAndSet(long, long)}. - * - * If the update results in a collision, we back off and retry the update - * (using the new current value) until successful. - * + * + * If the update results in a collision, we back off and retry the update + * (using the new current value) until successful. + * * @param op the operator to use to compute the new value * @return the new value */ @@ -172,10 +172,10 @@ /** * Sets the value by applying the supplied operator to the old value, * and updating it atomically as in {@link #compareAndSet(long, long)}. - * - * If the update results in a collision, we back off and retry the update - * (using the new current value) until successful. - * + * + * If the update results in a collision, we back off and retry the update + * (using the new current value) until successful. + * * @param op the operator to use to compute the new value * @return the old value */ @@ -187,7 +187,7 @@ } while (!compareAndSet(oldValue, newValue)); return oldValue; } - + /** * Atomically sets the value to the given updated value * if the current value {@code ==} the expected value.
--- a/src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java Thu Nov 15 10:55:22 2012 -0800 @@ -40,8 +40,8 @@ import java.security.AccessController; import java.security.PrivilegedExceptionAction; import java.security.PrivilegedActionException; -import java.util.functions.IntUnaryOperator; -import java.util.functions.LongUnaryOperator; +import java.util.function.IntUnaryOperator; +import java.util.function.LongUnaryOperator; /** * A reflection-based utility that enables atomic updates to
--- a/src/share/classes/java/util/concurrent/atomic/AtomicReference.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/concurrent/atomic/AtomicReference.java Thu Nov 15 10:55:22 2012 -0800 @@ -34,7 +34,7 @@ */ package java.util.concurrent.atomic; -import java.util.functions.UnaryOperator; +import java.util.function.UnaryOperator; import sun.misc.Unsafe; /** @@ -118,10 +118,10 @@ /** * Sets the value by applying the supplied operator to the old value, * and updating it atomically as in {@link #compareAndSet(V, V)}. - * - * If the update results in a collision, we back off and retry the update - * (using the new current value) until successful. - * + * + * If the update results in a collision, we back off and retry the update + * (using the new current value) until successful. + * * @param op the operator to use to compute the new value * @return the new value */ @@ -137,10 +137,10 @@ /** * Sets the value by applying the supplied operator to the old value, * and updating it atomically as in {@link #compareAndSet(V, V)}. - * - * If the update results in a collision, we back off and retry the update - * (using the new current value) until successful. - * + * + * If the update results in a collision, we back off and retry the update + * (using the new current value) until successful. + * * @param op the operator to use to compute the new value * @return the old value */ @@ -152,7 +152,7 @@ } while (!compareAndSet(oldValue, newValue)); return oldValue; } - + /** * Atomically sets the value to the given updated value * if the current value {@code ==} the expected value.
--- a/src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java Thu Nov 15 10:55:22 2012 -0800 @@ -40,7 +40,7 @@ import java.security.AccessController; import java.security.PrivilegedExceptionAction; import java.security.PrivilegedActionException; -import java.util.functions.UnaryOperator; +import java.util.function.UnaryOperator; /** * A reflection-based utility that enables atomic updates to
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/BiBlock.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2012, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +/** + * BiBlock + * + * @author Brian Goetz + */ +/** + * Performs operations upon an input object which may modify that object and/or + * external state (other objects). + * + * <p>All block implementations are expected to: + * <ul> + * <li>When used for aggregate operations upon many elements blocks + * should not assume that the {@code apply} operation will be called upon + * elements in any specific order.</li> + * </ul> + * + * @param <L> the type of input objects provided to {@code apply}. + * @param <R> the type of input objects provided to {@code apply}. + */ +public interface BiBlock<L, R> { + + /** + * Performs operations upon the provided object which may modify that object + * and/or external state. + * + * @param l an input object + */ + void apply(L l, R r); + + /** + * Returns a Block which performs in sequence the {@code apply} methods of + * multiple Blocks. This Block's {@code apply} method is performed followed + * by the {@code apply} method of the specified Block operation. + * + * @param other an additional Block which will be chained after this Block + * @return a Block which performs in sequence the {@code apply} method of + * this Block and the {@code apply} method of the specified Block operation + */ + public default BiBlock<L, R> chain(BiBlock<? super L, ? super R> other) { + return (l, r) -> { apply(l, r); other.apply(l, r); }; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/BiMapper.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2010, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +/** + * Given input objects maps to an appropriate output object. A mapper may + * variously provide a mapping between types, object instances or keys and + * values or any other form of transformation upon the input. + * + * <p/>All mapper implementations are expected to: + * <ul> + * <li>Provide stable results such that for any {@code t} the result of two + * {@code map} operations are always equivalent. ie.<pre> + * Foo one = mapper.map(a); + * Foo two = mapper.map(a); + * + * assert one.equals(two) && two.equals(one); + * </pre></li> + * <li>Equivalent input objects should map to equivalent output objects. ie.<pre> + * assert a.equals(b); // a and b are equivalent + * + * Foo x = mapper.map(a); + * Foo y = mapper.map(b); + * + * assert x.equals(y); // their mapped results should be as equivalent. + * </pre></li> + * <li>The mapper should not modify the input object in any way that would + * change the mapping.</li> + * <li>When used for aggregate operations upon many elements mappers + * should not assume that the {@code map} operation will be called upon elements + * in any specific order.</li> + * </ul> + * + * @param <R> the type of output objects from {@code map} operation. May be the + * @param <T> the type of input objects provided to the {@code map} operation. + * @param <U> the type of input objects provided to the {@code map} operation. + * same type as either {@code <T>} or {@code <U>}. + */ +public interface BiMapper<R, T, U> { + + /** + * Map the provided input objects to an appropriate output object. + * + * @param t an object to be mapped. + * @param u another object to be mapped. + * @return the mapped output object. + */ + R map(T t, U u); + + /** + * Combine with another mapper producing a mapper which preforms both + * mappings. + * + * @param <W> Type of output objects from the combined mapper. May be the + * same type as {@code <U>}. + * @param after An additional mapping to be applied to the result of this + * mapping. + * @return A mapper which performs both the original mapping followed by + * a second mapping. + */ + public default <W> BiMapper<W, T, U> compose(Mapper<? extends W, ? super R> after) { + throw new UnsupportedOperationException("Not yet implemented."); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/BiPredicate.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2010, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package java.util.function; + +/** + * Determines if the input object matches some criteria. + * + * <p>All predicate implementations are expected to: + * <ul> + * <li>Provide stable results such that for any {@code t} the result of two + * {@code eval} operations are always equivalent. ie.<pre> + * boolean one = predicate.eval(a); + * boolean two = predicate.eval(a); + * + * assert one == two; + * </pre></li> + * <li>Equivalent input objects should map to equivalent output objects. ie.<pre> + * assert a.equals(b); // a and b are equivalent + * + * boolean x = predicate.eval(a); + * boolean y = predicate.eval(ab; + * + * assert x == y; // their eval results should be the same. + * </pre></li> + * <li>The predicate should not modify the input object in any way that would + * change the evaluation.</li> + * <li>When used for aggregate operations upon many elements predicates + * should not assume that the {@code eval} operation will be called upon + * elements in any specific order.</li> + * </ul> + * + * @param <L> the type of input objects provided to {@code test}. + * @param <R> the type of input objects provided to {@code test}. + */ +public interface BiPredicate<L,R> { + + /** + * Return {@code true} if the inputs match some criteria. + * + * @param l an input object. + * @param r an input object. + * @return {@code true} if the inputs match some criteria. + */ + boolean test(L l, R r); + + /** + * Create a predicate which evaluates to {@code true} only if this predicate + * and the provided predicate both evaluate to {@code true}. If this + * predicate returns {@code false} then the remaining predicate is not + * evaluated. + * + * @return a new predicate which returns {@code true} only if both + * predicates return {@code true}. + */ + default BiPredicate<L,R> and(BiPredicate<? super L,? super R> p) { + throw new UnsupportedOperationException("Not yet implemented"); + } + + /** + * Create a predicate which negates the result of this predicate. + * + * @return a new predicate who's result is always the opposite of this predicate. + */ + default BiPredicate<L,R> negate() { + throw new UnsupportedOperationException("Not yet implemented"); + } + + /** + * Create a predicate which evaluates to {@code true} if either this + * predicate or the provided predicate evaluates to {@code true}. If this + * predicate returns {@code true} then the remaining predicate is not + * evaluated. + * + * @return a new predicate which returns {@code true} if either predicate + * returns {@code true}. + */ + default BiPredicate<L,R> or(BiPredicate<? super L,? super R> p) { + throw new UnsupportedOperationException("Not yet implemented"); + } + + /** + * Creates a predicate that evaluates to {@code true} 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. + * + * @return a predicate that evaluates to {@code true} if all or none of the + * component predicates evaluate to {@code true} + */ + default BiPredicate<L,R> xor(BiPredicate<? super L,? super R> p) { + throw new UnsupportedOperationException("Not yet implemented"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/BinaryOperator.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2010, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +/** + * Combines two operands. + * + * <p>All Operator implementations are expected to: + * <ul> + * <li>Provide stable + * results such that for any {@code a} and {@code b} the result of two {@code eval} + * operations are always equivalent. ie.<pre> + * Foo one = operator.eval(a,b); + * Foo two = operator.eval(a,b); + * + * assert one.equals(two) && two.equals(one); + * </pre></li> + * + * <li>The operator should not modify the input object in any way + * that would change the result.</li> + * + * <li>When used for aggregate operations + * upon many elements operators should not assume that the {@code eval} + * operation will be called upon elements in any specific order ie.<pre> + * Foo one = operator.eval(a,operator.eval(b,c)); + * Foo two = operator.eval(b,operator.eval(a,c)); + * + * assert one.equals(two) && two.equals(one); + * </pre></li> + * </ul> + * + * @param <T> the type of input objects provided to {@code eval} and the result. + */ +public interface BinaryOperator<T> extends Combiner<T, T, T> { + + public T operate(T left, T right); + + @Override + public default T combine(T t1, T t2) { + return operate(t1, t2); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/Block.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,38 @@ +package java.util.function; + +/** + * Performs operations upon an input object which may modify that object and/or + * external state (other objects). + * + * <p>All block implementations are expected to: + * <ul> + * <li>When used for aggregate operations upon many elements blocks + * should not assume that the {@code apply} operation will be called upon + * elements in any specific order.</li> + * </ul> + * + * @param <T> The type of input objects to {@code apply}. + */ +public interface Block<T> { + + /** + * Performs operations upon the provided object which may modify that object + * and/or external state. + * + * @param t an input object + */ + void apply(T t); + + /** + * Returns a Block which performs in sequence the {@code apply} methods of + * multiple Blocks. This Block's {@code apply} method is performed followed + * by the {@code apply} method of the specified Block operation. + * + * @param other an additional Block which will be chained after this Block + * @return a Block which performs in sequence the {@code apply} method of + * this Block and the {@code apply} method of the specified Block operation + */ + public default Block<T> chain(Block<? super T> other) { + return (T t) -> { apply(t); other.apply(t); }; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/Combiner.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +/** + * Combiner + * + * @author Brian Goetz + */ +public interface Combiner<R, T, U> { + R combine(T t, U u); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/DoubleBinaryOperator.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +/** + * DoubleBiOperator + */ +public interface DoubleBinaryOperator { + public double eval(double left, double right); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/DoubleMapper.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2010, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +/** + * Given an input object maps to an appropriate double value; this is the + * double-bearing specialization for {@link java.util.function.Mapper}. + * + * <p/>Like Mapper, DoubleMapper implementations are expected to: + * <ul> + * <li>Provide stable results such that for any {@code t} the result of two + * {@code map} operations are always equivalent. ie.<pre> + * double one = mapper.map(a); + * double two = mapper.map(a); + * + * assert one == two; + * </pre></li> + * <li>Equivalent input objects should map to equivalent output objects. ie.<pre> + * assert a.equals(b); // a and b are equivalent + * + * double x = mapper.map(a); + * double y = mapper.map(b); + * + * assert x == y; // their mapped results should be as equivalent. + * </pre></li> + * <li>The mapper should not modify the input object in any way that would + * change the mapping.</li> + * <li>When used for aggregate operations upon many elements mappers + * should not assume that the {@code map} operation will be called upon elements + * in any specific order.</li> + * </ul> + * + * @param <T> the type of input objects provided to the {@code map} operation. + */ +public interface DoubleMapper<T> { + + /** + * Map the provided input object to an appropriate output object. + * + * @param t the input object to be mapped. + * @return the mapped output value. + */ + double map(T t); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/DoubleUnaryOperator.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2012, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +/** + * Operator on a single {@code double} operand. + * + * <p>All Operator implementations are expected to: + * <ul> + * <li>Provide stable + * results such that for any {@code a} the result of two {@code operate} + * operations are always equivalent. i.e.<pre> + * Foo one = operator.operate(a); + * Foo two = operator.operate(a); + * + * assert one.equals(two) && two.equals(one); + * </pre></li> + * + * <li>The operator should not modify the input object in any way + * that would change the result.</li> + * + * </ul> + * + * @author Jim Gish + * @since 1.8 + * + */ +public interface DoubleUnaryOperator { + + /** + * The implementation of the method is used to compute a new value + * from the old value. + * + * @param operand the old value + * @return the new value + */ + public double operate(double operand); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/Factory.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2010, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +/** + * aka Source and Producer + * + * <p>All Factory implementations are expected to: + * <ul> + * <li></li> + * </ul> + * + * @param <T> The type of objects returned by {@code create}. + */ +public interface Factory<T> { + + /** + * Returns an object. + * + * @return an object. + */ + T make(); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/FlatMapper.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2012, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +/** + * Map an element to zero or more results and add all results to a sink. + * + * @author Brian Goetz + */ +public interface FlatMapper<R, T> { + /** + * Map {@code element} and add all of the results to {@code sink}. + * + * @param sink Destination for mapped elements. + * @param element The element to be mapped. + */ + void flatMapInto(Block<? super R> sink, T element); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/IntBinaryOperator.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +/** + * IntBinaryOperator + */ +public interface IntBinaryOperator { + public int eval(int left, int right); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/IntMapper.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2010, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +/** + * Given an input object maps to an appropriate integer value; this is the + * int-bearing specialization for {@link Mapper}. + * + * <p/>Like Mapper, IntMapper implementations are expected to: + * <ul> + * <li>Provide stable results such that for any {@code t} the result of two + * {@code map} operations are always equivalent. ie.<pre> + * int one = mapper.map(a); + * int two = mapper.map(a); + * + * assert one == two; + * </pre></li> + * <li>Equivalent input objects should map to equivalent output objects. ie.<pre> + * assert a.equals(b); // a and b are equivalent + * + * int x = mapper.map(a); + * int y = mapper.map(b); + * + * assert x == y; // their mapped results should be as equivalent. + * </pre></li> + * <li>The mapper should not modify the input object in any way that would + * change the mapping.</li> + * <li>When used for aggregate operations upon many elements mappers + * should not assume that the {@code map} operation will be called upon elements + * in any specific order.</li> + * </ul> + * + * @param <T> the type of input objects provided to the {@code map} operation. + */ +public interface IntMapper<T> { + + /** + * Map the provided input object to an appropriate output object. + * + * @param t the input object to be mapped. + * @return the mapped output value. + */ + int map(T t); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/IntUnaryOperator.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2012, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +/** + * Operator on a single {@code int} operand. + * + * <p>All Operator implementations are expected to: + * <ul> + * <li>Provide stable + * results such that for any {@code a} the result of two {@code operate} + * operations are always equivalent. i.e.<pre> + * Foo one = operator.operate(a); + * Foo two = operator.operate(a); + * + * assert one.equals(two) && two.equals(one); + * </pre></li> + * + * <li>The operator should not modify the input object in any way + * that would change the result.</li> + * + * </ul> + * + * @author Jim Gish + * @since 1.8 + * + */ +public interface IntUnaryOperator { + + /** + * The implementation of the method is used to compute a new value + * from the old value. + * + * @param operand the old value + * @return the new value + */ + public int operate(int operand); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/LongBinaryOperator.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +/** + * LongBinaryOperator + */ +public interface LongBinaryOperator { + public long eval(long left, long right); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/LongMapper.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2010, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +/** + * Given an input object maps to an appropriate long value; this is the + * long-bearing specialization for {@link java.util.function.Mapper}. + * + * <p/>Like Mapper, LongMapper implementations are expected to: + * <ul> + * <li>Provide stable results such that for any {@code t} the result of two + * {@code map} operations are always equivalent. ie.<pre> + * long one = mapper.map(a); + * long two = mapper.map(a); + * + * assert one == two; + * </pre></li> + * <li>Equivalent input objects should map to equivalent output objects. ie.<pre> + * assert a.equals(b); // a and b are equivalent + * + * long x = mapper.map(a); + * long y = mapper.map(b); + * + * assert x == y; // their mapped results should be as equivalent. + * </pre></li> + * <li>The mapper should not modify the input object in any way that would + * change the mapping.</li> + * <li>When used for aggregate operations upon many elements mappers + * should not assume that the {@code map} operation will be called upon elements + * in any specific order.</li> + * </ul> + * + * @param <T> the type of input objects provided to the {@code map} operation. + */ +public interface LongMapper<T> { + + /** + * Map the provided input object to an appropriate output object. + * + * @param t the input object to be mapped. + * @return the mapped output value. + */ + long map(T t); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/LongUnaryOperator.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2012, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +/** + * Operator on a single {@code long} operand. + * + * <p>All Operator implementations are expected to: + * <ul> + * <li>Provide stable + * results such that for any {@code a} the result of two {@code operate} + * operations are always equivalent. i.e.<pre> + * Foo one = operator.operate(a); + * Foo two = operator.operate(a); + * + * assert one.equals(two) && two.equals(one); + * </pre></li> + * + * <li>The operator should not modify the input object in any way + * that would change the result.</li> + * + * </ul> + * + * @author Jim Gish + * @since 1.8 + * + */ +public interface LongUnaryOperator { + + /** + * The implementation of the method is used to compute a new value + * from the old value. + * + * @param operand the old value + * @return the new value + */ + public long operate(long operand); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/Mapper.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2010, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +/** + * Given an input object maps to an appropriate output object. A mapper may + * variously provide a mapping between types, object instances or keys and + * values or any other form of transformation upon the input. + * + * <p/>All mapper implementations are expected to: + * <ul> + * <li>Provide stable results such that for any {@code t} the result of two + * {@code map} operations are always equivalent. ie.<pre> + * Foo one = mapper.map(a); + * Foo two = mapper.map(a); + * + * assert one.equals(two) && two.equals(one); + * </pre></li> + * <li>Equivalent input objects should map to equivalent output objects. ie.<pre> + * assert a.equals(b); // a and b are equivalent + * + * Foo x = mapper.map(a); + * Foo y = mapper.map(b); + * + * assert x.equals(y); // their mapped results should be as equivalent. + * </pre></li> + * <li>The mapper should not modify the input object in any way that would + * change the mapping.</li> + * <li>When used for aggregate operations upon many elements mappers + * should not assume that the {@code map} operation will be called upon elements + * in any specific order.</li> + * </ul> + * + * @param <R> the type of output objects from {@code map} operation. May be the + * @param <T> the type of input objects provided to the {@code map} operation. + * same type as {@code <T>}. + */ +public interface Mapper<R, T> { + + /** + * Map the provided input object to an appropriate output object. + * + * @param t the input object to be mapped. + * @return the mapped output object. + */ + R map(T t); + + /** + * Combine with another mapper producing a mapper which preforms both + * mappings. + * + * @param <V> Type of output objects from the combined mapper. May be the + * same type as {@code <U>}. + * @param after An additional mapping to be applied to the result of this + * mapping. + * @return A mapper which performs both the original mapping followed by + * a second mapping. + */ + public default <V> Mapper<V, T> compose(Mapper<? extends V, ? super R> after) { + return Mappers.chain(this, after); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/Mappers.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,235 @@ +/* + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +import java.lang.reflect.Constructor; +import java.lang.reflect.UndeclaredThrowableException; +import java.util.Map; +import java.util.Objects; + +/** + * Static utility methods pertaining to {@code Mapper} instances. + * + * <p>All of the returned mappers are serializable if provided serializable + * parameters. + */ +public final class Mappers { + + /** + * A mapper which who's {@code map} method returns the provided + * input. + */ + private static final Mapper<Object, Object> IDENTITY = t -> t; + + /** + * A mapper which performs a mapping from an object to it's + * string representation. + */ + private static final Mapper<String, Object> STRING = String::valueOf; + + /** + * singleton utils + */ + private Mappers() { + throw new AssertionError("No instances!"); + } + + /** + * Returns a mapper which who's {@code map} method returns the provided + * input. Useful when a Mapper is required and {@code <T>} and {@code <U>} + * are the same type. + */ + public static <T> Mapper<T, T> identity() { + return (Mapper<T, T>) IDENTITY; + } + +// /** +// * Returns a mapper which who's {@code map} method returns a clone of the +// * provided input. +// */ +// public static <T> Mapper<T, T> cloneOf() { +// return t -> { +// try { +// return t.clone(); +// } catch (CloneNotSupportedException ex) { +// throw new UndeclaredThrowableException(ex); +// } +// }; +// } +// + /** + * Returns a mapper which performs a mapping from {@code <T>} to it's + * string representation. + * + * @param <T> Type of input values + * @return a mapper which performs a mapping from {@code <T>} to it's + * string representation + */ + public static <T> Mapper<String, T> string() { + return (Mapper<String, T>) STRING; + } + + /** + * Returns a mapper which performs a mapping from {@code <T>} to {@code <U>} + * followed by a mapping from {@code <U>} to {@code <V>}. + * + * @param <R> Type for final mapped values. May be the same type as + * {@code <U>}. + * @param <T> Type for input values + * @param <U> Type for intermediate mapped values. May be the same type as + * {@code <T>}. + * @param first Initial mapping from {@code <T>} to {@code <U>}. + * @param second additional mapping from {@code <U>} to {@code <V>}. + */ + public static <R, T, U> Mapper<R, T> chain( + Mapper<? extends U, ? super T> first, + Mapper<? extends R, ? super U> second) { + Objects.requireNonNull(first); + Objects.requireNonNull(second); + + return t -> second.map(first.map(t)); + } + + /** + * Returns a constant output regardless of input. + * + * @param constant The value to be returned by the {@code map} method. + * @return a mapper who's {@code map} method provides a constant result. + */ + public static <R, T> Mapper<R, T> constant(R constant) { + return t -> constant; + } + + /** + * A mapper that substitutes a single input value with a specified + * replacement. Input values are compared using {@code equals()}. + * + * @param <T> The type of values. + * @param subOut The input value to be substituted out. + * @param subIn The replacement value for matching inputs. + * @return a mapper that substitutes a single input value with a specified + * replacement. + */ + public static <T> Mapper<T, T> substitute(T subOut, T subIn) { + return t -> Objects.equals(subOut, t) ? subIn : t; + } + + /** + * Returns a new instance of {@code <U>} 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 mapper 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 <R, T> Mapper<R, T> 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); + } + }; + } + + /** + * Map according to the provided map. Attempting to map 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 map} method contract. + * + * @param <R> output type from mapping operation + * @param <T> input type to mapping operation + * @param map provides the mappings from {@code <T>} to {@code <U>} + * @throws IllegalArgumentException for all values of {@code <T>} not + * present in the map + */ + public static <R, T> Mapper<R, T> forMap(Map<? super T, ? extends R> map) { + Objects.requireNonNull(map); + + return t -> { + if (map.containsKey(t)) { + return map.get(t); + } else { + throw new IllegalArgumentException("unmappable <T> : " + t); + } + }; + } + + /** + * Map 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 map and care should be taken to avoid + * changes to the map during operation may produce results which violate the + * {@code map} method contract. + * + * @param <R> output type from mapping + * @param <T> input type to map + * @param map provides the mappings from {@code <T>} to {@code <U>} + * @param defaultValue the value returned by {@code map} method for + * {@code <T>} values not contained in the provided map + */ + public static <R, T> Mapper<R, T> forMap(Map<? super T, ? extends R> map, R defaultValue) { + Objects.requireNonNull(map); + + return t -> map.containsKey(t) ? map.get(t) : defaultValue; + } + + /** + * Map according to the provided predicate. Two output values are provided + * {@code forTrue} is returned if the predicate returns {@code true} + * otherwise the {@code forFalse} value is returned. + * + * @param <R> output type from mapping + * @param <T> input type to map + * @param predicate decides which value {@code map} method should return + * @param forTrue value to be returned for {@code true} predicate results + * @param forFalse value to be returned for {@code false} predicate results + * @return a Mapper who's {@code map} method provides results according to + * the provided predicate. + */ + public static <R, T> Mapper<R, T> forPredicate(Predicate<? super T> predicate, R forTrue, R forFalse) { + Objects.requireNonNull(predicate); + + return t -> predicate.test(t) ? forTrue : forFalse; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/Predicate.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2010, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package java.util.function; + +/** + * Determines if the input object matches some criteria. + * + * <p>All predicate implementations are expected to: + * <ul> + * <li>Provide stable results such that for any {@code t} the result of two + * {@code eval} operations are always equivalent. ie.<pre> + * boolean one = predicate.test(a); + * boolean two = predicate.test(a); + * + * assert one == two; + * </pre></li> + * <li>Equivalent input objects should map to equivalent output objects. ie.<pre> + * assert a.equals(b); // a and b are equivalent + * + * boolean x = predicate.test(a); + * boolean y = predicate.test(ab; + * + * assert x == y; // their test results should be the same. + * </pre></li> + * <li>The predicate should not modify the input object in any way that would + * change the evaluation.</li> + * <li>When used for aggregate operations upon many elements predicates + * should not assume that the {@code test} operation will be called upon + * elements in any specific order.</li> + * </ul> + * + * @param <T> the type of input objects provided to {@code test}. + */ +public interface Predicate<T> { + + /** + * Return {@code true} if the input object matches some criteria. + * + * @param t the input object. + * @return {@code true} if the input object matched some criteria. + */ + boolean test(T t); + + /** + * Create a predicate which evaluates to {@code true} only if this predicate + * and the provided predicate both evaluate to {@code true}. If this + * predicate returns {@code false} then the remaining predicate is not + * evaluated. + * + * @return a new predicate which returns {@code true} only if both + * predicates return {@code true}. + */ + default Predicate<T> and(Predicate<? super T> p) { + 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. + */ + default Predicate<T> negate() { + return Predicates.negate(this); + } + + /** + * Create a predicate which evaluates to {@code true} if either this + * predicate or the provided predicate evaluates to {@code true}. If this + * predicate returns {@code true} then the remaining predicate is not + * evaluated. + * + * @return a new predicate which returns {@code true} if either predicate + * returns {@code true}. + */ + default Predicate<T> or(Predicate<? super T> p) { + return Predicates.or(this, p); + } + + /** + * Creates a predicate that evaluates to {@code true} 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. + * + * @return a predicate that evaluates to {@code true} if all or none of the + * component predicates evaluate to {@code true} + */ + default Predicate<T> xor(Predicate<? super T> p) { + return Predicates.xor(this, p); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/Predicates.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,522 @@ +/* + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.Objects; + +/** + * Static utility methods pertaining to {@code Predicate} instances. + * + * <p>All of the returned predicates are serializable if given serializable + * parameters. + */ +public final class Predicates { + + /** + * a predicate that evaluates to {@code true} if the reference + * being tested is {@code null}. + */ + private static final Predicate<Object> IS_NULL = t -> t == null; + + /** + * a predicate that evaluates to {@code true} if the reference + * being tested is not {@code null}. + */ + private static final Predicate<Object> NON_NULL = t -> t != null; + + /** + * a predicate who's result is always {@code false}. + */ + private static final Predicate<Object> FALSE = t -> false; + + + /** + * a predicate who's result is always {@code true}. + */ + private static final Predicate<Object> TRUE = t -> true; + + /** + * singleton utils + */ + private Predicates() { + throw new AssertionError("No instances!"); + } + + /** + * Returns a predicate that evaluates to {@code true} if the reference + * being tested is {@code null}. + * + * @param <T> the type of values evaluated by the predicate. + * @return a predicate that evaluates to {@code true} if the reference + * being tested is {@code null} + */ + public static <T> Predicate<T> isNull() { + return (Predicate<T>)IS_NULL; + } + + /** + * Returns a predicate that evaluates to {@code true} if the reference + * being tested is non-{@code null}. + * + * @param <T> the type of values evaluated by the predicate. + * @return a predicate that evaluates to {@code true} if the reference + * being tested is is non-{@code null} + */ + public static <T> Predicate<T> nonNull() { + return (Predicate<T>)NON_NULL; + } + + /** + * Returns a predicate that always evaluates to {@code false}. + * + * @param <T> the type of values evaluated by the predicate. + * @return a predicate that always evaluates to {@code false}. + */ + public static <T> Predicate<T> alwaysFalse() { + return (Predicate<T>)FALSE; + } + + /** + * Returns a predicate that always evaluates to {@code true}. + * + * @param <T> the type of values evaluated by the predicate. + * @return a predicate that always evaluates to {@code true}. + */ + public static <T> Predicate<T> alwaysTrue() { + return (Predicate<T>)TRUE; + } + + /** + * Returns a predicate that evaluates to {@code true} if the object being + * tested is an instance of the provided class. If the object being tested + * is {@code null} this predicate evaluates to {@code false}. + * + * @param <T> the type of values evaluated by the predicate. + * @param clazz The target class to be matched by the predicate. + * @return a predicate that evaluates to {@code true} if the object being + * tested is an instance of the provided class + */ + public static <T> Predicate<T> instanceOf(Class<?> clazz) { + return o -> clazz.isInstance(o); + } + + /** + * 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)}. + * + * @param <T> the type of values evaluated by the predicate. + * @param target The target value to be compared for equality. + * @return a predicate who's result matches {@code Objects.equals(target, t)} + */ + public static <T> Predicate<T> isEqual(Object target) { + if (null == target) + return Predicates.isNull(); + else + return object -> target.equals(object); + } + + /** + * Creates a predicate that evaluates to {@code true} if the {@code test} + * object is a member of the provided collection. The collection is not + * defensively copied so changes to it will alter the behavior of the + * predicate. + * + * @param <T> Type of predicate values. + * @param target the collection against which objects will be tested. + * @return a predicate that evaluates to {@code true} if the tested object + * is a member of the provided collection. The collection is not defensively + * copied so changes to it will alter the behavior of the predicate. + */ + public static <T> Predicate<T> contains(Collection<?> target) { + return t -> target.contains(t); + } + + /** + * Creates a predicate that is a composition of a mapper and a predicate. + * The returned predicate's result is {@code predicate.test(mapper.map(t))}. + * + * @return the composition of the provided mapper and predicate + */ + public static <T, V> Predicate<T> compose( + Predicate<? super V> predicate, Mapper<? extends V, ? super T> mapper) { + return t -> predicate.test(mapper.map(t)); + } + + /** + * Returns a predicate that evaluates to {@code true} if the provided + * predicate evaluates to {@code false} + * + * @param <T> the type of values evaluated by the predicate. + * @param predicate The predicate to be evaluated. + * @return A predicate who's result is the logical inverse of the provided + * predicate. + */ + public static <T> Predicate<T> negate(Predicate<? super T> predicate) { + return t -> !predicate.test(t); + } + + /** + * 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 terminate upon the first + * {@code false} predicate. + * + * @param <T> the type of values evaluated by the predicates. + * @param first initial component predicate to be evaluated. + * @param second additional component predicate 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( + Predicate<? super T> first, Predicate<? super T> second) { + Objects.requireNonNull(first); + Objects.requireNonNull(second); + + return t -> first.test(t) && second.test(t); + } + + /** + * 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 first initial component predicate to be evaluated. + * @param second additional component predicate 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( + Predicate<? super T> first, Predicate<? super T> second) { + Objects.requireNonNull(first); + Objects.requireNonNull(second); + + return t -> first.test(t) || second.test(t); + } + + /** + * 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 first initial component predicate to be evaluated. + * @param second additional component predicate 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( + Predicate<? super T> first, Predicate<? super T> second) { + Objects.requireNonNull(first); + Objects.requireNonNull(second); + + return t -> first.test(t) ^ second.test(t); + } + + /** + * 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)); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/UnaryOperator.java Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2012, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.util.function; + +/** + * Operator on a single operand. + * + * <p>All Operator implementations are expected to: + * <ul> + * <li>Provide stable + * results such that for any {@code a} the result of two {@code operate} + * operations are always equivalent. i.e.<pre> + * Foo one = operator.operate(a); + * Foo two = operator.operate(a); + * + * assert one.equals(two) && two.equals(one); + * </pre></li> + * + * <li>The operator should not modify the input object in any way + * that would change the result.</li> + * + * </ul> + * + * @param <T> the type of input objects provided to {@code operate} and the result. + * + * @author Jim Gish + * @since 1.8 + * + */ +public interface UnaryOperator<T> { + + /** + * The implementation of the method is used to compute a new value + * from the old value. + * + * @param operand the old value + * @return the new value + */ + public T operate(T operand); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/java/util/function/package.html Thu Nov 15 10:55:22 2012 -0800 @@ -0,0 +1,38 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head> +<!-- +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. Oracle designates this +particular file as subject to the "Classpath" exception as provided +by Oracle in the LICENSE file that accompanied this code. + +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. +--> + +</head> +<body bgcolor="white"> +These interfaces each provide a single accessible method and are used to +provide typing for lambda methods. The operation identified by each interface +is generally applied to a collection of objects. + +<p> + +</body> +</html>
--- a/src/share/classes/java/util/functions/BiBlock.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2012, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -/** - * BiBlock - * - * @author Brian Goetz - */ -/** - * Performs operations upon an input object which may modify that object and/or - * external state (other objects). - * - * <p>All block implementations are expected to: - * <ul> - * <li>When used for aggregate operations upon many elements blocks - * should not assume that the {@code apply} operation will be called upon - * elements in any specific order.</li> - * </ul> - * - * @param <L> the type of input objects provided to {@code apply}. - * @param <R> the type of input objects provided to {@code apply}. - */ -public interface BiBlock<L, R> { - - /** - * Performs operations upon the provided object which may modify that object - * and/or external state. - * - * @param l an input object - */ - void apply(L l, R r); - - /** - * Returns a Block which performs in sequence the {@code apply} methods of - * multiple Blocks. This Block's {@code apply} method is performed followed - * by the {@code apply} method of the specified Block operation. - * - * @param other an additional Block which will be chained after this Block - * @return a Block which performs in sequence the {@code apply} method of - * this Block and the {@code apply} method of the specified Block operation - */ - public default BiBlock<L, R> chain(BiBlock<? super L, ? super R> other) { - return (l, r) -> { apply(l, r); other.apply(l, r); }; - } -}
--- a/src/share/classes/java/util/functions/BiMapper.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2010, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -/** - * Given input objects maps to an appropriate output object. A mapper may - * variously provide a mapping between types, object instances or keys and - * values or any other form of transformation upon the input. - * - * <p/>All mapper implementations are expected to: - * <ul> - * <li>Provide stable results such that for any {@code t} the result of two - * {@code map} operations are always equivalent. ie.<pre> - * Foo one = mapper.map(a); - * Foo two = mapper.map(a); - * - * assert one.equals(two) && two.equals(one); - * </pre></li> - * <li>Equivalent input objects should map to equivalent output objects. ie.<pre> - * assert a.equals(b); // a and b are equivalent - * - * Foo x = mapper.map(a); - * Foo y = mapper.map(b); - * - * assert x.equals(y); // their mapped results should be as equivalent. - * </pre></li> - * <li>The mapper should not modify the input object in any way that would - * change the mapping.</li> - * <li>When used for aggregate operations upon many elements mappers - * should not assume that the {@code map} operation will be called upon elements - * in any specific order.</li> - * </ul> - * - * @param <R> the type of output objects from {@code map} operation. May be the - * @param <T> the type of input objects provided to the {@code map} operation. - * @param <U> the type of input objects provided to the {@code map} operation. - * same type as either {@code <T>} or {@code <U>}. - */ -public interface BiMapper<R, T, U> { - - /** - * Map the provided input objects to an appropriate output object. - * - * @param t an object to be mapped. - * @param u another object to be mapped. - * @return the mapped output object. - */ - R map(T t, U u); - - /** - * Combine with another mapper producing a mapper which preforms both - * mappings. - * - * @param <W> Type of output objects from the combined mapper. May be the - * same type as {@code <U>}. - * @param after An additional mapping to be applied to the result of this - * mapping. - * @return A mapper which performs both the original mapping followed by - * a second mapping. - */ - public default <W> BiMapper<W, T, U> compose(Mapper<? extends W, ? super R> after) { - throw new UnsupportedOperationException("Not yet implemented."); - } -}
--- a/src/share/classes/java/util/functions/BiPredicate.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2010, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ - -package java.util.functions; - -/** - * Determines if the input object matches some criteria. - * - * <p>All predicate implementations are expected to: - * <ul> - * <li>Provide stable results such that for any {@code t} the result of two - * {@code eval} operations are always equivalent. ie.<pre> - * boolean one = predicate.eval(a); - * boolean two = predicate.eval(a); - * - * assert one == two; - * </pre></li> - * <li>Equivalent input objects should map to equivalent output objects. ie.<pre> - * assert a.equals(b); // a and b are equivalent - * - * boolean x = predicate.eval(a); - * boolean y = predicate.eval(ab; - * - * assert x == y; // their eval results should be the same. - * </pre></li> - * <li>The predicate should not modify the input object in any way that would - * change the evaluation.</li> - * <li>When used for aggregate operations upon many elements predicates - * should not assume that the {@code eval} operation will be called upon - * elements in any specific order.</li> - * </ul> - * - * @param <L> the type of input objects provided to {@code test}. - * @param <R> the type of input objects provided to {@code test}. - */ -public interface BiPredicate<L,R> { - - /** - * Return {@code true} if the inputs match some criteria. - * - * @param l an input object. - * @param r an input object. - * @return {@code true} if the inputs match some criteria. - */ - boolean test(L l, R r); - - /** - * Create a predicate which evaluates to {@code true} only if this predicate - * and the provided predicate both evaluate to {@code true}. If this - * predicate returns {@code false} then the remaining predicate is not - * evaluated. - * - * @return a new predicate which returns {@code true} only if both - * predicates return {@code true}. - */ - default BiPredicate<L,R> and(BiPredicate<? super L,? super R> p) { - throw new UnsupportedOperationException("Not yet implemented"); - } - - /** - * Create a predicate which negates the result of this predicate. - * - * @return a new predicate who's result is always the opposite of this predicate. - */ - default BiPredicate<L,R> negate() { - throw new UnsupportedOperationException("Not yet implemented"); - } - - /** - * Create a predicate which evaluates to {@code true} if either this - * predicate or the provided predicate evaluates to {@code true}. If this - * predicate returns {@code true} then the remaining predicate is not - * evaluated. - * - * @return a new predicate which returns {@code true} if either predicate - * returns {@code true}. - */ - default BiPredicate<L,R> or(BiPredicate<? super L,? super R> p) { - throw new UnsupportedOperationException("Not yet implemented"); - } - - /** - * Creates a predicate that evaluates to {@code true} 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. - * - * @return a predicate that evaluates to {@code true} if all or none of the - * component predicates evaluate to {@code true} - */ - default BiPredicate<L,R> xor(BiPredicate<? super L,? super R> p) { - throw new UnsupportedOperationException("Not yet implemented"); - } -}
--- a/src/share/classes/java/util/functions/BinaryOperator.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2010, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -/** - * Combines two operands. - * - * <p>All Operator implementations are expected to: - * <ul> - * <li>Provide stable - * results such that for any {@code a} and {@code b} the result of two {@code eval} - * operations are always equivalent. ie.<pre> - * Foo one = operator.eval(a,b); - * Foo two = operator.eval(a,b); - * - * assert one.equals(two) && two.equals(one); - * </pre></li> - * - * <li>The operator should not modify the input object in any way - * that would change the result.</li> - * - * <li>When used for aggregate operations - * upon many elements operators should not assume that the {@code eval} - * operation will be called upon elements in any specific order ie.<pre> - * Foo one = operator.eval(a,operator.eval(b,c)); - * Foo two = operator.eval(b,operator.eval(a,c)); - * - * assert one.equals(two) && two.equals(one); - * </pre></li> - * </ul> - * - * @param <T> the type of input objects provided to {@code eval} and the result. - */ -public interface BinaryOperator<T> extends Combiner<T, T, T> { - - public T operate(T left, T right); - - @Override - public default T combine(T t1, T t2) { - return operate(t1, t2); - } -}
--- a/src/share/classes/java/util/functions/Block.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -package java.util.functions; - -/** - * Performs operations upon an input object which may modify that object and/or - * external state (other objects). - * - * <p>All block implementations are expected to: - * <ul> - * <li>When used for aggregate operations upon many elements blocks - * should not assume that the {@code apply} operation will be called upon - * elements in any specific order.</li> - * </ul> - * - * @param <T> The type of input objects to {@code apply}. - */ -public interface Block<T> { - - /** - * Performs operations upon the provided object which may modify that object - * and/or external state. - * - * @param t an input object - */ - void apply(T t); - - /** - * Returns a Block which performs in sequence the {@code apply} methods of - * multiple Blocks. This Block's {@code apply} method is performed followed - * by the {@code apply} method of the specified Block operation. - * - * @param other an additional Block which will be chained after this Block - * @return a Block which performs in sequence the {@code apply} method of - * this Block and the {@code apply} method of the specified Block operation - */ - public default Block<T> chain(Block<? super T> other) { - return (T t) -> { apply(t); other.apply(t); }; - } -}
--- a/src/share/classes/java/util/functions/Combiner.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2012, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -/** - * Combiner - * - * @author Brian Goetz - */ -public interface Combiner<R, T, U> { - R combine(T t, U u); -}
--- a/src/share/classes/java/util/functions/DoubleBinaryOperator.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2010, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -/** - * DoubleBiOperator - */ -public interface DoubleBinaryOperator { - public double eval(double left, double right); -}
--- a/src/share/classes/java/util/functions/DoubleMapper.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2010, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -/** - * Given an input object maps to an appropriate double value; this is the - * double-bearing specialization for {@link java.util.functions.Mapper}. - * - * <p/>Like Mapper, DoubleMapper implementations are expected to: - * <ul> - * <li>Provide stable results such that for any {@code t} the result of two - * {@code map} operations are always equivalent. ie.<pre> - * double one = mapper.map(a); - * double two = mapper.map(a); - * - * assert one == two; - * </pre></li> - * <li>Equivalent input objects should map to equivalent output objects. ie.<pre> - * assert a.equals(b); // a and b are equivalent - * - * double x = mapper.map(a); - * double y = mapper.map(b); - * - * assert x == y; // their mapped results should be as equivalent. - * </pre></li> - * <li>The mapper should not modify the input object in any way that would - * change the mapping.</li> - * <li>When used for aggregate operations upon many elements mappers - * should not assume that the {@code map} operation will be called upon elements - * in any specific order.</li> - * </ul> - * - * @param <T> the type of input objects provided to the {@code map} operation. - */ -public interface DoubleMapper<T> { - - /** - * Map the provided input object to an appropriate output object. - * - * @param t the input object to be mapped. - * @return the mapped output value. - */ - double map(T t); -}
--- a/src/share/classes/java/util/functions/DoubleUnaryOperator.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2012, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -/** - * Operator on a single {@code double} operand. - * - * <p>All Operator implementations are expected to: - * <ul> - * <li>Provide stable - * results such that for any {@code a} the result of two {@code operate} - * operations are always equivalent. i.e.<pre> - * Foo one = operator.operate(a); - * Foo two = operator.operate(a); - * - * assert one.equals(two) && two.equals(one); - * </pre></li> - * - * <li>The operator should not modify the input object in any way - * that would change the result.</li> - * - * </ul> - * - * @author Jim Gish - * @since 1.8 - * - */ -public interface DoubleUnaryOperator { - - /** - * The implementation of the method is used to compute a new value - * from the old value. - * - * @param operand the old value - * @return the new value - */ - public double operate(double operand); -}
--- a/src/share/classes/java/util/functions/Factory.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2010, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -/** - * aka Source and Producer - * - * <p>All Factory implementations are expected to: - * <ul> - * <li></li> - * </ul> - * - * @param <T> The type of objects returned by {@code create}. - */ -public interface Factory<T> { - - /** - * Returns an object. - * - * @return an object. - */ - T make(); - -}
--- a/src/share/classes/java/util/functions/FlatMapper.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2012, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -/** - * Map an element to zero or more results and add all results to a sink. - * - * @author Brian Goetz - */ -public interface FlatMapper<R, T> { - /** - * Map {@code element} and add all of the results to {@code sink}. - * - * @param sink Destination for mapped elements. - * @param element The element to be mapped. - */ - void flatMapInto(Block<? super R> sink, T element); -}
--- a/src/share/classes/java/util/functions/IntBinaryOperator.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2010, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -/** - * IntBinaryOperator - */ -public interface IntBinaryOperator { - public int eval(int left, int right); -}
--- a/src/share/classes/java/util/functions/IntMapper.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2010, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -/** - * Given an input object maps to an appropriate integer value; this is the - * int-bearing specialization for {@link Mapper}. - * - * <p/>Like Mapper, IntMapper implementations are expected to: - * <ul> - * <li>Provide stable results such that for any {@code t} the result of two - * {@code map} operations are always equivalent. ie.<pre> - * int one = mapper.map(a); - * int two = mapper.map(a); - * - * assert one == two; - * </pre></li> - * <li>Equivalent input objects should map to equivalent output objects. ie.<pre> - * assert a.equals(b); // a and b are equivalent - * - * int x = mapper.map(a); - * int y = mapper.map(b); - * - * assert x == y; // their mapped results should be as equivalent. - * </pre></li> - * <li>The mapper should not modify the input object in any way that would - * change the mapping.</li> - * <li>When used for aggregate operations upon many elements mappers - * should not assume that the {@code map} operation will be called upon elements - * in any specific order.</li> - * </ul> - * - * @param <T> the type of input objects provided to the {@code map} operation. - */ -public interface IntMapper<T> { - - /** - * Map the provided input object to an appropriate output object. - * - * @param t the input object to be mapped. - * @return the mapped output value. - */ - int map(T t); -}
--- a/src/share/classes/java/util/functions/IntUnaryOperator.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2012, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -/** - * Operator on a single {@code int} operand. - * - * <p>All Operator implementations are expected to: - * <ul> - * <li>Provide stable - * results such that for any {@code a} the result of two {@code operate} - * operations are always equivalent. i.e.<pre> - * Foo one = operator.operate(a); - * Foo two = operator.operate(a); - * - * assert one.equals(two) && two.equals(one); - * </pre></li> - * - * <li>The operator should not modify the input object in any way - * that would change the result.</li> - * - * </ul> - * - * @author Jim Gish - * @since 1.8 - * - */ -public interface IntUnaryOperator { - - /** - * The implementation of the method is used to compute a new value - * from the old value. - * - * @param operand the old value - * @return the new value - */ - public int operate(int operand); -}
--- a/src/share/classes/java/util/functions/LongBinaryOperator.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2010, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -/** - * LongBinaryOperator - */ -public interface LongBinaryOperator { - public long eval(long left, long right); -}
--- a/src/share/classes/java/util/functions/LongMapper.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2010, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -/** - * Given an input object maps to an appropriate long value; this is the - * long-bearing specialization for {@link java.util.functions.Mapper}. - * - * <p/>Like Mapper, LongMapper implementations are expected to: - * <ul> - * <li>Provide stable results such that for any {@code t} the result of two - * {@code map} operations are always equivalent. ie.<pre> - * long one = mapper.map(a); - * long two = mapper.map(a); - * - * assert one == two; - * </pre></li> - * <li>Equivalent input objects should map to equivalent output objects. ie.<pre> - * assert a.equals(b); // a and b are equivalent - * - * long x = mapper.map(a); - * long y = mapper.map(b); - * - * assert x == y; // their mapped results should be as equivalent. - * </pre></li> - * <li>The mapper should not modify the input object in any way that would - * change the mapping.</li> - * <li>When used for aggregate operations upon many elements mappers - * should not assume that the {@code map} operation will be called upon elements - * in any specific order.</li> - * </ul> - * - * @param <T> the type of input objects provided to the {@code map} operation. - */ -public interface LongMapper<T> { - - /** - * Map the provided input object to an appropriate output object. - * - * @param t the input object to be mapped. - * @return the mapped output value. - */ - long map(T t); -}
--- a/src/share/classes/java/util/functions/LongUnaryOperator.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2012, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -/** - * Operator on a single {@code long} operand. - * - * <p>All Operator implementations are expected to: - * <ul> - * <li>Provide stable - * results such that for any {@code a} the result of two {@code operate} - * operations are always equivalent. i.e.<pre> - * Foo one = operator.operate(a); - * Foo two = operator.operate(a); - * - * assert one.equals(two) && two.equals(one); - * </pre></li> - * - * <li>The operator should not modify the input object in any way - * that would change the result.</li> - * - * </ul> - * - * @author Jim Gish - * @since 1.8 - * - */ -public interface LongUnaryOperator { - - /** - * The implementation of the method is used to compute a new value - * from the old value. - * - * @param operand the old value - * @return the new value - */ - public long operate(long operand); -}
--- a/src/share/classes/java/util/functions/Mapper.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2010, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -/** - * Given an input object maps to an appropriate output object. A mapper may - * variously provide a mapping between types, object instances or keys and - * values or any other form of transformation upon the input. - * - * <p/>All mapper implementations are expected to: - * <ul> - * <li>Provide stable results such that for any {@code t} the result of two - * {@code map} operations are always equivalent. ie.<pre> - * Foo one = mapper.map(a); - * Foo two = mapper.map(a); - * - * assert one.equals(two) && two.equals(one); - * </pre></li> - * <li>Equivalent input objects should map to equivalent output objects. ie.<pre> - * assert a.equals(b); // a and b are equivalent - * - * Foo x = mapper.map(a); - * Foo y = mapper.map(b); - * - * assert x.equals(y); // their mapped results should be as equivalent. - * </pre></li> - * <li>The mapper should not modify the input object in any way that would - * change the mapping.</li> - * <li>When used for aggregate operations upon many elements mappers - * should not assume that the {@code map} operation will be called upon elements - * in any specific order.</li> - * </ul> - * - * @param <R> the type of output objects from {@code map} operation. May be the - * @param <T> the type of input objects provided to the {@code map} operation. - * same type as {@code <T>}. - */ -public interface Mapper<R, T> { - - /** - * Map the provided input object to an appropriate output object. - * - * @param t the input object to be mapped. - * @return the mapped output object. - */ - R map(T t); - - /** - * Combine with another mapper producing a mapper which preforms both - * mappings. - * - * @param <V> Type of output objects from the combined mapper. May be the - * same type as {@code <U>}. - * @param after An additional mapping to be applied to the result of this - * mapping. - * @return A mapper which performs both the original mapping followed by - * a second mapping. - */ - public default <V> Mapper<V, T> compose(Mapper<? extends V, ? super R> after) { - return Mappers.chain(this, after); - } -}
--- a/src/share/classes/java/util/functions/Mappers.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,235 +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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -import java.lang.reflect.Constructor; -import java.lang.reflect.UndeclaredThrowableException; -import java.util.Map; -import java.util.Objects; - -/** - * Static utility methods pertaining to {@code Mapper} instances. - * - * <p>All of the returned mappers are serializable if provided serializable - * parameters. - */ -public final class Mappers { - - /** - * A mapper which who's {@code map} method returns the provided - * input. - */ - private static final Mapper<Object, Object> IDENTITY = t -> t; - - /** - * A mapper which performs a mapping from an object to it's - * string representation. - */ - private static final Mapper<String, Object> STRING = String::valueOf; - - /** - * singleton utils - */ - private Mappers() { - throw new AssertionError("No instances!"); - } - - /** - * Returns a mapper which who's {@code map} method returns the provided - * input. Useful when a Mapper is required and {@code <T>} and {@code <U>} - * are the same type. - */ - public static <T> Mapper<T, T> identity() { - return (Mapper<T, T>) IDENTITY; - } - -// /** -// * Returns a mapper which who's {@code map} method returns a clone of the -// * provided input. -// */ -// public static <T> Mapper<T, T> cloneOf() { -// return t -> { -// try { -// return t.clone(); -// } catch (CloneNotSupportedException ex) { -// throw new UndeclaredThrowableException(ex); -// } -// }; -// } -// - /** - * Returns a mapper which performs a mapping from {@code <T>} to it's - * string representation. - * - * @param <T> Type of input values - * @return a mapper which performs a mapping from {@code <T>} to it's - * string representation - */ - public static <T> Mapper<String, T> string() { - return (Mapper<String, T>) STRING; - } - - /** - * Returns a mapper which performs a mapping from {@code <T>} to {@code <U>} - * followed by a mapping from {@code <U>} to {@code <V>}. - * - * @param <R> Type for final mapped values. May be the same type as - * {@code <U>}. - * @param <T> Type for input values - * @param <U> Type for intermediate mapped values. May be the same type as - * {@code <T>}. - * @param first Initial mapping from {@code <T>} to {@code <U>}. - * @param second additional mapping from {@code <U>} to {@code <V>}. - */ - public static <R, T, U> Mapper<R, T> chain( - Mapper<? extends U, ? super T> first, - Mapper<? extends R, ? super U> second) { - Objects.requireNonNull(first); - Objects.requireNonNull(second); - - return t -> second.map(first.map(t)); - } - - /** - * Returns a constant output regardless of input. - * - * @param constant The value to be returned by the {@code map} method. - * @return a mapper who's {@code map} method provides a constant result. - */ - public static <R, T> Mapper<R, T> constant(R constant) { - return t -> constant; - } - - /** - * A mapper that substitutes a single input value with a specified - * replacement. Input values are compared using {@code equals()}. - * - * @param <T> The type of values. - * @param subOut The input value to be substituted out. - * @param subIn The replacement value for matching inputs. - * @return a mapper that substitutes a single input value with a specified - * replacement. - */ - public static <T> Mapper<T, T> substitute(T subOut, T subIn) { - return t -> Objects.equals(subOut, t) ? subIn : t; - } - - /** - * Returns a new instance of {@code <U>} 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 mapper 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 <R, T> Mapper<R, T> 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); - } - }; - } - - /** - * Map according to the provided map. Attempting to map 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 map} method contract. - * - * @param <R> output type from mapping operation - * @param <T> input type to mapping operation - * @param map provides the mappings from {@code <T>} to {@code <U>} - * @throws IllegalArgumentException for all values of {@code <T>} not - * present in the map - */ - public static <R, T> Mapper<R, T> forMap(Map<? super T, ? extends R> map) { - Objects.requireNonNull(map); - - return t -> { - if (map.containsKey(t)) { - return map.get(t); - } else { - throw new IllegalArgumentException("unmappable <T> : " + t); - } - }; - } - - /** - * Map 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 map and care should be taken to avoid - * changes to the map during operation may produce results which violate the - * {@code map} method contract. - * - * @param <R> output type from mapping - * @param <T> input type to map - * @param map provides the mappings from {@code <T>} to {@code <U>} - * @param defaultValue the value returned by {@code map} method for - * {@code <T>} values not contained in the provided map - */ - public static <R, T> Mapper<R, T> forMap(Map<? super T, ? extends R> map, R defaultValue) { - Objects.requireNonNull(map); - - return t -> map.containsKey(t) ? map.get(t) : defaultValue; - } - - /** - * Map according to the provided predicate. Two output values are provided - * {@code forTrue} is returned if the predicate returns {@code true} - * otherwise the {@code forFalse} value is returned. - * - * @param <R> output type from mapping - * @param <T> input type to map - * @param predicate decides which value {@code map} method should return - * @param forTrue value to be returned for {@code true} predicate results - * @param forFalse value to be returned for {@code false} predicate results - * @return a Mapper who's {@code map} method provides results according to - * the provided predicate. - */ - public static <R, T> Mapper<R, T> forPredicate(Predicate<? super T> predicate, R forTrue, R forFalse) { - Objects.requireNonNull(predicate); - - return t -> predicate.test(t) ? forTrue : forFalse; - } -}
--- a/src/share/classes/java/util/functions/Predicate.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2010, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ - -package java.util.functions; - -/** - * Determines if the input object matches some criteria. - * - * <p>All predicate implementations are expected to: - * <ul> - * <li>Provide stable results such that for any {@code t} the result of two - * {@code eval} operations are always equivalent. ie.<pre> - * boolean one = predicate.test(a); - * boolean two = predicate.test(a); - * - * assert one == two; - * </pre></li> - * <li>Equivalent input objects should map to equivalent output objects. ie.<pre> - * assert a.equals(b); // a and b are equivalent - * - * boolean x = predicate.test(a); - * boolean y = predicate.test(ab; - * - * assert x == y; // their test results should be the same. - * </pre></li> - * <li>The predicate should not modify the input object in any way that would - * change the evaluation.</li> - * <li>When used for aggregate operations upon many elements predicates - * should not assume that the {@code test} operation will be called upon - * elements in any specific order.</li> - * </ul> - * - * @param <T> the type of input objects provided to {@code test}. - */ -public interface Predicate<T> { - - /** - * Return {@code true} if the input object matches some criteria. - * - * @param t the input object. - * @return {@code true} if the input object matched some criteria. - */ - boolean test(T t); - - /** - * Create a predicate which evaluates to {@code true} only if this predicate - * and the provided predicate both evaluate to {@code true}. If this - * predicate returns {@code false} then the remaining predicate is not - * evaluated. - * - * @return a new predicate which returns {@code true} only if both - * predicates return {@code true}. - */ - default Predicate<T> and(Predicate<? super T> p) { - 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. - */ - default Predicate<T> negate() { - return Predicates.negate(this); - } - - /** - * Create a predicate which evaluates to {@code true} if either this - * predicate or the provided predicate evaluates to {@code true}. If this - * predicate returns {@code true} then the remaining predicate is not - * evaluated. - * - * @return a new predicate which returns {@code true} if either predicate - * returns {@code true}. - */ - default Predicate<T> or(Predicate<? super T> p) { - return Predicates.or(this, p); - } - - /** - * Creates a predicate that evaluates to {@code true} 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. - * - * @return a predicate that evaluates to {@code true} if all or none of the - * component predicates evaluate to {@code true} - */ - default Predicate<T> xor(Predicate<? super T> p) { - return Predicates.xor(this, p); - } -}
--- a/src/share/classes/java/util/functions/Predicates.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,522 +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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.Objects; - -/** - * Static utility methods pertaining to {@code Predicate} instances. - * - * <p>All of the returned predicates are serializable if given serializable - * parameters. - */ -public final class Predicates { - - /** - * a predicate that evaluates to {@code true} if the reference - * being tested is {@code null}. - */ - private static final Predicate<Object> IS_NULL = t -> t == null; - - /** - * a predicate that evaluates to {@code true} if the reference - * being tested is not {@code null}. - */ - private static final Predicate<Object> NON_NULL = t -> t != null; - - /** - * a predicate who's result is always {@code false}. - */ - private static final Predicate<Object> FALSE = t -> false; - - - /** - * a predicate who's result is always {@code true}. - */ - private static final Predicate<Object> TRUE = t -> true; - - /** - * singleton utils - */ - private Predicates() { - throw new AssertionError("No instances!"); - } - - /** - * Returns a predicate that evaluates to {@code true} if the reference - * being tested is {@code null}. - * - * @param <T> the type of values evaluated by the predicate. - * @return a predicate that evaluates to {@code true} if the reference - * being tested is {@code null} - */ - public static <T> Predicate<T> isNull() { - return (Predicate<T>)IS_NULL; - } - - /** - * Returns a predicate that evaluates to {@code true} if the reference - * being tested is non-{@code null}. - * - * @param <T> the type of values evaluated by the predicate. - * @return a predicate that evaluates to {@code true} if the reference - * being tested is is non-{@code null} - */ - public static <T> Predicate<T> nonNull() { - return (Predicate<T>)NON_NULL; - } - - /** - * Returns a predicate that always evaluates to {@code false}. - * - * @param <T> the type of values evaluated by the predicate. - * @return a predicate that always evaluates to {@code false}. - */ - public static <T> Predicate<T> alwaysFalse() { - return (Predicate<T>)FALSE; - } - - /** - * Returns a predicate that always evaluates to {@code true}. - * - * @param <T> the type of values evaluated by the predicate. - * @return a predicate that always evaluates to {@code true}. - */ - public static <T> Predicate<T> alwaysTrue() { - return (Predicate<T>)TRUE; - } - - /** - * Returns a predicate that evaluates to {@code true} if the object being - * tested is an instance of the provided class. If the object being tested - * is {@code null} this predicate evaluates to {@code false}. - * - * @param <T> the type of values evaluated by the predicate. - * @param clazz The target class to be matched by the predicate. - * @return a predicate that evaluates to {@code true} if the object being - * tested is an instance of the provided class - */ - public static <T> Predicate<T> instanceOf(Class<?> clazz) { - return o -> clazz.isInstance(o); - } - - /** - * 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)}. - * - * @param <T> the type of values evaluated by the predicate. - * @param target The target value to be compared for equality. - * @return a predicate who's result matches {@code Objects.equals(target, t)} - */ - public static <T> Predicate<T> isEqual(Object target) { - if (null == target) - return Predicates.isNull(); - else - return object -> target.equals(object); - } - - /** - * Creates a predicate that evaluates to {@code true} if the {@code test} - * object is a member of the provided collection. The collection is not - * defensively copied so changes to it will alter the behavior of the - * predicate. - * - * @param <T> Type of predicate values. - * @param target the collection against which objects will be tested. - * @return a predicate that evaluates to {@code true} if the tested object - * is a member of the provided collection. The collection is not defensively - * copied so changes to it will alter the behavior of the predicate. - */ - public static <T> Predicate<T> contains(Collection<?> target) { - return t -> target.contains(t); - } - - /** - * Creates a predicate that is a composition of a mapper and a predicate. - * The returned predicate's result is {@code predicate.test(mapper.map(t))}. - * - * @return the composition of the provided mapper and predicate - */ - public static <T, V> Predicate<T> compose( - Predicate<? super V> predicate, Mapper<? extends V, ? super T> mapper) { - return t -> predicate.test(mapper.map(t)); - } - - /** - * Returns a predicate that evaluates to {@code true} if the provided - * predicate evaluates to {@code false} - * - * @param <T> the type of values evaluated by the predicate. - * @param predicate The predicate to be evaluated. - * @return A predicate who's result is the logical inverse of the provided - * predicate. - */ - public static <T> Predicate<T> negate(Predicate<? super T> predicate) { - return t -> !predicate.test(t); - } - - /** - * 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 terminate upon the first - * {@code false} predicate. - * - * @param <T> the type of values evaluated by the predicates. - * @param first initial component predicate to be evaluated. - * @param second additional component predicate 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( - Predicate<? super T> first, Predicate<? super T> second) { - Objects.requireNonNull(first); - Objects.requireNonNull(second); - - return t -> first.test(t) && second.test(t); - } - - /** - * 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 first initial component predicate to be evaluated. - * @param second additional component predicate 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( - Predicate<? super T> first, Predicate<? super T> second) { - Objects.requireNonNull(first); - Objects.requireNonNull(second); - - return t -> first.test(t) || second.test(t); - } - - /** - * 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 first initial component predicate to be evaluated. - * @param second additional component predicate 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( - Predicate<? super T> first, Predicate<? super T> second) { - Objects.requireNonNull(first); - Objects.requireNonNull(second); - - return t -> first.test(t) ^ second.test(t); - } - - /** - * 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/src/share/classes/java/util/functions/UnaryOperator.java Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2012, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package java.util.functions; - -/** - * Operator on a single operand. - * - * <p>All Operator implementations are expected to: - * <ul> - * <li>Provide stable - * results such that for any {@code a} the result of two {@code operate} - * operations are always equivalent. i.e.<pre> - * Foo one = operator.operate(a); - * Foo two = operator.operate(a); - * - * assert one.equals(two) && two.equals(one); - * </pre></li> - * - * <li>The operator should not modify the input object in any way - * that would change the result.</li> - * - * </ul> - * - * @param <T> the type of input objects provided to {@code operate} and the result. - * - * @author Jim Gish - * @since 1.8 - * - */ -public interface UnaryOperator<T> { - - /** - * The implementation of the method is used to compute a new value - * from the old value. - * - * @param operand the old value - * @return the new value - */ - public T operate(T operand); -}
--- a/src/share/classes/java/util/functions/package.html Thu Nov 15 13:36:22 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> -<html> -<head> -<!-- -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. Oracle designates this -particular file as subject to the "Classpath" exception as provided -by Oracle in the LICENSE file that accompanied this code. - -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. ---> - -</head> -<body bgcolor="white"> -These interfaces each provide a single accessible method and are used to -provide typing for lambda methods. The operation identified by each interface -is generally applied to a collection of objects. - -<p> - -</body> -</html>
--- a/src/share/classes/java/util/streams/ReferencePipeline.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/ReferencePipeline.java Thu Nov 15 10:55:22 2012 -0800 @@ -24,11 +24,18 @@ */ package java.util.streams; +import java.util.function.IntMapper; +import java.util.function.FlatMapper; +import java.util.function.Predicate; +import java.util.function.Factory; +import java.util.function.Mapper; +import java.util.function.Block; +import java.util.function.BinaryOperator; +import java.util.function.Combiner; import java.util.Collection; import java.util.Comparator; import java.util.Map; import java.util.Optional; -import java.util.functions.*; import java.util.streams.ops.*; import java.util.streams.primitives.RefToIntMapOp; import java.util.streams.primitives.IntStream;
--- a/src/share/classes/java/util/streams/Sink.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/Sink.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,8 +25,8 @@ package java.util.streams; import java.util.Objects; -import java.util.functions.BiBlock; -import java.util.functions.Block; +import java.util.function.BiBlock; +import java.util.function.Block; import java.util.logging.Logger; /**
--- a/src/share/classes/java/util/streams/Spliterator.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/Spliterator.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,7 +25,7 @@ package java.util.streams; import java.util.Iterator; -import java.util.functions.Block; +import java.util.function.Block; /** * Provides the ability to decompose an aggregate data structure and to iterate
--- a/src/share/classes/java/util/streams/Stream.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/Stream.java Thu Nov 15 10:55:22 2012 -0800 @@ -24,8 +24,15 @@ */ package java.util.streams; +import java.util.function.IntMapper; +import java.util.function.FlatMapper; +import java.util.function.Predicate; +import java.util.function.Factory; +import java.util.function.Mapper; +import java.util.function.Block; +import java.util.function.BinaryOperator; +import java.util.function.Combiner; import java.util.*; -import java.util.functions.*; import java.util.streams.primitives.IntStream; /**
--- a/src/share/classes/java/util/streams/Streams.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/Streams.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,9 +25,9 @@ package java.util.streams; import java.util.*; -import java.util.functions.Block; -import java.util.functions.Factory; -import java.util.functions.UnaryOperator; +import java.util.function.Block; +import java.util.function.Factory; +import java.util.function.UnaryOperator; /** * Streams
--- a/src/share/classes/java/util/streams/ops/CumulateOp.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/ops/CumulateOp.java Thu Nov 15 10:55:22 2012 -0800 @@ -27,7 +27,7 @@ import java.util.Iterator; import java.util.Objects; import java.util.concurrent.RecursiveTask; -import java.util.functions.BinaryOperator; +import java.util.function.BinaryOperator; import java.util.streams.*; /**
--- a/src/share/classes/java/util/streams/ops/FilterOp.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/ops/FilterOp.java Thu Nov 15 10:55:22 2012 -0800 @@ -27,7 +27,7 @@ import java.util.Iterator; import java.util.Iterators; import java.util.Objects; -import java.util.functions.Predicate; +import java.util.function.Predicate; import java.util.streams.Sink; import java.util.streams.StreamOpFlags;
--- a/src/share/classes/java/util/streams/ops/FlatMapOp.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/ops/FlatMapOp.java Thu Nov 15 10:55:22 2012 -0800 @@ -28,8 +28,8 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; -import java.util.functions.Block; -import java.util.functions.FlatMapper; +import java.util.function.Block; +import java.util.function.FlatMapper; import java.util.streams.Sink; import java.util.streams.StreamOpFlags;
--- a/src/share/classes/java/util/streams/ops/FoldOp.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/ops/FoldOp.java Thu Nov 15 10:55:22 2012 -0800 @@ -24,9 +24,9 @@ */ package java.util.streams.ops; -import java.util.functions.BinaryOperator; -import java.util.functions.Combiner; -import java.util.functions.Factory; +import java.util.function.BinaryOperator; +import java.util.function.Combiner; +import java.util.function.Factory; import java.util.streams.ParallelPipelineHelper; import java.util.streams.PipelineHelper;
--- a/src/share/classes/java/util/streams/ops/ForEachOp.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/ops/ForEachOp.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,7 +25,7 @@ package java.util.streams.ops; import java.util.Objects; -import java.util.functions.Block; +import java.util.function.Block; import java.util.logging.Logger; import java.util.streams.*;
--- a/src/share/classes/java/util/streams/ops/GroupByOp.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/ops/GroupByOp.java Thu Nov 15 10:55:22 2012 -0800 @@ -26,8 +26,8 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; -import java.util.functions.Factory; -import java.util.functions.Mapper; +import java.util.function.Factory; +import java.util.function.Mapper; import java.util.streams.*; /**
--- a/src/share/classes/java/util/streams/ops/MapOp.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/ops/MapOp.java Thu Nov 15 10:55:22 2012 -0800 @@ -27,7 +27,7 @@ import java.util.Iterator; import java.util.Iterators; import java.util.Objects; -import java.util.functions.Mapper; +import java.util.function.Mapper; import java.util.streams.Sink; import java.util.streams.StreamOpFlags;
--- a/src/share/classes/java/util/streams/ops/MatchOp.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/ops/MatchOp.java Thu Nov 15 10:55:22 2012 -0800 @@ -27,8 +27,8 @@ import java.util.Iterator; import java.util.concurrent.CountedCompleter; import java.util.concurrent.atomic.AtomicReference; -import java.util.functions.Mapper; -import java.util.functions.Predicate; +import java.util.function.Mapper; +import java.util.function.Predicate; import java.util.streams.*; /**
--- a/src/share/classes/java/util/streams/ops/NodeBuilder.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/ops/NodeBuilder.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,7 +25,7 @@ package java.util.streams.ops; import java.util.Sized; -import java.util.functions.UnaryOperator; +import java.util.function.UnaryOperator; import java.util.streams.Sink; /**
--- a/src/share/classes/java/util/streams/ops/Nodes.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/ops/Nodes.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,8 +25,8 @@ package java.util.streams.ops; import java.util.*; -import java.util.functions.Block; -import java.util.functions.UnaryOperator; +import java.util.function.Block; +import java.util.function.UnaryOperator; import java.util.streams.*; public class Nodes {
--- a/src/share/classes/java/util/streams/ops/OpUtils.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/ops/OpUtils.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,7 +25,7 @@ package java.util.streams.ops; import java.util.concurrent.CountedCompleter; -import java.util.functions.Factory; +import java.util.function.Factory; import java.util.streams.*; /**
--- a/src/share/classes/java/util/streams/ops/ReduceByOp.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/ops/ReduceByOp.java Thu Nov 15 10:55:22 2012 -0800 @@ -29,10 +29,10 @@ import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; -import java.util.functions.BinaryOperator; -import java.util.functions.Combiner; -import java.util.functions.Factory; -import java.util.functions.Mapper; +import java.util.function.BinaryOperator; +import java.util.function.Combiner; +import java.util.function.Factory; +import java.util.function.Mapper; import java.util.streams.*; /**
--- a/src/share/classes/java/util/streams/ops/SeedlessFoldOp.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/ops/SeedlessFoldOp.java Thu Nov 15 10:55:22 2012 -0800 @@ -26,7 +26,7 @@ import java.util.Objects; import java.util.Optional; -import java.util.functions.BinaryOperator; +import java.util.function.BinaryOperator; import java.util.streams.ParallelPipelineHelper; import java.util.streams.PipelineHelper;
--- a/src/share/classes/java/util/streams/ops/TeeOp.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/ops/TeeOp.java Thu Nov 15 10:55:22 2012 -0800 @@ -26,7 +26,7 @@ import java.util.Iterator; import java.util.Objects; -import java.util.functions.Block; +import java.util.function.Block; import java.util.streams.Sink; /**
--- a/src/share/classes/java/util/streams/primitives/IntBlock.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/primitives/IntBlock.java Thu Nov 15 10:55:22 2012 -0800 @@ -24,7 +24,7 @@ */ package java.util.streams.primitives; -import java.util.functions.Block; +import java.util.function.Block; import java.util.logging.Level; import java.util.logging.Logger;
--- a/src/share/classes/java/util/streams/primitives/IntFactory.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/primitives/IntFactory.java Thu Nov 15 10:55:22 2012 -0800 @@ -24,7 +24,7 @@ */ package java.util.streams.primitives; -import java.util.functions.Factory; +import java.util.function.Factory; import java.util.logging.Level; import java.util.logging.Logger;
--- a/src/share/classes/java/util/streams/primitives/IntIterable.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/primitives/IntIterable.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,7 +25,7 @@ package java.util.streams.primitives; import java.util.Iterator; -import java.util.functions.Block; +import java.util.function.Block; public interface IntIterable extends Iterable<Integer> {
--- a/src/share/classes/java/util/streams/primitives/IntIterator.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/primitives/IntIterator.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,7 +25,7 @@ package java.util.streams.primitives; import java.util.Iterator; -import java.util.functions.Block; +import java.util.function.Block; import java.util.logging.Level; import java.util.logging.Logger;
--- a/src/share/classes/java/util/streams/primitives/IntNodeBuilder.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/primitives/IntNodeBuilder.java Thu Nov 15 10:55:22 2012 -0800 @@ -24,7 +24,7 @@ */ package java.util.streams.primitives; -import java.util.functions.UnaryOperator; +import java.util.function.UnaryOperator; import java.util.streams.ops.NodeBuilder; public interface IntNodeBuilder extends NodeBuilder<Integer>, IntIterable, IntSink {
--- a/src/share/classes/java/util/streams/primitives/IntNodes.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/primitives/IntNodes.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,8 +25,8 @@ package java.util.streams.primitives; import java.util.*; -import java.util.functions.Block; -import java.util.functions.UnaryOperator; +import java.util.function.Block; +import java.util.function.UnaryOperator; import java.util.streams.*; import java.util.streams.ops.CollectorOps; import java.util.streams.ops.Node;
--- a/src/share/classes/java/util/streams/primitives/IntPipeline.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/primitives/IntPipeline.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,7 +25,7 @@ package java.util.streams.primitives; import java.util.Optional; -import java.util.functions.IntBinaryOperator; +import java.util.function.IntBinaryOperator; import java.util.streams.AbstractPipeline; import java.util.streams.Stream; import java.util.streams.StreamShapeFactory;
--- a/src/share/classes/java/util/streams/primitives/IntSpliterator.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/primitives/IntSpliterator.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,7 +25,7 @@ package java.util.streams.primitives; import java.util.Iterator; -import java.util.functions.Block; +import java.util.function.Block; import java.util.streams.Spliterator; import java.util.streams.Streams;
--- a/src/share/classes/java/util/streams/primitives/IntStream.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/primitives/IntStream.java Thu Nov 15 10:55:22 2012 -0800 @@ -24,11 +24,11 @@ */ package java.util.streams.primitives; +import java.util.function.IntBinaryOperator; import java.util.Collection; import java.util.Comparator; import java.util.Map; import java.util.Optional; -import java.util.functions.*; import java.util.streams.BaseStream; import java.util.streams.Stream; import java.util.streams.StreamShape;
--- a/src/share/classes/java/util/streams/primitives/IntUnaryOperator.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/primitives/IntUnaryOperator.java Thu Nov 15 10:55:22 2012 -0800 @@ -24,7 +24,7 @@ */ package java.util.streams.primitives; -import java.util.functions.UnaryOperator; +import java.util.function.UnaryOperator; import java.util.logging.Level; import java.util.logging.Logger;
--- a/src/share/classes/java/util/streams/primitives/Primitives.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/primitives/Primitives.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,9 +25,9 @@ package java.util.streams.primitives; import java.util.*; -import java.util.functions.Block; -import java.util.functions.Factory; -import java.util.functions.UnaryOperator; +import java.util.function.Block; +import java.util.function.Factory; +import java.util.function.UnaryOperator; import java.util.logging.Logger; import java.util.streams.*;
--- a/src/share/classes/java/util/streams/primitives/RefToIntMapOp.java Thu Nov 15 13:36:22 2012 -0500 +++ b/src/share/classes/java/util/streams/primitives/RefToIntMapOp.java Thu Nov 15 10:55:22 2012 -0800 @@ -26,7 +26,7 @@ import java.util.Iterator; import java.util.Objects; -import java.util.functions.IntMapper; +import java.util.function.IntMapper; import java.util.streams.Sink; import java.util.streams.StreamOpFlags; import java.util.streams.StreamShape;
--- a/test-ng/tests/org/openjdk/tests/java/lang/ThreadLocalFactoryTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/lang/ThreadLocalFactoryTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,7 +25,7 @@ package org.openjdk.tests.java.lang; import java.util.concurrent.atomic.AtomicInteger; -import java.util.functions.Factory; +import java.util.function.Factory; import org.testng.annotations.Test; import static org.testng.Assert.*;
--- a/test-ng/tests/org/openjdk/tests/java/lang/ThreadLocalTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/lang/ThreadLocalTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -24,7 +24,7 @@ */ package org.openjdk.tests.java.lang; -import java.util.functions.Factory; +import java.util.function.Factory; import org.testng.annotations.Test; import static org.testng.Assert.*;
--- a/test-ng/tests/org/openjdk/tests/java/util/ComparatorsTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/ComparatorsTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -30,10 +30,10 @@ import java.util.Map; import org.testng.annotations.Test; -import java.util.functions.DoubleMapper; -import java.util.functions.IntMapper; -import java.util.functions.LongMapper; -import java.util.functions.Mapper; +import java.util.function.DoubleMapper; +import java.util.function.IntMapper; +import java.util.function.LongMapper; +import java.util.function.Mapper; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue;
--- a/test-ng/tests/org/openjdk/tests/java/util/LambdaTestHelpers.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/LambdaTestHelpers.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,7 +25,7 @@ package org.openjdk.tests.java.util; import java.util.*; -import java.util.functions.*; +import java.util.function.*; import java.util.streams.Streamable; import java.util.streams.TerminalSink; import java.util.streams.Stream;
--- a/test-ng/tests/org/openjdk/tests/java/util/NullArgsTestCase.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/NullArgsTestCase.java Thu Nov 15 10:55:22 2012 -0800 @@ -27,7 +27,7 @@ import org.testng.annotations.Test; import java.util.Arrays; -import java.util.functions.Block; +import java.util.function.Block; import static org.testng.Assert.fail;
--- a/test-ng/tests/org/openjdk/tests/java/util/concurrent/AtomicReferenceTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/concurrent/AtomicReferenceTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -25,7 +25,7 @@ package org.openjdk.tests.java.util.concurrent; import java.util.concurrent.atomic.AtomicReference; -import java.util.functions.UnaryOperator; +import java.util.function.UnaryOperator; import org.testng.annotations.Test; import static org.testng.Assert.*;
--- a/test-ng/tests/org/openjdk/tests/java/util/functions/DoubleUnaryOperatorTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/functions/DoubleUnaryOperatorTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -22,9 +22,9 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.openjdk.tests.java.util.functions; +package org.openjdk.tests.java.util.function; -import java.util.functions.DoubleUnaryOperator; +import java.util.function.DoubleUnaryOperator; import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeMethod;
--- a/test-ng/tests/org/openjdk/tests/java/util/functions/IntUnaryOperatorTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/functions/IntUnaryOperatorTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -22,9 +22,9 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.openjdk.tests.java.util.functions; +package org.openjdk.tests.java.util.function; -import java.util.functions.IntUnaryOperator; +import java.util.function.IntUnaryOperator; import java.util.concurrent.atomic.AtomicInteger; import org.testng.annotations.Test; import static org.testng.Assert.*;
--- a/test-ng/tests/org/openjdk/tests/java/util/functions/LongUnaryOperatorTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/functions/LongUnaryOperatorTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -22,10 +22,10 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.openjdk.tests.java.util.functions; +package org.openjdk.tests.java.util.function; import java.util.concurrent.atomic.AtomicLong; -import java.util.functions.LongUnaryOperator; +import java.util.function.LongUnaryOperator; import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeMethod;
--- a/test-ng/tests/org/openjdk/tests/java/util/functions/MappersTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/functions/MappersTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -21,15 +21,15 @@ * questions. */ -package org.openjdk.tests.java.util.functions; +package org.openjdk.tests.java.util.function; import org.testng.annotations.Test; import java.lang.reflect.UndeclaredThrowableException; import java.util.HashMap; import java.util.Map; -import java.util.functions.Mapper; -import java.util.functions.Mappers; +import java.util.function.Mapper; +import java.util.function.Mappers; import static org.testng.Assert.assertNull; import static org.testng.Assert.fail;
--- a/test-ng/tests/org/openjdk/tests/java/util/functions/PredicatesTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/functions/PredicatesTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -21,7 +21,7 @@ * questions. */ -package org.openjdk.tests.java.util.functions; +package org.openjdk.tests.java.util.function; import org.testng.annotations.Test; @@ -30,8 +30,8 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; -import java.util.functions.Predicate; -import java.util.functions.Predicates; +import java.util.function.Predicate; +import java.util.function.Predicates; import static org.testng.Assert.assertTrue;
--- a/test-ng/tests/org/openjdk/tests/java/util/functions/UnaryOperatorTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/functions/UnaryOperatorTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -22,9 +22,9 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.openjdk.tests.java.util.functions; +package org.openjdk.tests.java.util.function; -import java.util.functions.UnaryOperator; +import java.util.function.UnaryOperator; import org.testng.annotations.Test; import static org.testng.Assert.*;
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/OpTestCase.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/streams/OpTestCase.java Thu Nov 15 10:55:22 2012 -0800 @@ -32,10 +32,10 @@ import org.testng.annotations.Test; import java.util.*; -import java.util.functions.BiPredicate; -import java.util.functions.Block; -import java.util.functions.Factory; -import java.util.functions.Mapper; +import java.util.function.BiPredicate; +import java.util.function.Block; +import java.util.function.Factory; +import java.util.function.Mapper; import java.util.streams.*; import java.util.streams.ops.*; import java.util.streams.primitives.IntStream;
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/StreamIntermediateOpTestScenario.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/streams/StreamIntermediateOpTestScenario.java Thu Nov 15 10:55:22 2012 -0800 @@ -26,8 +26,8 @@ import java.util.ArrayList; import java.util.Iterator; -import java.util.functions.Block; -import java.util.functions.Mapper; +import java.util.function.Block; +import java.util.function.Mapper; import java.util.streams.*; import java.util.streams.ops.FlagDeclaringOp; import java.util.streams.ops.IntermediateOp;
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/StreamTestDataProvider.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/streams/StreamTestDataProvider.java Thu Nov 15 10:55:22 2012 -0800 @@ -28,7 +28,7 @@ import org.testng.annotations.DataProvider; import java.util.*; -import java.util.functions.Combiner; +import java.util.function.Combiner; /** * StreamTestDataProvider
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/FindAnyOpTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/FindAnyOpTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -31,7 +31,7 @@ import java.util.Collections; import java.util.Optional; -import java.util.functions.BiPredicate; +import java.util.function.BiPredicate; import java.util.streams.ops.FilterOp; import java.util.streams.ops.FindAnyOp;
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/FlagOpTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/FlagOpTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -32,7 +32,7 @@ import org.testng.annotations.Test; import java.util.*; -import java.util.functions.Factory; +import java.util.function.Factory; import java.util.streams.Sink; import java.util.streams.StreamOpFlags; import java.util.streams.ops.*;
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/FlatMapOpTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/FlatMapOpTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -30,8 +30,8 @@ import org.testng.annotations.Test; import java.util.Arrays; -import java.util.functions.Block; -import java.util.functions.FlatMapper; +import java.util.function.Block; +import java.util.function.FlatMapper; import java.util.streams.Stream; import java.util.streams.ops.FlatMapOp; import java.util.streams.ops.Node;
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/GroupByOpTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/GroupByOpTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -30,7 +30,7 @@ import org.testng.annotations.Test; import java.util.*; -import java.util.functions.*; +import java.util.function.*; import java.util.streams.Stream; import java.util.streams.StreamOpFlags; import java.util.streams.ops.GroupByOp;
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/IntNodeTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/IntNodeTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -30,7 +30,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.functions.Mapper; +import java.util.function.Mapper; import java.util.streams.ops.Node; import java.util.streams.primitives.*;
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/MapOpTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/MapOpTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -30,7 +30,7 @@ import org.testng.annotations.Test; import java.util.Iterators; -import java.util.functions.Block; +import java.util.function.Block; import java.util.streams.ops.MapOp; import java.util.streams.ops.Node;
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/MatchOpTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/MatchOpTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -29,7 +29,7 @@ import org.openjdk.tests.java.util.streams.StreamTestDataProvider; import org.testng.annotations.Test; -import java.util.functions.Predicate; +import java.util.function.Predicate; import java.util.streams.Stream; import java.util.streams.Streamable; import java.util.streams.ops.FilterOp;
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/NodeBuilderTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/NodeBuilderTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -31,7 +31,7 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; -import java.util.functions.Mapper; +import java.util.function.Mapper; import java.util.streams.ops.NodeBuilder; import java.util.streams.ops.Nodes;
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/NodeTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/NodeTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -28,7 +28,7 @@ import org.testng.annotations.Test; import java.util.*; -import java.util.functions.Mapper; +import java.util.function.Mapper; import java.util.streams.Spliterator; import java.util.streams.Stream; import java.util.streams.Streamable;
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/ReduceByOpTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/ReduceByOpTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -32,7 +32,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.Map; -import java.util.functions.Mappers; +import java.util.function.Mappers; import java.util.streams.ops.GroupByOp; import java.util.streams.ops.ReduceByOp;
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/SliceOpTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/SliceOpTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -35,8 +35,8 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -import java.util.functions.Mapper; -import java.util.functions.UnaryOperator; +import java.util.function.Mapper; +import java.util.function.UnaryOperator; import java.util.streams.AbstractPipeline; import java.util.streams.Stream; import java.util.streams.Streamable;
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/TeeOpTest.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/TeeOpTest.java Thu Nov 15 10:55:22 2012 -0800 @@ -33,7 +33,7 @@ import java.util.Collections; import java.util.Iterators; import java.util.List; -import java.util.functions.Block; +import java.util.function.Block; import java.util.streams.Stream; import java.util.streams.ops.TeeOp;
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/primitives/IntStreamIntermediateOpTestScenario.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/streams/primitives/IntStreamIntermediateOpTestScenario.java Thu Nov 15 10:55:22 2012 -0800 @@ -27,8 +27,8 @@ import org.openjdk.tests.java.util.streams.OpTestCase; import java.util.Iterator; -import java.util.functions.Block; -import java.util.functions.Mapper; +import java.util.function.Block; +import java.util.function.Mapper; import java.util.streams.*; import java.util.streams.ops.FlagDeclaringOp; import java.util.streams.ops.IntermediateOp;
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/primitives/IntStreamTestDataProvider.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/java/util/streams/primitives/IntStreamTestDataProvider.java Thu Nov 15 10:55:22 2012 -0800 @@ -28,7 +28,7 @@ import org.testng.annotations.DataProvider; import java.util.*; -import java.util.functions.Combiner; +import java.util.function.Combiner; public class IntStreamTestDataProvider { private static final int[] to0 = new int[0];
--- a/test-ng/tests/org/openjdk/tests/javac/LambdaTranslationTest1.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/javac/LambdaTranslationTest1.java Thu Nov 15 10:55:22 2012 -0800 @@ -26,7 +26,7 @@ import org.testng.annotations.Test; -import java.util.functions.Block; +import java.util.function.Block; import static org.testng.Assert.assertEquals;
--- a/test-ng/tests/org/openjdk/tests/javac/LambdaTranslationTest2.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/javac/LambdaTranslationTest2.java Thu Nov 15 10:55:22 2012 -0800 @@ -28,8 +28,8 @@ import java.util.ArrayList; import java.util.List; -import java.util.functions.Mapper; -import java.util.functions.Predicate; +import java.util.function.Mapper; +import java.util.function.Predicate; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue;
--- a/test-ng/tests/org/openjdk/tests/javac/MethodReferenceTestInstanceMethod.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test-ng/tests/org/openjdk/tests/javac/MethodReferenceTestInstanceMethod.java Thu Nov 15 10:55:22 2012 -0800 @@ -26,7 +26,7 @@ package org.openjdk.tests.javac; import java.util.Arrays; -import java.util.functions.*; +import java.util.function.*; import java.util.streams.Stream; import org.testng.annotations.Test;
--- a/test/java/util/Collection/MOAT.java Thu Nov 15 13:36:22 2012 -0500 +++ b/test/java/util/Collection/MOAT.java Thu Nov 15 10:55:22 2012 -0800 @@ -53,7 +53,7 @@ import java.io.*; import java.util.*; import java.util.concurrent.*; -import java.util.functions.*; +import java.util.function.*; import static java.util.Collections.*; public class MOAT {