8004561: Additional functional interfaces, extension methods and name changes
Summary: Adds additional functional interfaces for primitives and "Bi" (two operand). Adds utility extension methods. Includes some name changes for existing functional interfaces per EG decisions.
Reviewed-by: briangoetz, darcy, chegar, dholmes
--- a/jdk/src/share/classes/java/time/chrono/HijrahDeviationReader.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/time/chrono/HijrahDeviationReader.java Tue Feb 19 11:56:49 2013 -0800
@@ -70,7 +70,7 @@
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.util.Arrays;
-import java.util.function.Block;
+import java.util.function.Consumer;
/**
* A reader for Hijrah Deviation files.
@@ -126,13 +126,13 @@
* @param typeId the name of the calendar
* @param calendarType the calendar type
* @return {@code true} if the file was read and each entry accepted by the
- * Block; else {@code false} no configuration was done
+ * Consumer; else {@code false} no configuration was done
*
* @throws IOException for zip/jar file handling exception.
* @throws ParseException if the format of the configuration file is wrong.
*/
static boolean readDeviation(String typeId, String calendarType,
- Block<HijrahChronology.Deviation> block) throws IOException, ParseException {
+ Consumer<HijrahChronology.Deviation> consumer) throws IOException, ParseException {
InputStream is = getConfigFileInputStream(typeId);
if (is != null) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
@@ -142,7 +142,7 @@
num++;
HijrahChronology.Deviation entry = parseLine(line, num);
if (entry != null) {
- block.accept(entry);
+ consumer.accept(entry);
}
}
}
--- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicInteger.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicInteger.java Tue Feb 19 11:56:49 2013 -0800
@@ -219,7 +219,7 @@
int prev, next;
do {
prev = get();
- next = updateFunction.operateAsInt(prev);
+ next = updateFunction.applyAsInt(prev);
} while (!compareAndSet(prev, next));
return prev;
}
@@ -238,7 +238,7 @@
int prev, next;
do {
prev = get();
- next = updateFunction.operateAsInt(prev);
+ next = updateFunction.applyAsInt(prev);
} while (!compareAndSet(prev, next));
return next;
}
@@ -262,7 +262,7 @@
int prev, next;
do {
prev = get();
- next = accumulatorFunction.operateAsInt(prev, x);
+ next = accumulatorFunction.applyAsInt(prev, x);
} while (!compareAndSet(prev, next));
return prev;
}
@@ -286,7 +286,7 @@
int prev, next;
do {
prev = get();
- next = accumulatorFunction.operateAsInt(prev, x);
+ next = accumulatorFunction.applyAsInt(prev, x);
} while (!compareAndSet(prev, next));
return next;
}
--- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicIntegerArray.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicIntegerArray.java Tue Feb 19 11:56:49 2013 -0800
@@ -263,7 +263,7 @@
int prev, next;
do {
prev = getRaw(offset);
- next = updateFunction.operateAsInt(prev);
+ next = updateFunction.applyAsInt(prev);
} while (!compareAndSetRaw(offset, prev, next));
return prev;
}
@@ -284,7 +284,7 @@
int prev, next;
do {
prev = getRaw(offset);
- next = updateFunction.operateAsInt(prev);
+ next = updateFunction.applyAsInt(prev);
} while (!compareAndSetRaw(offset, prev, next));
return next;
}
@@ -310,7 +310,7 @@
int prev, next;
do {
prev = getRaw(offset);
- next = accumulatorFunction.operateAsInt(prev, x);
+ next = accumulatorFunction.applyAsInt(prev, x);
} while (!compareAndSetRaw(offset, prev, next));
return prev;
}
@@ -336,7 +336,7 @@
int prev, next;
do {
prev = getRaw(offset);
- next = accumulatorFunction.operateAsInt(prev, x);
+ next = accumulatorFunction.applyAsInt(prev, x);
} while (!compareAndSetRaw(offset, prev, next));
return next;
}
--- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java Tue Feb 19 11:56:49 2013 -0800
@@ -281,7 +281,7 @@
int prev, next;
do {
prev = get(obj);
- next = updateFunction.operateAsInt(prev);
+ next = updateFunction.applyAsInt(prev);
} while (!compareAndSet(obj, prev, next));
return prev;
}
@@ -301,7 +301,7 @@
int prev, next;
do {
prev = get(obj);
- next = updateFunction.operateAsInt(prev);
+ next = updateFunction.applyAsInt(prev);
} while (!compareAndSet(obj, prev, next));
return next;
}
@@ -326,7 +326,7 @@
int prev, next;
do {
prev = get(obj);
- next = accumulatorFunction.operateAsInt(prev, x);
+ next = accumulatorFunction.applyAsInt(prev, x);
} while (!compareAndSet(obj, prev, next));
return prev;
}
@@ -351,7 +351,7 @@
int prev, next;
do {
prev = get(obj);
- next = accumulatorFunction.operateAsInt(prev, x);
+ next = accumulatorFunction.applyAsInt(prev, x);
} while (!compareAndSet(obj, prev, next));
return next;
}
--- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLong.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLong.java Tue Feb 19 11:56:49 2013 -0800
@@ -233,7 +233,7 @@
long prev, next;
do {
prev = get();
- next = updateFunction.operateAsLong(prev);
+ next = updateFunction.applyAsLong(prev);
} while (!compareAndSet(prev, next));
return prev;
}
@@ -252,7 +252,7 @@
long prev, next;
do {
prev = get();
- next = updateFunction.operateAsLong(prev);
+ next = updateFunction.applyAsLong(prev);
} while (!compareAndSet(prev, next));
return next;
}
@@ -276,7 +276,7 @@
long prev, next;
do {
prev = get();
- next = accumulatorFunction.operateAsLong(prev, x);
+ next = accumulatorFunction.applyAsLong(prev, x);
} while (!compareAndSet(prev, next));
return prev;
}
@@ -300,7 +300,7 @@
long prev, next;
do {
prev = get();
- next = accumulatorFunction.operateAsLong(prev, x);
+ next = accumulatorFunction.applyAsLong(prev, x);
} while (!compareAndSet(prev, next));
return next;
}
--- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongArray.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongArray.java Tue Feb 19 11:56:49 2013 -0800
@@ -262,7 +262,7 @@
long prev, next;
do {
prev = getRaw(offset);
- next = updateFunction.operateAsLong(prev);
+ next = updateFunction.applyAsLong(prev);
} while (!compareAndSetRaw(offset, prev, next));
return prev;
}
@@ -283,7 +283,7 @@
long prev, next;
do {
prev = getRaw(offset);
- next = updateFunction.operateAsLong(prev);
+ next = updateFunction.applyAsLong(prev);
} while (!compareAndSetRaw(offset, prev, next));
return next;
}
@@ -309,7 +309,7 @@
long prev, next;
do {
prev = getRaw(offset);
- next = accumulatorFunction.operateAsLong(prev, x);
+ next = accumulatorFunction.applyAsLong(prev, x);
} while (!compareAndSetRaw(offset, prev, next));
return prev;
}
@@ -335,7 +335,7 @@
long prev, next;
do {
prev = getRaw(offset);
- next = accumulatorFunction.operateAsLong(prev, x);
+ next = accumulatorFunction.applyAsLong(prev, x);
} while (!compareAndSetRaw(offset, prev, next));
return next;
}
--- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java Tue Feb 19 11:56:49 2013 -0800
@@ -284,7 +284,7 @@
long prev, next;
do {
prev = get(obj);
- next = updateFunction.operateAsLong(prev);
+ next = updateFunction.applyAsLong(prev);
} while (!compareAndSet(obj, prev, next));
return prev;
}
@@ -304,7 +304,7 @@
long prev, next;
do {
prev = get(obj);
- next = updateFunction.operateAsLong(prev);
+ next = updateFunction.applyAsLong(prev);
} while (!compareAndSet(obj, prev, next));
return next;
}
@@ -329,7 +329,7 @@
long prev, next;
do {
prev = get(obj);
- next = accumulatorFunction.operateAsLong(prev, x);
+ next = accumulatorFunction.applyAsLong(prev, x);
} while (!compareAndSet(obj, prev, next));
return prev;
}
@@ -354,7 +354,7 @@
long prev, next;
do {
prev = get(obj);
- next = accumulatorFunction.operateAsLong(prev, x);
+ next = accumulatorFunction.applyAsLong(prev, x);
} while (!compareAndSet(obj, prev, next));
return next;
}
--- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReference.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReference.java Tue Feb 19 11:56:49 2013 -0800
@@ -157,7 +157,7 @@
V prev, next;
do {
prev = get();
- next = updateFunction.operate(prev);
+ next = updateFunction.apply(prev);
} while (!compareAndSet(prev, next));
return prev;
}
@@ -176,7 +176,7 @@
V prev, next;
do {
prev = get();
- next = updateFunction.operate(prev);
+ next = updateFunction.apply(prev);
} while (!compareAndSet(prev, next));
return next;
}
@@ -200,7 +200,7 @@
V prev, next;
do {
prev = get();
- next = accumulatorFunction.operate(prev, x);
+ next = accumulatorFunction.apply(prev, x);
} while (!compareAndSet(prev, next));
return prev;
}
@@ -224,7 +224,7 @@
V prev, next;
do {
prev = get();
- next = accumulatorFunction.operate(prev, x);
+ next = accumulatorFunction.apply(prev, x);
} while (!compareAndSet(prev, next));
return next;
}
--- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java Tue Feb 19 11:56:49 2013 -0800
@@ -217,7 +217,7 @@
E prev, next;
do {
prev = getRaw(offset);
- next = updateFunction.operate(prev);
+ next = updateFunction.apply(prev);
} while (!compareAndSetRaw(offset, prev, next));
return prev;
}
@@ -238,7 +238,7 @@
E prev, next;
do {
prev = getRaw(offset);
- next = updateFunction.operate(prev);
+ next = updateFunction.apply(prev);
} while (!compareAndSetRaw(offset, prev, next));
return next;
}
@@ -264,7 +264,7 @@
E prev, next;
do {
prev = getRaw(offset);
- next = accumulatorFunction.operate(prev, x);
+ next = accumulatorFunction.apply(prev, x);
} while (!compareAndSetRaw(offset, prev, next));
return prev;
}
@@ -290,7 +290,7 @@
E prev, next;
do {
prev = getRaw(offset);
- next = accumulatorFunction.operate(prev, x);
+ next = accumulatorFunction.apply(prev, x);
} while (!compareAndSetRaw(offset, prev, next));
return next;
}
--- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java Tue Feb 19 11:56:49 2013 -0800
@@ -200,7 +200,7 @@
V prev, next;
do {
prev = get(obj);
- next = updateFunction.operate(prev);
+ next = updateFunction.apply(prev);
} while (!compareAndSet(obj, prev, next));
return prev;
}
@@ -220,7 +220,7 @@
V prev, next;
do {
prev = get(obj);
- next = updateFunction.operate(prev);
+ next = updateFunction.apply(prev);
} while (!compareAndSet(obj, prev, next));
return next;
}
@@ -245,7 +245,7 @@
V prev, next;
do {
prev = get(obj);
- next = accumulatorFunction.operate(prev, x);
+ next = accumulatorFunction.apply(prev, x);
} while (!compareAndSet(obj, prev, next));
return prev;
}
@@ -270,7 +270,7 @@
V prev, next;
do {
prev = get(obj);
- next = accumulatorFunction.operate(prev, x);
+ next = accumulatorFunction.apply(prev, x);
} while (!compareAndSet(obj, prev, next));
return next;
}
--- a/jdk/src/share/classes/java/util/concurrent/atomic/DoubleAccumulator.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/atomic/DoubleAccumulator.java Tue Feb 19 11:56:49 2013 -0800
@@ -100,14 +100,14 @@
Cell[] as; long b, v, r; int m; Cell a;
if ((as = cells) != null ||
(r = Double.doubleToRawLongBits
- (function.operateAsDouble
+ (function.applyAsDouble
(Double.longBitsToDouble(b = base), x))) != b && !casBase(b, r)) {
boolean uncontended = true;
if (as == null || (m = as.length - 1) < 0 ||
(a = as[getProbe() & m]) == null ||
!(uncontended =
(r = Double.doubleToRawLongBits
- (function.operateAsDouble
+ (function.applyAsDouble
(Double.longBitsToDouble(v = a.value), x))) == v ||
a.cas(v, r)))
doubleAccumulate(x, function, uncontended);
@@ -129,7 +129,7 @@
if (as != null) {
for (int i = 0; i < as.length; ++i) {
if ((a = as[i]) != null)
- result = function.operateAsDouble
+ result = function.applyAsDouble
(result, Double.longBitsToDouble(a.value));
}
}
@@ -174,7 +174,7 @@
if ((a = as[i]) != null) {
double v = Double.longBitsToDouble(a.value);
a.value = identity;
- result = function.operateAsDouble(result, v);
+ result = function.applyAsDouble(result, v);
}
}
}
--- a/jdk/src/share/classes/java/util/concurrent/atomic/LongAccumulator.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/atomic/LongAccumulator.java Tue Feb 19 11:56:49 2013 -0800
@@ -101,12 +101,12 @@
public void accumulate(long x) {
Cell[] as; long b, v, r; int m; Cell a;
if ((as = cells) != null ||
- (r = function.operateAsLong(b = base, x)) != b && !casBase(b, r)) {
+ (r = function.applyAsLong(b = base, x)) != b && !casBase(b, r)) {
boolean uncontended = true;
if (as == null || (m = as.length - 1) < 0 ||
(a = as[getProbe() & m]) == null ||
!(uncontended =
- (r = function.operateAsLong(v = a.value, x)) == v ||
+ (r = function.applyAsLong(v = a.value, x)) == v ||
a.cas(v, r)))
longAccumulate(x, function, uncontended);
}
@@ -127,7 +127,7 @@
if (as != null) {
for (int i = 0; i < as.length; ++i) {
if ((a = as[i]) != null)
- result = function.operateAsLong(result, a.value);
+ result = function.applyAsLong(result, a.value);
}
}
return result;
@@ -171,7 +171,7 @@
if ((a = as[i]) != null) {
long v = a.value;
a.value = identity;
- result = function.operateAsLong(result, v);
+ result = function.applyAsLong(result, v);
}
}
}
--- a/jdk/src/share/classes/java/util/concurrent/atomic/Striped64.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/atomic/Striped64.java Tue Feb 19 11:56:49 2013 -0800
@@ -253,7 +253,7 @@
else if (!wasUncontended) // CAS already known to fail
wasUncontended = true; // Continue after rehash
else if (a.cas(v = a.value, ((fn == null) ? v + x :
- fn.operateAsLong(v, x))))
+ fn.applyAsLong(v, x))))
break;
else if (n >= NCPU || cells != as)
collide = false; // At max size or stale
@@ -291,7 +291,7 @@
break;
}
else if (casBase(v = base, ((fn == null) ? v + x :
- fn.operateAsLong(v, x))))
+ fn.applyAsLong(v, x))))
break; // Fall back on using base
}
}
@@ -344,7 +344,7 @@
Double.doubleToRawLongBits
(Double.longBitsToDouble(v) + x) :
Double.doubleToRawLongBits
- (fn.operateAsDouble
+ (fn.applyAsDouble
(Double.longBitsToDouble(v), x)))))
break;
else if (n >= NCPU || cells != as)
@@ -387,7 +387,7 @@
Double.doubleToRawLongBits
(Double.longBitsToDouble(v) + x) :
Double.doubleToRawLongBits
- (fn.operateAsDouble
+ (fn.applyAsDouble
(Double.longBitsToDouble(v), x)))))
break; // Fall back on using base
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/BiConsumer.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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;
+
+/**
+ * An operation which accepts two input arguments and returns no result. This is
+ * the two-arity specialization of {@link Consumer}. Unlike most other
+ * functional interfaces, {@code BiConsumer} is expected to operate via
+ * side-effects.
+ *
+ * @param <T> the type of the first argument to the {@code accept} operation.
+ * @param <U> the type of the second argument to the {@code accept} operation.
+ *
+ * @see Consumer
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface BiConsumer<T, U> {
+
+ /**
+ * Performs operations upon the provided objects which may modify those
+ * objects and/or external state.
+ *
+ * @param t an input object
+ * @param u an input object
+ */
+ void accept(T t, U u);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/BiFunction.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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;
+
+/**
+ * Apply a function to the input arguments, yielding an appropriate result. This
+ * is the two-arity specialization of {@link Function}. A function may
+ * variously provide a mapping between types, object instances or keys and
+ * values or any other form of transformation upon the input.
+ *
+ * @param <T> the type of the first argument to the {@code apply} operation.
+ * @param <U> the type of the second argument to the {@code apply} operation.
+ * @param <R> the type of results returned by the {@code apply} operation.
+ *
+ * @see Function
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface BiFunction<T, U, R> {
+
+ /**
+ * Compute the result of applying the function to the input arguments
+ *
+ * @param t an input object
+ * @param u an input object
+ * @return the function result
+ */
+ R apply(T t, U u);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/BiPredicate.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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.Objects;
+
+/**
+ * Determines if the input objects match some criteria. This is the two-arity
+ * specialization of {@link Predicate}.
+ *
+ * @param <T> the type of the first argument to {@code test}.
+ * @param <U> the type of the second argument to {@code test}.
+ *
+ * @see Predicate
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface BiPredicate<T, U> {
+
+ /**
+ * Return {@code true} if the inputs match some criteria.
+ *
+ * @param t an input object.
+ * @param u an input object.
+ * @return {@code true} if the inputs match some criteria.
+ */
+ boolean test(T t, U u);
+
+ /**
+ * Returns 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.
+ *
+ * @param p a predicate which will be logically-ANDed with this predicate.
+ * @return a new predicate which returns {@code true} only if both
+ * predicates return {@code true}.
+ */
+ public default BiPredicate<T, U> and(BiPredicate<? super T, ? super U> p) {
+ Objects.requireNonNull(p);
+ return (T t, U u) -> test(t, u) && p.test(t, u);
+ }
+
+ /**
+ * Returns a predicate which negates the result of this predicate.
+ *
+ * @return a new predicate who's result is always the opposite of this
+ * predicate.
+ */
+ public default BiPredicate<T, U> negate() {
+ return (T t, U u) -> !test(t, u);
+ }
+
+ /**
+ * Returns 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.
+ *
+ * @param p a predicate which will be logically-ORed with this predicate.
+ * @return a new predicate which returns {@code true} if either predicate
+ * returns {@code true}.
+ */
+ public default BiPredicate<T, U> or(BiPredicate<? super T, ? super U> p) {
+ Objects.requireNonNull(p);
+ return (T t, U u) -> test(t, u) || p.test(t, u);
+ }
+
+ /**
+ * Returns a predicate that evaluates to {@code true} if both or neither of
+ * the component predicates evaluate to {@code true}.
+ *
+ * @param p a predicate which will be logically-XORed with this predicate.
+ * @return a predicate that evaluates to {@code true} if both or neither of
+ * the component predicates evaluate to {@code true}.
+ */
+ public default BiPredicate<T, U> xor(BiPredicate<? super T, ? super U> p) {
+ Objects.requireNonNull(p);
+ return (T t, U u) -> test(t, u) ^ p.test(t, u);
+ }
+}
--- a/jdk/src/share/classes/java/util/function/BinaryOperator.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/function/BinaryOperator.java Tue Feb 19 11:56:49 2013 -0800
@@ -25,24 +25,14 @@
package java.util.function;
/**
- * An operation upon two operands yielding a result. The operands and the result
- * are all of the same type.
+ * An operation upon two operands yielding a result. This is a specialization of
+ * {@code BiFunction} where the operands and the result are all of the same type.
*
- * @param <T> the type of operands to {@code operate} and of the result
+ * @param <T> the type of operands to {@code apply} and of the result
*
+ * @see BiFunction.
* @since 1.8
*/
@FunctionalInterface
-public interface BinaryOperator<T> {
-
- /**
- * Returns the result of the operation upon the operands.
- * The operands are named {@code left} and {@code right} for operations
- * where the order of operands matters.
- *
- * @param left the left operand
- * @param right the right operand
- * @return the result of the operation
- */
- public T operate(T left, T right);
+public interface BinaryOperator<T> extends BiFunction<T,T,T> {
}
--- a/jdk/src/share/classes/java/util/function/Block.java Tue Feb 19 10:34:26 2013 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * 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;
-
-/**
- * An operation upon an input object. The operation may modify that object or
- * external state (other objects).
- *
- * @param <T> The type of input objects to {@code accept}
- *
- * @since 1.8
- */
-@FunctionalInterface
-public interface Block<T> {
-
- /**
- * Use the input object in operations which may modify that object or
- * external state (other objects).
- *
- * @param t the input object
- */
- public void accept(T t);
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/BooleanSupplier.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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;
+
+
+/**
+ * A supplier of {@code boolean} values. This is the {@code boolean}-providing
+ * primitive specialization of {@link Supplier}.
+ *
+ * @see Supplier
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface BooleanSupplier {
+
+ /**
+ * Returns a {@code boolean} value.
+ *
+ * @return a {@code boolean} value
+ */
+ public boolean getAsBoolean();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/Consumer.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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;
+
+/**
+ * An operation which accepts a single input argument and returns no result.
+ * Unlike most other functional interfaces, {@code Consumer} is expected to
+ * operate via side-effects.
+ *
+ * @param <T> The type of input objects to {@code accept}
+ *
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface Consumer<T> {
+
+ /**
+ * Accept an input value.
+ *
+ * @param t the input object
+ */
+ public void accept(T t);
+}
--- a/jdk/src/share/classes/java/util/function/DoubleBinaryOperator.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/function/DoubleBinaryOperator.java Tue Feb 19 11:56:49 2013 -0800
@@ -26,23 +26,22 @@
/**
* An operation on two {@code double} operands yielding a {@code double} result.
+ * This is the primitive type specialization of {@link BinaryOperator} for
+ * {@code double}.
*
+ * @see BinaryOperator
* @since 1.8
*/
@FunctionalInterface
-public interface DoubleBinaryOperator /* extends BinaryOperator<Double> */ {
-//
-// @Override
-// public default Double operate(Double left, Double right) { return operateAsDouble((double) left, (double) right); }
-
+public interface DoubleBinaryOperator {
/**
* Returns the {@code double} result of the operation upon the
* {@code double} operands. The parameters are named {@code left} and
* {@code right} for operations where the order of parameters matters.
*
* @param left the left operand value
- * @param right the right operand value
+ * @param right the right operand value
* @return the result of the operation
*/
- public double operateAsDouble(double left, double right);
+ public double applyAsDouble(double left, double right);
}
--- a/jdk/src/share/classes/java/util/function/DoubleBlock.java Tue Feb 19 10:34:26 2013 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * 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;
-
-/**
- * An operation upon a {@code double} input value. The operation may modify
- * external state.
- *
- * <p/>This is the primitive type specialization of {@link Block} for
- * {@code double} and also may be used as a {@code Block<Double>}.
- *
- * @since 1.8
- */
-@FunctionalInterface
-public interface DoubleBlock {
-
- /**
- * Use the {@code double} input value in an operation which may modify
- * external state.
- *
- * @param t the input value
- */
- public void accept(double t);
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/DoubleConsumer.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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;
+
+/**
+ * An operation which accepts a single double argument and returns no result.
+ * This is the primitive type specialization of {@link Consumer} for
+ * {@code double}. Unlike most other functional interfaces,
+ * {@code DoubleConsumer} is expected to operate via side-effects.
+ *
+ * @see Consumer
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface DoubleConsumer {
+
+ /**
+ * Accept an input value.
+ *
+ * @param value the input value
+ */
+ public void accept(double value);
+}
--- a/jdk/src/share/classes/java/util/function/DoubleFunction.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/function/DoubleFunction.java Tue Feb 19 11:56:49 2013 -0800
@@ -25,22 +25,23 @@
package java.util.function;
/**
- * Apply a function to the input object yielding an appropriate {@code double}
- * value; this is the {@code double}-bearing specialization for {@link Function}.
+ * Apply a function to the double-valued input argument, yielding an appropriate
+ * result. This is the {@code double}-consuming primitive specialization for
+ * {@link Function}.
*
- * @param <T> the type of input objects to the function
+ * @param <R> the type of output objects from the function
*
+ * @see Function
* @since 1.8
*/
@FunctionalInterface
-public interface DoubleFunction<T> {
+public interface DoubleFunction<R> {
/**
- * Apply a function to the input object yielding an appropriate
- * {@code double} value.
+ * Compute the result of applying the function to the input argument
*
- * @param t the input object
- * @return the function result value
+ * @param value the input value
+ * @return the function result
*/
- public double applyAsDouble(T t);
+ public R apply(double value);
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/DoublePredicate.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2010, 2013 Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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.Objects;
+
+/**
+ * Determines if the {@code double} input value matches some criteria. This is
+ * the {@code double}-consuming primitive type specialization of
+ * {@link Predicate}.
+ *
+ * @see Predicate
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface DoublePredicate {
+
+ /**
+ * Returns {@code true} if the input value matches some criteria.
+ *
+ * @param value the value to be tested.
+ * @return {@code true} if the input value matches some criteria, otherwise
+ * {@code false}.
+ */
+ public boolean test(double value);
+
+ /**
+ * Returns 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.
+ *
+ * @param p a predicate which will be logically-ANDed with this predicate.
+ * @return a new predicate which returns {@code true} only if both
+ * predicates return {@code true}.
+ */
+ public default DoublePredicate and(DoublePredicate p) {
+ Objects.requireNonNull(p);
+ return (value) -> test(value) && p.test(value);
+ }
+
+ /**
+ * Returns a predicate which negates the result of this predicate.
+ *
+ * @return a new predicate who's result is always the opposite of this
+ * predicate.
+ */
+ public default DoublePredicate negate() {
+ return (value) -> !test(value);
+ }
+
+ /**
+ * Returns 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.
+ *
+ * @param p a predicate which will be logically-ANDed with this predicate.
+ * @return a new predicate which returns {@code true} if either predicate
+ * returns {@code true}.
+ */
+ public default DoublePredicate or(DoublePredicate p) {
+ Objects.requireNonNull(p);
+ return (value) -> test(value) || p.test(value);
+ }
+
+ /**
+ * Returns a predicate that evaluates to {@code true} if both or neither of
+ * the component predicates evaluate to {@code true}.
+ *
+ * @param p a predicate which will be logically-XORed with this predicate.
+ * @return a predicate that evaluates to {@code true} if all or none of the
+ * component predicates evaluate to {@code true}.
+ */
+ public default DoublePredicate xor(DoublePredicate p) {
+ Objects.requireNonNull(p);
+ return (value) -> test(value) ^ p.test(value);
+ }
+}
--- a/jdk/src/share/classes/java/util/function/DoubleSupplier.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/function/DoubleSupplier.java Tue Feb 19 11:56:49 2013 -0800
@@ -25,11 +25,10 @@
package java.util.function;
/**
- * A supplier of {@code double} values.
+ * A supplier of {@code double} values. This is the {@code double}-providing
+ * primitive specialization of {@link Supplier}.
*
- * <p/>This is the primitive type specialization of {@link Supplier} for
- * {@code double} and also may be used as a {@code Supplier<Double>}.
- *
+ * @see Supplier
* @since 1.8
*/
@FunctionalInterface
--- a/jdk/src/share/classes/java/util/function/DoubleUnaryOperator.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/function/DoubleUnaryOperator.java Tue Feb 19 11:56:49 2013 -0800
@@ -25,9 +25,11 @@
package java.util.function;
/**
- * An operation on a single {@code double} operand yielding a {@code double}
- * result.
+ * An operation on a {@code double} operand yielding a {@code double}
+ * result. This is the primitive type specialization of {@link UnaryOperator}
+ * for {@code double}.
*
+ * @see UnaryOperator
* @since 1.8
*/
@FunctionalInterface
@@ -40,5 +42,5 @@
* @param operand the operand value
* @return the operation result value
*/
- public double operateAsDouble(double operand);
+ public double applyAsDouble(double operand);
}
--- a/jdk/src/share/classes/java/util/function/Function.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/function/Function.java Tue Feb 19 11:56:49 2013 -0800
@@ -24,14 +24,14 @@
*/
package java.util.function;
+
/**
- * Apply a function to the input object yielding an appropriate result object. A
+ * Apply a function to the input argument, yielding an appropriate result. A
* function may variously provide a mapping between types, object instances or
* keys and values or any other form of transformation upon the input.
*
- * @param <T> the type of input objects to the {@code apply} operation
- * @param <R> the type of result objects from the {@code apply} operation. May
- * be the same type as {@code <T>}.
+ * @param <T> the type of the input to the {@code apply} operation.
+ * @param <R> the type of the result of the {@code apply} operation.
*
* @since 1.8
*/
@@ -39,7 +39,7 @@
public interface Function<T, R> {
/**
- * Yield an appropriate result object for the input object.
+ * Compute the result of applying the function to the input argument
*
* @param t the input object
* @return the function result
--- a/jdk/src/share/classes/java/util/function/IntBinaryOperator.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/function/IntBinaryOperator.java Tue Feb 19 11:56:49 2013 -0800
@@ -26,7 +26,10 @@
/**
* An operation on two {@code int} operands yielding an {@code int} result.
+ * This is the primitive type specialization of {@link BinaryOperator} for
+ * {@code int}.
*
+ * @see BinaryOperator
* @since 1.8
*/
@FunctionalInterface
@@ -41,5 +44,5 @@
* @param right the right operand value
* @return the result of the operation
*/
- public int operateAsInt(int left, int right);
+ public int applyAsInt(int left, int right);
}
--- a/jdk/src/share/classes/java/util/function/IntBlock.java Tue Feb 19 10:34:26 2013 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * 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;
-
-/**
- * An operation upon an {@code int} input value. The operation may modify
- * external state.
- *
- * <p/>This is the primitive type specialization of {@link Block} for
- * {@code int} and also may be used as a {@code Block<Integer>}.
- *
- * @since 1.8
- */
-@FunctionalInterface
-public interface IntBlock {
-
- /**
- * Use the {@code int} input value in an operation which may modify external
- * state.
- *
- * @param t the input value
- */
- public void accept(int t);
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/IntConsumer.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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;
+
+/**
+ * An operation which accepts a single integer argument and returns no result.
+ * This is the primitive type specialization of {@link Consumer} for {@code int}.
+ * Unlike most other functional interfaces, {@code IntConsumer} is expected to
+ * operate via side-effects.
+ *
+ * @see Consumer
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface IntConsumer {
+
+ /**
+ * Accept an input value.
+ *
+ * @param value the input value
+ */
+ public void accept(int value);
+}
--- a/jdk/src/share/classes/java/util/function/IntFunction.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/function/IntFunction.java Tue Feb 19 11:56:49 2013 -0800
@@ -25,22 +25,23 @@
package java.util.function;
/**
- * Apply a function to the input object yielding an appropriate {@code int}
- * value; this is the {@code int}-bearing specialization for {@link Function}.
+ * Apply a function to the integer-valued input argument, yielding an
+ * appropriate result. This is the {@code int}-consuming primitive
+ * specialization for {@link Function}.
*
- * @param <T> the type of input objects to the function
+ * @param <R> the type of output objects from the function
*
+ * @see Function
* @since 1.8
*/
@FunctionalInterface
-public interface IntFunction<T> {
+public interface IntFunction<R> {
/**
- * Apply a function to the input object yielding an appropriate {@code int}
- * value.
+ * Compute the result of applying the function to the input argument
*
- * @param t the input object
- * @return the function result value
+ * @param value the input value
+ * @return the function result
*/
- public int applyAsInt(T t);
+ public R apply(int value);
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/IntPredicate.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2010, 2013 Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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.Objects;
+
+/**
+ * Determines if the {@code int} input value matches some criteria. This is the
+ * {@code int}-consuming primitive type specialization of {@link Predicate}.
+ *
+ * @see Predicate
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface IntPredicate {
+
+ /**
+ * Returns {@code true} if the input value matches some criteria.
+ *
+ * @param value the value to be tested.
+ * @return {@code true} if the input value matches some criteria, otherwise
+ * {@code false}
+ */
+ public boolean test(int value);
+
+ /**
+ * Returns 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.
+ *
+ * @param p a predicate which will be logically-ANDed with this predicate.
+ * @return a new predicate which returns {@code true} only if both
+ * predicates return {@code true}.
+ */
+ public default IntPredicate and(IntPredicate p) {
+ Objects.requireNonNull(p);
+ return (value) -> test(value) && p.test(value);
+ }
+
+ /**
+ * Returns a predicate which negates the result of this predicate.
+ *
+ * @return a new predicate who's result is always the opposite of this
+ * predicate.
+ */
+ public default IntPredicate negate() {
+ return (value) -> !test(value);
+ }
+
+ /**
+ * Returns 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.
+ *
+ * @param p a predicate which will be logically-ORed with this predicate.
+ * @return a new predicate which returns {@code true} if either predicate
+ * returns {@code true}.
+ */
+ public default IntPredicate or(IntPredicate p) {
+ Objects.requireNonNull(p);
+ return (value) -> test(value) || p.test(value);
+ }
+
+ /**
+ * Returns a predicate that evaluates to {@code true} if both or neither of
+ * the component predicates evaluate to {@code true}.
+ *
+ * @param p a predicate which will be logically-XORed with this predicate.
+ * @return a predicate that evaluates to {@code true} if both or neither of
+ * the component predicates evaluate to {@code true}
+ */
+ public default IntPredicate xor(IntPredicate p) {
+ Objects.requireNonNull(p);
+ return (value) -> test(value) ^ p.test(value);
+ }
+}
--- a/jdk/src/share/classes/java/util/function/IntSupplier.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/function/IntSupplier.java Tue Feb 19 11:56:49 2013 -0800
@@ -25,11 +25,10 @@
package java.util.function;
/**
- * A supplier of {@code int} values.
+ * A supplier of {@code int} values. This is the {@code int}-providing
+ * primitive specialization of {@link Supplier}.
*
- * <p/>This is the primitive type specialization of {@link Supplier} for
- * {@code int} and also may be used as a {@code Supplier<Integer>}.
- *
+ * @see Supplier
* @since 1.8
*/
@FunctionalInterface
--- a/jdk/src/share/classes/java/util/function/IntUnaryOperator.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/function/IntUnaryOperator.java Tue Feb 19 11:56:49 2013 -0800
@@ -26,18 +26,21 @@
/**
* An operation on a single {@code int} operand yielding an {@code int} result.
+ * This is the primitive type specialization of {@link UnaryOperator} for
+ * {@code int}.
*
+ * @see UnaryOperator
* @since 1.8
*/
@FunctionalInterface
public interface IntUnaryOperator {
/**
- * Returns the {@code int} result of the operation upon the {@code int}
- * operand.
+ * Returns the {@code int} value result of the operation upon the
+ * {@code int} operand.
*
* @param operand the operand value
* @return the operation result value
*/
- public int operateAsInt(int operand);
+ public int applyAsInt(int operand);
}
--- a/jdk/src/share/classes/java/util/function/LongBinaryOperator.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/function/LongBinaryOperator.java Tue Feb 19 11:56:49 2013 -0800
@@ -26,7 +26,10 @@
/**
* An operation on two {@code long} operands yielding a {@code long} result.
+ * This is the primitive type specialization of {@link BinaryOperator} for
+ * {@code long}.
*
+ * @see BinaryOperator
* @since 1.8
*/
@FunctionalInterface
@@ -41,5 +44,5 @@
* @param right the right operand value
* @return the result of the operation
*/
- public long operateAsLong(long left, long right);
+ public long applyAsLong(long left, long right);
}
--- a/jdk/src/share/classes/java/util/function/LongBlock.java Tue Feb 19 10:34:26 2013 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * 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;
-
-/**
- * An operation upon a {@code long} input value. The operation may modify
- * external state.
- *
- * <p/>This is the primitive type specialization of {@link Block} for
- * {@code long} and also may be used as a {@code Block<Long>}.
- *
- * @since 1.8
- */
-@FunctionalInterface
-public interface LongBlock {
-
- /**
- * Use the {@code long} input value in an operation which may modify
- * external state.
- *
- * @param t the input value
- */
- public void accept(long t);
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/LongConsumer.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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;
+
+/**
+ * An operation which accepts a single long argument and returns no result.
+ * This is the {@code long}-consuming primitive type specialization of
+ * {@link Consumer}. Unlike most other functional interfaces, {@code LongConsumer}
+ * is expected to operate via side-effects.
+ *
+ * @see Consumer
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface LongConsumer {
+
+ /**
+ * Accept an input value.
+ *
+ * @param value the input value
+ */
+ public void accept(long value);
+}
--- a/jdk/src/share/classes/java/util/function/LongFunction.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/function/LongFunction.java Tue Feb 19 11:56:49 2013 -0800
@@ -25,22 +25,23 @@
package java.util.function;
/**
- * Apply a function to the input object yielding an appropriate {@code long}
- * value; this is the {@code long}-bearing specialization for {@link Function}.
+ * Apply a function to the long-valued input argument, yielding an appropriate
+ * result. This is the {@code long}-consuming primitive specialization for
+ * {@link Function}.
*
- * @param <T> the type of input objects to the function
+ * @param <R> the type of output objects from the function
*
+ * @see Function
* @since 1.8
*/
@FunctionalInterface
-public interface LongFunction<T> {
+public interface LongFunction<R> {
/**
- * Apply a function to the input object yielding an appropriate {@code long}
- * value.
+ * Compute the result of applying the function to the input argument
*
- * @param t the input object
- * @return the function result value
+ * @param value the input value
+ * @return the function result
*/
- public long applyAsLong(T t);
+ public R apply(long value);
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/LongPredicate.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2010, 2013 Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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.Objects;
+
+/**
+ * Determines if the {@code long} input value matches some criteria. This is the
+ * {@code long}-consuming primitive type specialization of {@link Predicate}.
+ *
+ * @see Predicate
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface LongPredicate {
+
+ /**
+ * Returns {@code true} if the input value matches some criteria.
+ *
+ * @param value the value to be tested.
+ * @return {@code true} if the input value matches some criteria, otherwise
+ * {@code false}.
+ */
+ public boolean test(long value);
+
+ /**
+ * Returns 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.
+ *
+ * @param p a predicate which will be logically-ANDed with this predicate.
+ * @return a new predicate which returns {@code true} only if both
+ * predicates return {@code true}.
+ */
+ public default LongPredicate and(LongPredicate p) {
+ Objects.requireNonNull(p);
+ return (value) -> test(value) && p.test(value);
+ }
+
+ /**
+ * Returns a predicate which negates the result of this predicate.
+ *
+ * @return a new predicate who's result is always the opposite of this
+ * predicate.
+ */
+ public default LongPredicate negate() {
+ return (value) -> !test(value);
+ }
+
+ /**
+ * Returns 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.
+ *
+ * @param p a predicate which will be logically-ORed with this predicate.
+ * @return a new predicate which returns {@code true} if either predicate
+ * returns {@code true}.
+ */
+ public default LongPredicate or(LongPredicate p) {
+ Objects.requireNonNull(p);
+ return (value) -> test(value) || p.test(value);
+ }
+
+ /**
+ * Returns a predicate that evaluates to {@code true} if both or neither of
+ * the component predicates evaluate to {@code true}.
+ *
+ * @param p a predicate which will be logically-XORed with this predicate.
+ * @return a predicate that evaluates to {@code true} if both or neither of
+ * the component predicates evaluate to {@code true}.
+ */
+ public default LongPredicate xor(LongPredicate p) {
+ Objects.requireNonNull(p);
+ return (value) -> test(value) ^ p.test(value);
+ }
+}
--- a/jdk/src/share/classes/java/util/function/LongSupplier.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/function/LongSupplier.java Tue Feb 19 11:56:49 2013 -0800
@@ -25,11 +25,10 @@
package java.util.function;
/**
- * A supplier of {@code long} values.
+ * A supplier of {@code long} values. This is the {@code long}-providing
+ * primitive specialization of {@link Supplier}.
*
- * <p/>This is the primitive type specialization of {@link Supplier} for
- * {@code long} and also may be used as a {@code Supplier<Long>}.
- *
+ * @see Supplier
* @since 1.8
*/
@FunctionalInterface
@@ -38,7 +37,7 @@
/**
* Returns a {@code long} value.
*
- * @return a {@code long} value.
+ * @return a {@code long} value
*/
public long getAsLong();
}
--- a/jdk/src/share/classes/java/util/function/LongUnaryOperator.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/function/LongUnaryOperator.java Tue Feb 19 11:56:49 2013 -0800
@@ -26,7 +26,10 @@
/**
* An operation on a single {@code long} operand yielding a {@code long} result.
+ * This is the primitive type specialization of {@link UnaryOperator} for
+ * {@code long}.
*
+ * @see UnaryOperator
* @since 1.8
*/
@FunctionalInterface
@@ -39,5 +42,5 @@
* @param operand the operand value
* @return the operation result value
*/
- public long operateAsLong(long operand);
+ public long applyAsLong(long operand);
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/ObjDoubleConsumer.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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;
+
+/**
+ * An operation which accepts an object reference and a double, and returns no
+ * result. This is the {@code (reference, double)} specialization of
+ * {@link BiConsumer}. Unlike most other functional interfaces,
+ * {@code ObjDoubleConsumer} is expected to operate via side-effects.
+ *
+ * @param <T> Type of reference argument to {@code accept()}.
+ *
+ * @see BiConsumer
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface ObjDoubleConsumer<T> {
+
+ /**
+ * Accept a set of input values.
+ *
+ * @param t an input object
+ * @param value an input value
+ */
+ public void accept(T t, double value);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/ObjIntConsumer.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2012, 2013 Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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;
+
+/**
+ * An operation which accepts an object reference and an int, and returns no
+ * result. This is the {@code (reference, int)} specialization of
+ * {@link BiConsumer}. Unlike most other functional interfaces,
+ * {@code ObjIntConsumer} is expected to operate via side-effects.
+ *
+ * @param <T> Type of reference argument to {@code accept()}.
+ *
+ * @see BiConsumer
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface ObjIntConsumer<T> {
+
+ /**
+ * Accept a set of input values.
+ *
+ * @param t an input object
+ * @param value an input value
+ */
+ public void accept(T t, int value);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/ObjLongConsumer.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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;
+
+/**
+ * An operation which accepts an object reference and a long, and returns no
+ * result. This is the {@code (reference, long)} specialization of
+ * {@link BiConsumer}. Unlike most other functional interfaces,
+ * {@code ObjLongConsumer} is expected to operate via side-effects.
+ *
+ * @param <T> Type of reference argument to {@code accept()}.
+ *
+ * @see BiConsumer
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface ObjLongConsumer<T> {
+
+ /**
+ * Accept a set of input values.
+ *
+ * @param t an input object
+ * @param value an input value
+ */
+ public void accept(T t, long value);
+}
--- a/jdk/src/share/classes/java/util/function/Predicate.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/function/Predicate.java Tue Feb 19 11:56:49 2013 -0800
@@ -24,10 +24,12 @@
*/
package java.util.function;
+import java.util.Objects;
+
/**
* Determines if the input object matches some criteria.
*
- * @param <T> the type of input objects to {@code test}
+ * @param <T> the type of argument to {@code test}
*
* @since 1.8
*/
@@ -42,4 +44,57 @@
* {@code false}
*/
public boolean test(T t);
+
+ /**
+ * Returns 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.
+ *
+ * @param p a predicate which will be logically-ANDed with this predicate.
+ * @return a new predicate which returns {@code true} only if both
+ * predicates return {@code true}.
+ */
+ public default Predicate<T> and(Predicate<? super T> p) {
+ Objects.requireNonNull(p);
+ return (t) -> test(t) && p.test(t);
+ }
+
+ /**
+ * Returns a predicate which negates the result of this predicate.
+ *
+ * @return a new predicate who's result is always the opposite of this
+ * predicate.
+ */
+ public default Predicate<T> negate() {
+ return (t) -> !test(t);
+ }
+
+ /**
+ * Returns 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.
+ *
+ * @param p a predicate which will be logically-ORed with this predicate.
+ * @return a new predicate which returns {@code true} if either predicate
+ * returns {@code true}.
+ */
+ public default Predicate<T> or(Predicate<? super T> p) {
+ Objects.requireNonNull(p);
+ return (t) -> test(t) || p.test(t);
+ }
+
+ /**
+ * Returns a predicate that evaluates to {@code true} if both or neither of
+ * the component predicates evaluate to {@code true}.
+ *
+ * @param p a predicate which will be logically-XORed with this predicte.
+ * @return a predicate that evaluates to {@code true} if both or neither of
+ * the component predicates evaluate to {@code true}.
+ */
+ public default Predicate<T> xor(Predicate<? super T> p) {
+ Objects.requireNonNull(p);
+ return (t) -> test(t) ^ p.test(t);
+ }
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/ToDoubleBiFunction.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2012, 2013 Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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;
+
+/**
+ * Apply a function to the input arguments, yielding an appropriate result.
+ * This is the {@code double}-bearing specialization for {@link BiFunction}.
+ *
+ * @param <T> the type of the first argument to the {@code applyAsDouble}
+ * operation.
+ * @param <U> the type of the second argument to the {@code applyAsDouble}
+ * operation.
+ *
+ * @see BiFunction.
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface ToDoubleBiFunction<T, U> {
+
+ /**
+ * Compute the result of applying the function to the input arguments
+ *
+ * @param t an input object
+ * @param u an input object
+ * @return the function result value
+ */
+ public double applyAsDouble(T t, U u);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/ToDoubleFunction.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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;
+
+/**
+ * Apply a function to the input argument, yielding an appropriate result.
+ * This is the {@code double}-bearing specialization for {@link Function}.
+ *
+ * @param <T> the type of input objects to the function
+ *
+ * @see Function
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface ToDoubleFunction<T> {
+
+ /**
+ * Compute the result of applying the function to the input argument
+ *
+ * @param t the input object
+ * @return the function result value
+ */
+ public double applyAsDouble(T t);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/ToIntBiFunction.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+/**
+ * Apply a function to the input arguments, yielding an appropriate result.
+ * This is the {@code int}-bearing specialization for {@link BiFunction}.
+ *
+ * @param <T> the type of the first argument to the {@code applyAsLong}
+ * operation.
+ * @param <U> the type of the second argument to the {@code applyAsLong}
+ * operation.
+ *
+ * @see BiFunction
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface ToIntBiFunction<T, U> {
+
+ /**
+ * Compute the result of applying the function to the input arguments
+ *
+ * @param t an input object
+ * @param u an input object
+ * @return the function result value
+ */
+ public int applyAsInt(T t, U u);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/ToIntFunction.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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;
+
+/**
+ * Apply a function to the input argument, yielding an appropriate result.
+ * This is the {@code int}-bearing specialization for {@link Function}.
+ *
+ * @param <T> the type of input objects to the function
+ *
+ * @see Function
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface ToIntFunction<T> {
+
+ /**
+ * Compute the result of applying the function to the input arguments
+ *
+ * @param t the input object
+ * @return the function result value
+ */
+ public int applyAsInt(T t);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/ToLongBiFunction.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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;
+
+/**
+ * Apply a function to the input arguments, yielding an appropriate result.
+ * This is the {@code long}-bearing specialization for {@link BiFunction}.
+ *
+ * @param <T> the type of the first argument to the {@code applyAsLong}
+ * operation.
+ * @param <U> the type of the second argument to the {@code applyAsLong}
+ * operation.
+ *
+ * @see BiFunction
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface ToLongBiFunction<T, U> {
+
+ /**
+ * Compute the result of applying the function to the input arguments.
+ *
+ * @param t an input object
+ * @param u an input object
+ * @return the function result value
+ */
+ public long applyAsLong(T t, U u);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/util/function/ToLongFunction.java Tue Feb 19 11:56:49 2013 -0800
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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;
+
+/**
+ * Apply a function to the input argument, yielding an appropriate result.
+ * This is the {@code long}-bearing specialization for {@link Function}.
+ *
+ * @param <T> the type of input objects to the function
+ *
+ * @see Function
+ * @since 1.8
+ */
+@FunctionalInterface
+public interface ToLongFunction<T> {
+
+ /**
+ * Compute the result of applying the function to the input arguments.
+ *
+ * @param t the input object
+ * @return the function result value
+ */
+ public long applyAsLong(T t);
+}
--- a/jdk/src/share/classes/java/util/function/UnaryOperator.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/function/UnaryOperator.java Tue Feb 19 11:56:49 2013 -0800
@@ -26,20 +26,14 @@
/**
* An operation upon a single operand yielding a result. The operand and the
- * result are of the same type.
+ * result are of the same type. This is a specialization of {@code Function} for
+ * the case where the operand and result are of the same type.
*
- * @param <T> the type of operand to {@code operate} and of the result
+ * @param <T> the type of operand to {@code apply} and of the result
*
+ * @see Function
* @since 1.8
*/
@FunctionalInterface
-public interface UnaryOperator<T> {
-
- /**
- * Returns the result of the operation upon the operand.
- *
- * @param operand the operand
- * @return the operation result
- */
- public T operate(T operand);
+public interface UnaryOperator<T> extends Function<T, T> {
}
--- a/jdk/src/share/classes/java/util/function/package-info.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/src/share/classes/java/util/function/package-info.java Tue Feb 19 11:56:49 2013 -0800
@@ -22,27 +22,62 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
+
/**
- * <em>Functional interfaces</em> provide typing for lambda expressions. Each
- * functional interface provides a single abstract method to which the lambda
- * expression's parameter and return types are matched.
+ * <em>Functional interfaces</em> provide target types for lambda expressions
+ * and method references. Each functional interface has a single abstract method
+ * to which the lambda expression's parameter and return types are matched or
+ * adapted. Functional interfaces can provide a target type in multiple contexts,
+ * such as assignment context, method invocation, or cast context:
+ *
+ * <pre>
+ * Predicate<String> p = String::isEmpty;
+ *
+ * stream.filter(e -> e.getSize() > 10)...
*
- * <p>The interfaces in this package are all functional interfaces used with the
- * collections and streams frameworks. The operation identified by each
- * interface is generally applied to a collection or stream of objects.
+ * stream.map((ToIntFunction) e -> e.getSize())...
+ * </pre>
+ *
+ * <p>The interfaces in this package are functional interfaces used by the JDK,
+ * and are available to be used by user code as well. While they do not identify
+ * a complete set of function shapes to which lambda expressions might be adapted,
+ * they provide enough to cover common requirements.
*
- * <p>All functional interface implementations are expected to ensure that:
+ * <p>The interfaces in this package are annotated with @{link FunctionalInterface}.
+ * This annotation is not a requirement for the compiler to recognize an interface
+ * as a functional interface, but merely an aid to capture design intent and enlist the
+ * help of the compiler in identifying accidental violations of design intent.
+ *
+ * <p>The functional interfaces in this package follow an extensible naming convention,
+ * as follows:
+ *
* <ul>
- * <li>When used for aggregate operations upon many elements it should not be
- * assumed that the operation will be called upon elements in any specific order.
- * </li>
- * <li>{@code null} values are accepted and returned by these functional
- * interfaces according to the constraints of the specification in which the
- * functional interfaces are used. The functional interfaces themselves do not
- * constrain or mandate use of {@code null} values. Most usages of the
- * functional interfaces will define the role, if any, of {@code null} for that
- * context.
- * </li>
+ * <li>There are several basic function shapes, including {@link java.util.function.Function} ({@code T -> R}),
+ * {@link java.util.function.Consumer} ({@code T -> void}),
+ * {@link java.util.function.Predicate} ({@code T -> boolean}),
+ * and {@link java.util.function.Supplier} ({@code () -> T}).
+ * </li>
+ * <li>Function shapes have a natural arity based on how they are most commonly used.
+ * The basic shapes can be modified by an arity prefix to indicate a different arity,
+ * such as {@link java.util.function.BiFunction} ({@code (T, U) -> R}).
+ * </li>
+ * <li>There are additional derived function shapes which extend the basic function
+ * shapes, including {@link java.util.function.UnaryOperator} (extends {@code Function}) and
+ * {@link java.util.function.BinaryOperator} (extends {@code BiFunction}).
+ * </li>
+ * <li>Type parameters of functional interfaces can be specialized to primitives with
+ * additional type prefixes. To specialize the return type for a type that has both
+ * generic return type and generic arguments, we prefix {@code ToXxx}, as in
+ * {@link java.util.function.ToIntFunction}. Otherwise, type arguments are specialized left-to-right,
+ * as in {@link java.util.function.DoubleConsumer} or {@link java.util.function.ObjIntConsumer}.
+ * (The type prefix {@code Obj} is used to indicate that we don't want to specialize this parameter,
+ * but want to move on to the next parameter.) These schemes can be combined as in {@code IntToDoubleFunction}.
+ * </li>
+ * <li>If there are specialization prefixes for all arguments, the arity prefix may be left
+ * out (as in {@link java.util.function.ObjIntConsumer}).
+ * </li>
* </ul>
+ *
+ * @see java.lang.FunctionalInterface
*/
package java.util.function;
--- a/jdk/test/java/lang/PrimitiveSumMinMaxTest.java Tue Feb 19 10:34:26 2013 -0800
+++ b/jdk/test/java/lang/PrimitiveSumMinMaxTest.java Tue Feb 19 11:56:49 2013 -0800
@@ -50,20 +50,20 @@
BinaryOperator<Boolean> xor = Boolean::logicalXor;
Comparator<Boolean> cmp = Boolean::compare;
- assertTrue(and.operate(true, true));
- assertFalse(and.operate(true, false));
- assertFalse(and.operate(false, true));
- assertFalse(and.operate(false, false));
+ assertTrue(and.apply(true, true));
+ assertFalse(and.apply(true, false));
+ assertFalse(and.apply(false, true));
+ assertFalse(and.apply(false, false));
- assertTrue(or.operate(true, true));
- assertTrue(or.operate(true, false));
- assertTrue(or.operate(false, true));
- assertFalse(or.operate(false, false));
+ assertTrue(or.apply(true, true));
+ assertTrue(or.apply(true, false));
+ assertTrue(or.apply(false, true));
+ assertFalse(or.apply(false, false));
- assertFalse(xor.operate(true, true));
- assertTrue(xor.operate(true, false));
- assertTrue(xor.operate(false, true));
- assertFalse(xor.operate(false, false));
+ assertFalse(xor.apply(true, true));
+ assertTrue(xor.apply(true, false));
+ assertTrue(xor.apply(false, true));
+ assertFalse(xor.apply(false, false));
assertEquals(Boolean.TRUE.compareTo(Boolean.TRUE), cmp.compare(true, true));
assertEquals(Boolean.TRUE.compareTo(Boolean.FALSE), cmp.compare(true, false));
@@ -83,12 +83,12 @@
int[] numbers = { -1, 0, 1, 100, Integer.MAX_VALUE, Integer.MIN_VALUE };
for (int i : numbers) {
for (int j : numbers) {
- assertEquals(i+j, (int) sum1.operate(i, j));
- assertEquals(i+j, sum2.operateAsInt(i, j));
- assertEquals(Math.max(i,j), (int) max1.operate(i, j));
- assertEquals(Math.max(i,j), max2.operateAsInt(i, j));
- assertEquals(Math.min(i,j), (int) min1.operate(i, j));
- assertEquals(Math.min(i,j), min2.operateAsInt(i, j));
+ assertEquals(i+j, (int) sum1.apply(i, j));
+ assertEquals(i+j, sum2.applyAsInt(i, j));
+ assertEquals(Math.max(i,j), (int) max1.apply(i, j));
+ assertEquals(Math.max(i,j), max2.applyAsInt(i, j));
+ assertEquals(Math.min(i,j), (int) min1.apply(i, j));
+ assertEquals(Math.min(i,j), min2.applyAsInt(i, j));
assertEquals(((Integer) i).compareTo(j), cmp.compare(i, j));
}
}
@@ -106,12 +106,12 @@
long[] numbers = { -1, 0, 1, 100, Long.MAX_VALUE, Long.MIN_VALUE };
for (long i : numbers) {
for (long j : numbers) {
- assertEquals(i+j, (long) sum1.operate(i, j));
- assertEquals(i+j, sum2.operateAsLong(i, j));
- assertEquals(Math.max(i,j), (long) max1.operate(i, j));
- assertEquals(Math.max(i,j), max2.operateAsLong(i, j));
- assertEquals(Math.min(i,j), (long) min1.operate(i, j));
- assertEquals(Math.min(i,j), min2.operateAsLong(i, j));
+ assertEquals(i+j, (long) sum1.apply(i, j));
+ assertEquals(i+j, sum2.applyAsLong(i, j));
+ assertEquals(Math.max(i,j), (long) max1.apply(i, j));
+ assertEquals(Math.max(i,j), max2.applyAsLong(i, j));
+ assertEquals(Math.min(i,j), (long) min1.apply(i, j));
+ assertEquals(Math.min(i,j), min2.applyAsLong(i, j));
assertEquals(((Long) i).compareTo(j), cmp.compare(i, j));
}
}
@@ -126,9 +126,9 @@
float[] numbers = { -1, 0, 1, 100, Float.MAX_VALUE, Float.MIN_VALUE };
for (float i : numbers) {
for (float j : numbers) {
- assertEquals(i+j, (float) sum1.operate(i, j));
- assertEquals(Math.max(i,j), (float) max1.operate(i, j));
- assertEquals(Math.min(i,j), (float) min1.operate(i, j));
+ assertEquals(i+j, (float) sum1.apply(i, j));
+ assertEquals(Math.max(i,j), (float) max1.apply(i, j));
+ assertEquals(Math.min(i,j), (float) min1.apply(i, j));
assertEquals(((Float) i).compareTo(j), cmp.compare(i, j));
}
}
@@ -146,12 +146,12 @@
double[] numbers = { -1, 0, 1, 100, Double.MAX_VALUE, Double.MIN_VALUE };
for (double i : numbers) {
for (double j : numbers) {
- assertEquals(i+j, (double) sum1.operate(i, j));
- assertEquals(i+j, sum2.operateAsDouble(i, j));
- assertEquals(Math.max(i,j), (double) max1.operate(i, j));
- assertEquals(Math.max(i,j), max2.operateAsDouble(i, j));
- assertEquals(Math.min(i,j), (double) min1.operate(i, j));
- assertEquals(Math.min(i,j), min2.operateAsDouble(i, j));
+ assertEquals(i+j, (double) sum1.apply(i, j));
+ assertEquals(i+j, sum2.applyAsDouble(i, j));
+ assertEquals(Math.max(i,j), (double) max1.apply(i, j));
+ assertEquals(Math.max(i,j), max2.applyAsDouble(i, j));
+ assertEquals(Math.min(i,j), (double) min1.apply(i, j));
+ assertEquals(Math.min(i,j), min2.applyAsDouble(i, j));
assertEquals(((Double) i).compareTo(j), cmp.compare(i, j));
}
}