提交 7ab4a402 编写于 作者: M mduigou

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
上级 8cceef90
...@@ -70,7 +70,7 @@ import java.time.LocalDate; ...@@ -70,7 +70,7 @@ import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField; import java.time.temporal.ChronoField;
import java.util.Arrays; import java.util.Arrays;
import java.util.function.Block; import java.util.function.Consumer;
/** /**
* A reader for Hijrah Deviation files. * A reader for Hijrah Deviation files.
...@@ -126,13 +126,13 @@ final class HijrahDeviationReader { ...@@ -126,13 +126,13 @@ final class HijrahDeviationReader {
* @param typeId the name of the calendar * @param typeId the name of the calendar
* @param calendarType the calendar type * @param calendarType the calendar type
* @return {@code true} if the file was read and each entry accepted by the * @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 IOException for zip/jar file handling exception.
* @throws ParseException if the format of the configuration file is wrong. * @throws ParseException if the format of the configuration file is wrong.
*/ */
static boolean readDeviation(String typeId, String calendarType, 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); InputStream is = getConfigFileInputStream(typeId);
if (is != null) { if (is != null) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
...@@ -142,7 +142,7 @@ final class HijrahDeviationReader { ...@@ -142,7 +142,7 @@ final class HijrahDeviationReader {
num++; num++;
HijrahChronology.Deviation entry = parseLine(line, num); HijrahChronology.Deviation entry = parseLine(line, num);
if (entry != null) { if (entry != null) {
block.accept(entry); consumer.accept(entry);
} }
} }
} }
......
...@@ -219,7 +219,7 @@ public class AtomicInteger extends Number implements java.io.Serializable { ...@@ -219,7 +219,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
int prev, next; int prev, next;
do { do {
prev = get(); prev = get();
next = updateFunction.operateAsInt(prev); next = updateFunction.applyAsInt(prev);
} while (!compareAndSet(prev, next)); } while (!compareAndSet(prev, next));
return prev; return prev;
} }
...@@ -238,7 +238,7 @@ public class AtomicInteger extends Number implements java.io.Serializable { ...@@ -238,7 +238,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
int prev, next; int prev, next;
do { do {
prev = get(); prev = get();
next = updateFunction.operateAsInt(prev); next = updateFunction.applyAsInt(prev);
} while (!compareAndSet(prev, next)); } while (!compareAndSet(prev, next));
return next; return next;
} }
...@@ -262,7 +262,7 @@ public class AtomicInteger extends Number implements java.io.Serializable { ...@@ -262,7 +262,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
int prev, next; int prev, next;
do { do {
prev = get(); prev = get();
next = accumulatorFunction.operateAsInt(prev, x); next = accumulatorFunction.applyAsInt(prev, x);
} while (!compareAndSet(prev, next)); } while (!compareAndSet(prev, next));
return prev; return prev;
} }
...@@ -286,7 +286,7 @@ public class AtomicInteger extends Number implements java.io.Serializable { ...@@ -286,7 +286,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
int prev, next; int prev, next;
do { do {
prev = get(); prev = get();
next = accumulatorFunction.operateAsInt(prev, x); next = accumulatorFunction.applyAsInt(prev, x);
} while (!compareAndSet(prev, next)); } while (!compareAndSet(prev, next));
return next; return next;
} }
......
...@@ -263,7 +263,7 @@ public class AtomicIntegerArray implements java.io.Serializable { ...@@ -263,7 +263,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
int prev, next; int prev, next;
do { do {
prev = getRaw(offset); prev = getRaw(offset);
next = updateFunction.operateAsInt(prev); next = updateFunction.applyAsInt(prev);
} while (!compareAndSetRaw(offset, prev, next)); } while (!compareAndSetRaw(offset, prev, next));
return prev; return prev;
} }
...@@ -284,7 +284,7 @@ public class AtomicIntegerArray implements java.io.Serializable { ...@@ -284,7 +284,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
int prev, next; int prev, next;
do { do {
prev = getRaw(offset); prev = getRaw(offset);
next = updateFunction.operateAsInt(prev); next = updateFunction.applyAsInt(prev);
} while (!compareAndSetRaw(offset, prev, next)); } while (!compareAndSetRaw(offset, prev, next));
return next; return next;
} }
...@@ -310,7 +310,7 @@ public class AtomicIntegerArray implements java.io.Serializable { ...@@ -310,7 +310,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
int prev, next; int prev, next;
do { do {
prev = getRaw(offset); prev = getRaw(offset);
next = accumulatorFunction.operateAsInt(prev, x); next = accumulatorFunction.applyAsInt(prev, x);
} while (!compareAndSetRaw(offset, prev, next)); } while (!compareAndSetRaw(offset, prev, next));
return prev; return prev;
} }
...@@ -336,7 +336,7 @@ public class AtomicIntegerArray implements java.io.Serializable { ...@@ -336,7 +336,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
int prev, next; int prev, next;
do { do {
prev = getRaw(offset); prev = getRaw(offset);
next = accumulatorFunction.operateAsInt(prev, x); next = accumulatorFunction.applyAsInt(prev, x);
} while (!compareAndSetRaw(offset, prev, next)); } while (!compareAndSetRaw(offset, prev, next));
return next; return next;
} }
......
...@@ -281,7 +281,7 @@ public abstract class AtomicIntegerFieldUpdater<T> { ...@@ -281,7 +281,7 @@ public abstract class AtomicIntegerFieldUpdater<T> {
int prev, next; int prev, next;
do { do {
prev = get(obj); prev = get(obj);
next = updateFunction.operateAsInt(prev); next = updateFunction.applyAsInt(prev);
} while (!compareAndSet(obj, prev, next)); } while (!compareAndSet(obj, prev, next));
return prev; return prev;
} }
...@@ -301,7 +301,7 @@ public abstract class AtomicIntegerFieldUpdater<T> { ...@@ -301,7 +301,7 @@ public abstract class AtomicIntegerFieldUpdater<T> {
int prev, next; int prev, next;
do { do {
prev = get(obj); prev = get(obj);
next = updateFunction.operateAsInt(prev); next = updateFunction.applyAsInt(prev);
} while (!compareAndSet(obj, prev, next)); } while (!compareAndSet(obj, prev, next));
return next; return next;
} }
...@@ -326,7 +326,7 @@ public abstract class AtomicIntegerFieldUpdater<T> { ...@@ -326,7 +326,7 @@ public abstract class AtomicIntegerFieldUpdater<T> {
int prev, next; int prev, next;
do { do {
prev = get(obj); prev = get(obj);
next = accumulatorFunction.operateAsInt(prev, x); next = accumulatorFunction.applyAsInt(prev, x);
} while (!compareAndSet(obj, prev, next)); } while (!compareAndSet(obj, prev, next));
return prev; return prev;
} }
...@@ -351,7 +351,7 @@ public abstract class AtomicIntegerFieldUpdater<T> { ...@@ -351,7 +351,7 @@ public abstract class AtomicIntegerFieldUpdater<T> {
int prev, next; int prev, next;
do { do {
prev = get(obj); prev = get(obj);
next = accumulatorFunction.operateAsInt(prev, x); next = accumulatorFunction.applyAsInt(prev, x);
} while (!compareAndSet(obj, prev, next)); } while (!compareAndSet(obj, prev, next));
return next; return next;
} }
......
...@@ -233,7 +233,7 @@ public class AtomicLong extends Number implements java.io.Serializable { ...@@ -233,7 +233,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
long prev, next; long prev, next;
do { do {
prev = get(); prev = get();
next = updateFunction.operateAsLong(prev); next = updateFunction.applyAsLong(prev);
} while (!compareAndSet(prev, next)); } while (!compareAndSet(prev, next));
return prev; return prev;
} }
...@@ -252,7 +252,7 @@ public class AtomicLong extends Number implements java.io.Serializable { ...@@ -252,7 +252,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
long prev, next; long prev, next;
do { do {
prev = get(); prev = get();
next = updateFunction.operateAsLong(prev); next = updateFunction.applyAsLong(prev);
} while (!compareAndSet(prev, next)); } while (!compareAndSet(prev, next));
return next; return next;
} }
...@@ -276,7 +276,7 @@ public class AtomicLong extends Number implements java.io.Serializable { ...@@ -276,7 +276,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
long prev, next; long prev, next;
do { do {
prev = get(); prev = get();
next = accumulatorFunction.operateAsLong(prev, x); next = accumulatorFunction.applyAsLong(prev, x);
} while (!compareAndSet(prev, next)); } while (!compareAndSet(prev, next));
return prev; return prev;
} }
...@@ -300,7 +300,7 @@ public class AtomicLong extends Number implements java.io.Serializable { ...@@ -300,7 +300,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
long prev, next; long prev, next;
do { do {
prev = get(); prev = get();
next = accumulatorFunction.operateAsLong(prev, x); next = accumulatorFunction.applyAsLong(prev, x);
} while (!compareAndSet(prev, next)); } while (!compareAndSet(prev, next));
return next; return next;
} }
......
...@@ -262,7 +262,7 @@ public class AtomicLongArray implements java.io.Serializable { ...@@ -262,7 +262,7 @@ public class AtomicLongArray implements java.io.Serializable {
long prev, next; long prev, next;
do { do {
prev = getRaw(offset); prev = getRaw(offset);
next = updateFunction.operateAsLong(prev); next = updateFunction.applyAsLong(prev);
} while (!compareAndSetRaw(offset, prev, next)); } while (!compareAndSetRaw(offset, prev, next));
return prev; return prev;
} }
...@@ -283,7 +283,7 @@ public class AtomicLongArray implements java.io.Serializable { ...@@ -283,7 +283,7 @@ public class AtomicLongArray implements java.io.Serializable {
long prev, next; long prev, next;
do { do {
prev = getRaw(offset); prev = getRaw(offset);
next = updateFunction.operateAsLong(prev); next = updateFunction.applyAsLong(prev);
} while (!compareAndSetRaw(offset, prev, next)); } while (!compareAndSetRaw(offset, prev, next));
return next; return next;
} }
...@@ -309,7 +309,7 @@ public class AtomicLongArray implements java.io.Serializable { ...@@ -309,7 +309,7 @@ public class AtomicLongArray implements java.io.Serializable {
long prev, next; long prev, next;
do { do {
prev = getRaw(offset); prev = getRaw(offset);
next = accumulatorFunction.operateAsLong(prev, x); next = accumulatorFunction.applyAsLong(prev, x);
} while (!compareAndSetRaw(offset, prev, next)); } while (!compareAndSetRaw(offset, prev, next));
return prev; return prev;
} }
...@@ -335,7 +335,7 @@ public class AtomicLongArray implements java.io.Serializable { ...@@ -335,7 +335,7 @@ public class AtomicLongArray implements java.io.Serializable {
long prev, next; long prev, next;
do { do {
prev = getRaw(offset); prev = getRaw(offset);
next = accumulatorFunction.operateAsLong(prev, x); next = accumulatorFunction.applyAsLong(prev, x);
} while (!compareAndSetRaw(offset, prev, next)); } while (!compareAndSetRaw(offset, prev, next));
return next; return next;
} }
......
...@@ -284,7 +284,7 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -284,7 +284,7 @@ public abstract class AtomicLongFieldUpdater<T> {
long prev, next; long prev, next;
do { do {
prev = get(obj); prev = get(obj);
next = updateFunction.operateAsLong(prev); next = updateFunction.applyAsLong(prev);
} while (!compareAndSet(obj, prev, next)); } while (!compareAndSet(obj, prev, next));
return prev; return prev;
} }
...@@ -304,7 +304,7 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -304,7 +304,7 @@ public abstract class AtomicLongFieldUpdater<T> {
long prev, next; long prev, next;
do { do {
prev = get(obj); prev = get(obj);
next = updateFunction.operateAsLong(prev); next = updateFunction.applyAsLong(prev);
} while (!compareAndSet(obj, prev, next)); } while (!compareAndSet(obj, prev, next));
return next; return next;
} }
...@@ -329,7 +329,7 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -329,7 +329,7 @@ public abstract class AtomicLongFieldUpdater<T> {
long prev, next; long prev, next;
do { do {
prev = get(obj); prev = get(obj);
next = accumulatorFunction.operateAsLong(prev, x); next = accumulatorFunction.applyAsLong(prev, x);
} while (!compareAndSet(obj, prev, next)); } while (!compareAndSet(obj, prev, next));
return prev; return prev;
} }
...@@ -354,7 +354,7 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -354,7 +354,7 @@ public abstract class AtomicLongFieldUpdater<T> {
long prev, next; long prev, next;
do { do {
prev = get(obj); prev = get(obj);
next = accumulatorFunction.operateAsLong(prev, x); next = accumulatorFunction.applyAsLong(prev, x);
} while (!compareAndSet(obj, prev, next)); } while (!compareAndSet(obj, prev, next));
return next; return next;
} }
......
...@@ -157,7 +157,7 @@ public class AtomicReference<V> implements java.io.Serializable { ...@@ -157,7 +157,7 @@ public class AtomicReference<V> implements java.io.Serializable {
V prev, next; V prev, next;
do { do {
prev = get(); prev = get();
next = updateFunction.operate(prev); next = updateFunction.apply(prev);
} while (!compareAndSet(prev, next)); } while (!compareAndSet(prev, next));
return prev; return prev;
} }
...@@ -176,7 +176,7 @@ public class AtomicReference<V> implements java.io.Serializable { ...@@ -176,7 +176,7 @@ public class AtomicReference<V> implements java.io.Serializable {
V prev, next; V prev, next;
do { do {
prev = get(); prev = get();
next = updateFunction.operate(prev); next = updateFunction.apply(prev);
} while (!compareAndSet(prev, next)); } while (!compareAndSet(prev, next));
return next; return next;
} }
...@@ -200,7 +200,7 @@ public class AtomicReference<V> implements java.io.Serializable { ...@@ -200,7 +200,7 @@ public class AtomicReference<V> implements java.io.Serializable {
V prev, next; V prev, next;
do { do {
prev = get(); prev = get();
next = accumulatorFunction.operate(prev, x); next = accumulatorFunction.apply(prev, x);
} while (!compareAndSet(prev, next)); } while (!compareAndSet(prev, next));
return prev; return prev;
} }
...@@ -224,7 +224,7 @@ public class AtomicReference<V> implements java.io.Serializable { ...@@ -224,7 +224,7 @@ public class AtomicReference<V> implements java.io.Serializable {
V prev, next; V prev, next;
do { do {
prev = get(); prev = get();
next = accumulatorFunction.operate(prev, x); next = accumulatorFunction.apply(prev, x);
} while (!compareAndSet(prev, next)); } while (!compareAndSet(prev, next));
return next; return next;
} }
......
...@@ -217,7 +217,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable { ...@@ -217,7 +217,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
E prev, next; E prev, next;
do { do {
prev = getRaw(offset); prev = getRaw(offset);
next = updateFunction.operate(prev); next = updateFunction.apply(prev);
} while (!compareAndSetRaw(offset, prev, next)); } while (!compareAndSetRaw(offset, prev, next));
return prev; return prev;
} }
...@@ -238,7 +238,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable { ...@@ -238,7 +238,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
E prev, next; E prev, next;
do { do {
prev = getRaw(offset); prev = getRaw(offset);
next = updateFunction.operate(prev); next = updateFunction.apply(prev);
} while (!compareAndSetRaw(offset, prev, next)); } while (!compareAndSetRaw(offset, prev, next));
return next; return next;
} }
...@@ -264,7 +264,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable { ...@@ -264,7 +264,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
E prev, next; E prev, next;
do { do {
prev = getRaw(offset); prev = getRaw(offset);
next = accumulatorFunction.operate(prev, x); next = accumulatorFunction.apply(prev, x);
} while (!compareAndSetRaw(offset, prev, next)); } while (!compareAndSetRaw(offset, prev, next));
return prev; return prev;
} }
...@@ -290,7 +290,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable { ...@@ -290,7 +290,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
E prev, next; E prev, next;
do { do {
prev = getRaw(offset); prev = getRaw(offset);
next = accumulatorFunction.operate(prev, x); next = accumulatorFunction.apply(prev, x);
} while (!compareAndSetRaw(offset, prev, next)); } while (!compareAndSetRaw(offset, prev, next));
return next; return next;
} }
......
...@@ -200,7 +200,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> { ...@@ -200,7 +200,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
V prev, next; V prev, next;
do { do {
prev = get(obj); prev = get(obj);
next = updateFunction.operate(prev); next = updateFunction.apply(prev);
} while (!compareAndSet(obj, prev, next)); } while (!compareAndSet(obj, prev, next));
return prev; return prev;
} }
...@@ -220,7 +220,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> { ...@@ -220,7 +220,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
V prev, next; V prev, next;
do { do {
prev = get(obj); prev = get(obj);
next = updateFunction.operate(prev); next = updateFunction.apply(prev);
} while (!compareAndSet(obj, prev, next)); } while (!compareAndSet(obj, prev, next));
return next; return next;
} }
...@@ -245,7 +245,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> { ...@@ -245,7 +245,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
V prev, next; V prev, next;
do { do {
prev = get(obj); prev = get(obj);
next = accumulatorFunction.operate(prev, x); next = accumulatorFunction.apply(prev, x);
} while (!compareAndSet(obj, prev, next)); } while (!compareAndSet(obj, prev, next));
return prev; return prev;
} }
...@@ -270,7 +270,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> { ...@@ -270,7 +270,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
V prev, next; V prev, next;
do { do {
prev = get(obj); prev = get(obj);
next = accumulatorFunction.operate(prev, x); next = accumulatorFunction.apply(prev, x);
} while (!compareAndSet(obj, prev, next)); } while (!compareAndSet(obj, prev, next));
return next; return next;
} }
......
...@@ -100,14 +100,14 @@ public class DoubleAccumulator extends Striped64 implements Serializable { ...@@ -100,14 +100,14 @@ public class DoubleAccumulator extends Striped64 implements Serializable {
Cell[] as; long b, v, r; int m; Cell a; Cell[] as; long b, v, r; int m; Cell a;
if ((as = cells) != null || if ((as = cells) != null ||
(r = Double.doubleToRawLongBits (r = Double.doubleToRawLongBits
(function.operateAsDouble (function.applyAsDouble
(Double.longBitsToDouble(b = base), x))) != b && !casBase(b, r)) { (Double.longBitsToDouble(b = base), x))) != b && !casBase(b, r)) {
boolean uncontended = true; boolean uncontended = true;
if (as == null || (m = as.length - 1) < 0 || if (as == null || (m = as.length - 1) < 0 ||
(a = as[getProbe() & m]) == null || (a = as[getProbe() & m]) == null ||
!(uncontended = !(uncontended =
(r = Double.doubleToRawLongBits (r = Double.doubleToRawLongBits
(function.operateAsDouble (function.applyAsDouble
(Double.longBitsToDouble(v = a.value), x))) == v || (Double.longBitsToDouble(v = a.value), x))) == v ||
a.cas(v, r))) a.cas(v, r)))
doubleAccumulate(x, function, uncontended); doubleAccumulate(x, function, uncontended);
...@@ -129,7 +129,7 @@ public class DoubleAccumulator extends Striped64 implements Serializable { ...@@ -129,7 +129,7 @@ public class DoubleAccumulator extends Striped64 implements Serializable {
if (as != null) { if (as != null) {
for (int i = 0; i < as.length; ++i) { for (int i = 0; i < as.length; ++i) {
if ((a = as[i]) != null) if ((a = as[i]) != null)
result = function.operateAsDouble result = function.applyAsDouble
(result, Double.longBitsToDouble(a.value)); (result, Double.longBitsToDouble(a.value));
} }
} }
...@@ -174,7 +174,7 @@ public class DoubleAccumulator extends Striped64 implements Serializable { ...@@ -174,7 +174,7 @@ public class DoubleAccumulator extends Striped64 implements Serializable {
if ((a = as[i]) != null) { if ((a = as[i]) != null) {
double v = Double.longBitsToDouble(a.value); double v = Double.longBitsToDouble(a.value);
a.value = identity; a.value = identity;
result = function.operateAsDouble(result, v); result = function.applyAsDouble(result, v);
} }
} }
} }
......
...@@ -101,12 +101,12 @@ public class LongAccumulator extends Striped64 implements Serializable { ...@@ -101,12 +101,12 @@ public class LongAccumulator extends Striped64 implements Serializable {
public void accumulate(long x) { public void accumulate(long x) {
Cell[] as; long b, v, r; int m; Cell a; Cell[] as; long b, v, r; int m; Cell a;
if ((as = cells) != null || 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; boolean uncontended = true;
if (as == null || (m = as.length - 1) < 0 || if (as == null || (m = as.length - 1) < 0 ||
(a = as[getProbe() & m]) == null || (a = as[getProbe() & m]) == null ||
!(uncontended = !(uncontended =
(r = function.operateAsLong(v = a.value, x)) == v || (r = function.applyAsLong(v = a.value, x)) == v ||
a.cas(v, r))) a.cas(v, r)))
longAccumulate(x, function, uncontended); longAccumulate(x, function, uncontended);
} }
...@@ -127,7 +127,7 @@ public class LongAccumulator extends Striped64 implements Serializable { ...@@ -127,7 +127,7 @@ public class LongAccumulator extends Striped64 implements Serializable {
if (as != null) { if (as != null) {
for (int i = 0; i < as.length; ++i) { for (int i = 0; i < as.length; ++i) {
if ((a = as[i]) != null) if ((a = as[i]) != null)
result = function.operateAsLong(result, a.value); result = function.applyAsLong(result, a.value);
} }
} }
return result; return result;
...@@ -171,7 +171,7 @@ public class LongAccumulator extends Striped64 implements Serializable { ...@@ -171,7 +171,7 @@ public class LongAccumulator extends Striped64 implements Serializable {
if ((a = as[i]) != null) { if ((a = as[i]) != null) {
long v = a.value; long v = a.value;
a.value = identity; a.value = identity;
result = function.operateAsLong(result, v); result = function.applyAsLong(result, v);
} }
} }
} }
......
...@@ -253,7 +253,7 @@ abstract class Striped64 extends Number { ...@@ -253,7 +253,7 @@ abstract class Striped64 extends Number {
else if (!wasUncontended) // CAS already known to fail else if (!wasUncontended) // CAS already known to fail
wasUncontended = true; // Continue after rehash wasUncontended = true; // Continue after rehash
else if (a.cas(v = a.value, ((fn == null) ? v + x : else if (a.cas(v = a.value, ((fn == null) ? v + x :
fn.operateAsLong(v, x)))) fn.applyAsLong(v, x))))
break; break;
else if (n >= NCPU || cells != as) else if (n >= NCPU || cells != as)
collide = false; // At max size or stale collide = false; // At max size or stale
...@@ -291,7 +291,7 @@ abstract class Striped64 extends Number { ...@@ -291,7 +291,7 @@ abstract class Striped64 extends Number {
break; break;
} }
else if (casBase(v = base, ((fn == null) ? v + x : else if (casBase(v = base, ((fn == null) ? v + x :
fn.operateAsLong(v, x)))) fn.applyAsLong(v, x))))
break; // Fall back on using base break; // Fall back on using base
} }
} }
...@@ -344,7 +344,7 @@ abstract class Striped64 extends Number { ...@@ -344,7 +344,7 @@ abstract class Striped64 extends Number {
Double.doubleToRawLongBits Double.doubleToRawLongBits
(Double.longBitsToDouble(v) + x) : (Double.longBitsToDouble(v) + x) :
Double.doubleToRawLongBits Double.doubleToRawLongBits
(fn.operateAsDouble (fn.applyAsDouble
(Double.longBitsToDouble(v), x))))) (Double.longBitsToDouble(v), x)))))
break; break;
else if (n >= NCPU || cells != as) else if (n >= NCPU || cells != as)
...@@ -387,7 +387,7 @@ abstract class Striped64 extends Number { ...@@ -387,7 +387,7 @@ abstract class Striped64 extends Number {
Double.doubleToRawLongBits Double.doubleToRawLongBits
(Double.longBitsToDouble(v) + x) : (Double.longBitsToDouble(v) + x) :
Double.doubleToRawLongBits Double.doubleToRawLongBits
(fn.operateAsDouble (fn.applyAsDouble
(Double.longBitsToDouble(v), x))))) (Double.longBitsToDouble(v), x)))))
break; // Fall back on using base break; // Fall back on using base
} }
......
/*
* 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);
}
/*
* 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);
}
/*
* 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);
}
}
...@@ -25,24 +25,14 @@ ...@@ -25,24 +25,14 @@
package java.util.function; package java.util.function;
/** /**
* An operation upon two operands yielding a result. The operands and the result * An operation upon two operands yielding a result. This is a specialization of
* are all of the same type. * {@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 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface BinaryOperator<T> { public interface BinaryOperator<T> extends BiFunction<T,T,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);
} }
/*
* 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();
}
...@@ -25,19 +25,19 @@ ...@@ -25,19 +25,19 @@
package java.util.function; package java.util.function;
/** /**
* An operation upon an input object. The operation may modify that object or * An operation which accepts a single input argument and returns no result.
* external state (other objects). * Unlike most other functional interfaces, {@code Consumer} is expected to
* operate via side-effects.
* *
* @param <T> The type of input objects to {@code accept} * @param <T> The type of input objects to {@code accept}
* *
* @since 1.8 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface Block<T> { public interface Consumer<T> {
/** /**
* Use the input object in operations which may modify that object or * Accept an input value.
* external state (other objects).
* *
* @param t the input object * @param t the input object
*/ */
......
...@@ -26,23 +26,22 @@ package java.util.function; ...@@ -26,23 +26,22 @@ package java.util.function;
/** /**
* An operation on two {@code double} operands yielding a {@code double} result. * 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 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface DoubleBinaryOperator /* extends BinaryOperator<Double> */ { public interface DoubleBinaryOperator {
//
// @Override
// public default Double operate(Double left, Double right) { return operateAsDouble((double) left, (double) right); }
/** /**
* Returns the {@code double} result of the operation upon the * Returns the {@code double} result of the operation upon the
* {@code double} operands. The parameters are named {@code left} and * {@code double} operands. The parameters are named {@code left} and
* {@code right} for operations where the order of parameters matters. * {@code right} for operations where the order of parameters matters.
* *
* @param left the left operand value * @param left the left operand value
* @param right the right operand value * @param right the right operand value
* @return the result of the operation * @return the result of the operation
*/ */
public double operateAsDouble(double left, double right); public double applyAsDouble(double left, double right);
} }
...@@ -25,22 +25,21 @@ ...@@ -25,22 +25,21 @@
package java.util.function; package java.util.function;
/** /**
* An operation upon a {@code double} input value. The operation may modify * An operation which accepts a single double argument and returns no result.
* external state. * This is the primitive type specialization of {@link Consumer} for
* * {@code double}. Unlike most other functional interfaces,
* <p/>This is the primitive type specialization of {@link Block} for * {@code DoubleConsumer} is expected to operate via side-effects.
* {@code double} and also may be used as a {@code Block<Double>}.
* *
* @see Consumer
* @since 1.8 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface DoubleBlock { public interface DoubleConsumer {
/** /**
* Use the {@code double} input value in an operation which may modify * Accept an input value.
* external state.
* *
* @param t the input value * @param value the input value
*/ */
public void accept(double t); public void accept(double value);
} }
...@@ -25,22 +25,23 @@ ...@@ -25,22 +25,23 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the input object yielding an appropriate {@code double} * Apply a function to the double-valued input argument, yielding an appropriate
* value; this is the {@code double}-bearing specialization for {@link Function}. * 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 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface DoubleFunction<T> { public interface DoubleFunction<R> {
/** /**
* Apply a function to the input object yielding an appropriate * Compute the result of applying the function to the input argument
* {@code double} value.
* *
* @param t the input object * @param value the input value
* @return the function result value * @return the function result
*/ */
public double applyAsDouble(T t); public R apply(double value);
} }
/*
* 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);
}
}
...@@ -25,11 +25,10 @@ ...@@ -25,11 +25,10 @@
package java.util.function; 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 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
......
...@@ -25,9 +25,11 @@ ...@@ -25,9 +25,11 @@
package java.util.function; package java.util.function;
/** /**
* An operation on a single {@code double} operand yielding a {@code double} * An operation on a {@code double} operand yielding a {@code double}
* result. * result. This is the primitive type specialization of {@link UnaryOperator}
* for {@code double}.
* *
* @see UnaryOperator
* @since 1.8 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
...@@ -40,5 +42,5 @@ public interface DoubleUnaryOperator { ...@@ -40,5 +42,5 @@ public interface DoubleUnaryOperator {
* @param operand the operand value * @param operand the operand value
* @return the operation result value * @return the operation result value
*/ */
public double operateAsDouble(double operand); public double applyAsDouble(double operand);
} }
...@@ -24,14 +24,14 @@ ...@@ -24,14 +24,14 @@
*/ */
package java.util.function; 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 * function may variously provide a mapping between types, object instances or
* keys and values or any other form of transformation upon the input. * 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 <T> the type of the input to the {@code apply} operation.
* @param <R> the type of result objects from the {@code apply} operation. May * @param <R> the type of the result of the {@code apply} operation.
* be the same type as {@code <T>}.
* *
* @since 1.8 * @since 1.8
*/ */
...@@ -39,7 +39,7 @@ package java.util.function; ...@@ -39,7 +39,7 @@ package java.util.function;
public interface Function<T, R> { 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 * @param t the input object
* @return the function result * @return the function result
......
...@@ -26,7 +26,10 @@ package java.util.function; ...@@ -26,7 +26,10 @@ package java.util.function;
/** /**
* An operation on two {@code int} operands yielding an {@code int} result. * 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 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
...@@ -41,5 +44,5 @@ public interface IntBinaryOperator { ...@@ -41,5 +44,5 @@ public interface IntBinaryOperator {
* @param right the right operand value * @param right the right operand value
* @return the result of the operation * @return the result of the operation
*/ */
public int operateAsInt(int left, int right); public int applyAsInt(int left, int right);
} }
...@@ -25,22 +25,21 @@ ...@@ -25,22 +25,21 @@
package java.util.function; package java.util.function;
/** /**
* An operation upon an {@code int} input value. The operation may modify * An operation which accepts a single integer argument and returns no result.
* external state. * This is the primitive type specialization of {@link Consumer} for {@code int}.
* * Unlike most other functional interfaces, {@code IntConsumer} is expected to
* <p/>This is the primitive type specialization of {@link Block} for * operate via side-effects.
* {@code int} and also may be used as a {@code Block<Integer>}.
* *
* @see Consumer
* @since 1.8 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface IntBlock { public interface IntConsumer {
/** /**
* Use the {@code int} input value in an operation which may modify external * Accept an input value.
* state.
* *
* @param t the input value * @param value the input value
*/ */
public void accept(int t); public void accept(int value);
} }
...@@ -25,22 +25,23 @@ ...@@ -25,22 +25,23 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the input object yielding an appropriate {@code int} * Apply a function to the integer-valued input argument, yielding an
* value; this is the {@code int}-bearing specialization for {@link Function}. * 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 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface IntFunction<T> { public interface IntFunction<R> {
/** /**
* Apply a function to the input object yielding an appropriate {@code int} * Compute the result of applying the function to the input argument
* value.
* *
* @param t the input object * @param value the input value
* @return the function result value * @return the function result
*/ */
public int applyAsInt(T t); public R apply(int value);
} }
/*
* 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);
}
}
...@@ -25,11 +25,10 @@ ...@@ -25,11 +25,10 @@
package java.util.function; 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 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
......
...@@ -26,18 +26,21 @@ package java.util.function; ...@@ -26,18 +26,21 @@ package java.util.function;
/** /**
* An operation on a single {@code int} operand yielding an {@code int} result. * 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 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface IntUnaryOperator { public interface IntUnaryOperator {
/** /**
* Returns the {@code int} result of the operation upon the {@code int} * Returns the {@code int} value result of the operation upon the
* operand. * {@code int} operand.
* *
* @param operand the operand value * @param operand the operand value
* @return the operation result value * @return the operation result value
*/ */
public int operateAsInt(int operand); public int applyAsInt(int operand);
} }
...@@ -26,7 +26,10 @@ package java.util.function; ...@@ -26,7 +26,10 @@ package java.util.function;
/** /**
* An operation on two {@code long} operands yielding a {@code long} result. * 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 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
...@@ -41,5 +44,5 @@ public interface LongBinaryOperator { ...@@ -41,5 +44,5 @@ public interface LongBinaryOperator {
* @param right the right operand value * @param right the right operand value
* @return the result of the operation * @return the result of the operation
*/ */
public long operateAsLong(long left, long right); public long applyAsLong(long left, long right);
} }
...@@ -25,22 +25,21 @@ ...@@ -25,22 +25,21 @@
package java.util.function; package java.util.function;
/** /**
* An operation upon a {@code long} input value. The operation may modify * An operation which accepts a single long argument and returns no result.
* external state. * This is the {@code long}-consuming primitive type specialization of
* * {@link Consumer}. Unlike most other functional interfaces, {@code LongConsumer}
* <p/>This is the primitive type specialization of {@link Block} for * is expected to operate via side-effects.
* {@code long} and also may be used as a {@code Block<Long>}.
* *
* @see Consumer
* @since 1.8 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface LongBlock { public interface LongConsumer {
/** /**
* Use the {@code long} input value in an operation which may modify * Accept an input value.
* external state.
* *
* @param t the input value * @param value the input value
*/ */
public void accept(long t); public void accept(long value);
} }
...@@ -25,22 +25,23 @@ ...@@ -25,22 +25,23 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the input object yielding an appropriate {@code long} * Apply a function to the long-valued input argument, yielding an appropriate
* value; this is the {@code long}-bearing specialization for {@link Function}. * 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 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface LongFunction<T> { public interface LongFunction<R> {
/** /**
* Apply a function to the input object yielding an appropriate {@code long} * Compute the result of applying the function to the input argument
* value.
* *
* @param t the input object * @param value the input value
* @return the function result value * @return the function result
*/ */
public long applyAsLong(T t); public R apply(long value);
} }
/*
* 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);
}
}
...@@ -25,11 +25,10 @@ ...@@ -25,11 +25,10 @@
package java.util.function; 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 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
...@@ -38,7 +37,7 @@ public interface LongSupplier { ...@@ -38,7 +37,7 @@ public interface LongSupplier {
/** /**
* Returns a {@code long} value. * Returns a {@code long} value.
* *
* @return a {@code long} value. * @return a {@code long} value
*/ */
public long getAsLong(); public long getAsLong();
} }
...@@ -26,7 +26,10 @@ package java.util.function; ...@@ -26,7 +26,10 @@ package java.util.function;
/** /**
* An operation on a single {@code long} operand yielding a {@code long} result. * 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 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
...@@ -39,5 +42,5 @@ public interface LongUnaryOperator { ...@@ -39,5 +42,5 @@ public interface LongUnaryOperator {
* @param operand the operand value * @param operand the operand value
* @return the operation result value * @return the operation result value
*/ */
public long operateAsLong(long operand); public long applyAsLong(long operand);
} }
/*
* 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);
}
/*
* 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);
}
/*
* 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);
}
...@@ -24,10 +24,12 @@ ...@@ -24,10 +24,12 @@
*/ */
package java.util.function; package java.util.function;
import java.util.Objects;
/** /**
* Determines if the input object matches some criteria. * 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 * @since 1.8
*/ */
...@@ -42,4 +44,57 @@ public interface Predicate<T> { ...@@ -42,4 +44,57 @@ public interface Predicate<T> {
* {@code false} * {@code false}
*/ */
public boolean test(T t); 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);
}
} }
/*
* 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);
}
/*
* 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);
}
/*
* 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);
}
/*
* 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);
}
/*
* 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);
}
/*
* 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);
}
...@@ -26,20 +26,14 @@ package java.util.function; ...@@ -26,20 +26,14 @@ package java.util.function;
/** /**
* An operation upon a single operand yielding a result. The operand and the * 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 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface UnaryOperator<T> { public interface UnaryOperator<T> extends Function<T, T> {
/**
* Returns the result of the operation upon the operand.
*
* @param operand the operand
* @return the operation result
*/
public T operate(T operand);
} }
...@@ -22,27 +22,62 @@ ...@@ -22,27 +22,62 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
/** /**
* <em>Functional interfaces</em> provide typing for lambda expressions. Each * <em>Functional interfaces</em> provide target types for lambda expressions
* functional interface provides a single abstract method to which the lambda * and method references. Each functional interface has a single abstract method
* expression's parameter and return types are matched. * 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:
* *
* <p>The interfaces in this package are all functional interfaces used with the * <pre>
* collections and streams frameworks. The operation identified by each * Predicate&lt;String> p = String::isEmpty;
* interface is generally applied to a collection or stream of objects. *
* stream.filter(e -> e.getSize() > 10)...
*
* 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>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:
* *
* <p>All functional interface implementations are expected to ensure that:
* <ul> * <ul>
* <li>When used for aggregate operations upon many elements it should not be * <li>There are several basic function shapes, including {@link java.util.function.Function} ({@code T -> R}),
* assumed that the operation will be called upon elements in any specific order. * {@link java.util.function.Consumer} ({@code T -> void}),
* </li> * {@link java.util.function.Predicate} ({@code T -> boolean}),
* <li>{@code null} values are accepted and returned by these functional * and {@link java.util.function.Supplier} ({@code () -> T}).
* interfaces according to the constraints of the specification in which the * </li>
* functional interfaces are used. The functional interfaces themselves do not * <li>Function shapes have a natural arity based on how they are most commonly used.
* constrain or mandate use of {@code null} values. Most usages of the * The basic shapes can be modified by an arity prefix to indicate a different arity,
* functional interfaces will define the role, if any, of {@code null} for that * such as {@link java.util.function.BiFunction} ({@code (T, U) -> R}).
* context. * </li>
* </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> * </ul>
*
* @see java.lang.FunctionalInterface
*/ */
package java.util.function; package java.util.function;
...@@ -50,20 +50,20 @@ public class PrimitiveSumMinMaxTest { ...@@ -50,20 +50,20 @@ public class PrimitiveSumMinMaxTest {
BinaryOperator<Boolean> xor = Boolean::logicalXor; BinaryOperator<Boolean> xor = Boolean::logicalXor;
Comparator<Boolean> cmp = Boolean::compare; Comparator<Boolean> cmp = Boolean::compare;
assertTrue(and.operate(true, true)); assertTrue(and.apply(true, true));
assertFalse(and.operate(true, false)); assertFalse(and.apply(true, false));
assertFalse(and.operate(false, true)); assertFalse(and.apply(false, true));
assertFalse(and.operate(false, false)); assertFalse(and.apply(false, false));
assertTrue(or.operate(true, true)); assertTrue(or.apply(true, true));
assertTrue(or.operate(true, false)); assertTrue(or.apply(true, false));
assertTrue(or.operate(false, true)); assertTrue(or.apply(false, true));
assertFalse(or.operate(false, false)); assertFalse(or.apply(false, false));
assertFalse(xor.operate(true, true)); assertFalse(xor.apply(true, true));
assertTrue(xor.operate(true, false)); assertTrue(xor.apply(true, false));
assertTrue(xor.operate(false, true)); assertTrue(xor.apply(false, true));
assertFalse(xor.operate(false, false)); assertFalse(xor.apply(false, false));
assertEquals(Boolean.TRUE.compareTo(Boolean.TRUE), cmp.compare(true, true)); assertEquals(Boolean.TRUE.compareTo(Boolean.TRUE), cmp.compare(true, true));
assertEquals(Boolean.TRUE.compareTo(Boolean.FALSE), cmp.compare(true, false)); assertEquals(Boolean.TRUE.compareTo(Boolean.FALSE), cmp.compare(true, false));
...@@ -83,12 +83,12 @@ public class PrimitiveSumMinMaxTest { ...@@ -83,12 +83,12 @@ public class PrimitiveSumMinMaxTest {
int[] numbers = { -1, 0, 1, 100, Integer.MAX_VALUE, Integer.MIN_VALUE }; int[] numbers = { -1, 0, 1, 100, Integer.MAX_VALUE, Integer.MIN_VALUE };
for (int i : numbers) { for (int i : numbers) {
for (int j : numbers) { for (int j : numbers) {
assertEquals(i+j, (int) sum1.operate(i, j)); assertEquals(i+j, (int) sum1.apply(i, j));
assertEquals(i+j, sum2.operateAsInt(i, j)); assertEquals(i+j, sum2.applyAsInt(i, j));
assertEquals(Math.max(i,j), (int) max1.operate(i, j)); assertEquals(Math.max(i,j), (int) max1.apply(i, j));
assertEquals(Math.max(i,j), max2.operateAsInt(i, j)); assertEquals(Math.max(i,j), max2.applyAsInt(i, j));
assertEquals(Math.min(i,j), (int) min1.operate(i, j)); assertEquals(Math.min(i,j), (int) min1.apply(i, j));
assertEquals(Math.min(i,j), min2.operateAsInt(i, j)); assertEquals(Math.min(i,j), min2.applyAsInt(i, j));
assertEquals(((Integer) i).compareTo(j), cmp.compare(i, j)); assertEquals(((Integer) i).compareTo(j), cmp.compare(i, j));
} }
} }
...@@ -106,12 +106,12 @@ public class PrimitiveSumMinMaxTest { ...@@ -106,12 +106,12 @@ public class PrimitiveSumMinMaxTest {
long[] numbers = { -1, 0, 1, 100, Long.MAX_VALUE, Long.MIN_VALUE }; long[] numbers = { -1, 0, 1, 100, Long.MAX_VALUE, Long.MIN_VALUE };
for (long i : numbers) { for (long i : numbers) {
for (long j : numbers) { for (long j : numbers) {
assertEquals(i+j, (long) sum1.operate(i, j)); assertEquals(i+j, (long) sum1.apply(i, j));
assertEquals(i+j, sum2.operateAsLong(i, j)); assertEquals(i+j, sum2.applyAsLong(i, j));
assertEquals(Math.max(i,j), (long) max1.operate(i, j)); assertEquals(Math.max(i,j), (long) max1.apply(i, j));
assertEquals(Math.max(i,j), max2.operateAsLong(i, j)); assertEquals(Math.max(i,j), max2.applyAsLong(i, j));
assertEquals(Math.min(i,j), (long) min1.operate(i, j)); assertEquals(Math.min(i,j), (long) min1.apply(i, j));
assertEquals(Math.min(i,j), min2.operateAsLong(i, j)); assertEquals(Math.min(i,j), min2.applyAsLong(i, j));
assertEquals(((Long) i).compareTo(j), cmp.compare(i, j)); assertEquals(((Long) i).compareTo(j), cmp.compare(i, j));
} }
} }
...@@ -126,9 +126,9 @@ public class PrimitiveSumMinMaxTest { ...@@ -126,9 +126,9 @@ public class PrimitiveSumMinMaxTest {
float[] numbers = { -1, 0, 1, 100, Float.MAX_VALUE, Float.MIN_VALUE }; float[] numbers = { -1, 0, 1, 100, Float.MAX_VALUE, Float.MIN_VALUE };
for (float i : numbers) { for (float i : numbers) {
for (float j : numbers) { for (float j : numbers) {
assertEquals(i+j, (float) sum1.operate(i, j)); assertEquals(i+j, (float) sum1.apply(i, j));
assertEquals(Math.max(i,j), (float) max1.operate(i, j)); assertEquals(Math.max(i,j), (float) max1.apply(i, j));
assertEquals(Math.min(i,j), (float) min1.operate(i, j)); assertEquals(Math.min(i,j), (float) min1.apply(i, j));
assertEquals(((Float) i).compareTo(j), cmp.compare(i, j)); assertEquals(((Float) i).compareTo(j), cmp.compare(i, j));
} }
} }
...@@ -146,12 +146,12 @@ public class PrimitiveSumMinMaxTest { ...@@ -146,12 +146,12 @@ public class PrimitiveSumMinMaxTest {
double[] numbers = { -1, 0, 1, 100, Double.MAX_VALUE, Double.MIN_VALUE }; double[] numbers = { -1, 0, 1, 100, Double.MAX_VALUE, Double.MIN_VALUE };
for (double i : numbers) { for (double i : numbers) {
for (double j : numbers) { for (double j : numbers) {
assertEquals(i+j, (double) sum1.operate(i, j)); assertEquals(i+j, (double) sum1.apply(i, j));
assertEquals(i+j, sum2.operateAsDouble(i, j)); assertEquals(i+j, sum2.applyAsDouble(i, j));
assertEquals(Math.max(i,j), (double) max1.operate(i, j)); assertEquals(Math.max(i,j), (double) max1.apply(i, j));
assertEquals(Math.max(i,j), max2.operateAsDouble(i, j)); assertEquals(Math.max(i,j), max2.applyAsDouble(i, j));
assertEquals(Math.min(i,j), (double) min1.operate(i, j)); assertEquals(Math.min(i,j), (double) min1.apply(i, j));
assertEquals(Math.min(i,j), min2.operateAsDouble(i, j)); assertEquals(Math.min(i,j), min2.applyAsDouble(i, j));
assertEquals(((Double) i).compareTo(j), cmp.compare(i, j)); assertEquals(((Double) i).compareTo(j), cmp.compare(i, j));
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册