提交 b1b3a8c1 编写于 作者: M mduigou

8019840: Spec updates for java.util.function

Reviewed-by: mduigou, chegar
Contributed-by: brian.goetz@oracle.com
上级 20bce577
...@@ -27,13 +27,16 @@ package java.util.function; ...@@ -27,13 +27,16 @@ package java.util.function;
import java.util.Objects; import java.util.Objects;
/** /**
* An operation which accepts two input arguments and returns no result. This is * Represents an operation that accepts two input arguments and returns no
* the two-arity specialization of {@link Consumer}. Unlike most other * result. This is the two-arity specialization of {@link Consumer}.
* functional interfaces, {@code BiConsumer} is expected to operate via * Unlike most other functional interfaces, {@code BiConsumer} is expected
* side-effects. * to operate via side-effects.
* *
* @param <T> the type of the first argument to the {@code accept} operation * <p>This is a <a href="package-summary.html">functional interface</a>
* @param <U> the type of the second argument to the {@code accept} operation * whose functional method is {@link #accept(Object, Object)}.
*
* @param <T> the type of the first argument to the operation
* @param <U> the type of the second argument to the operation
* *
* @see Consumer * @see Consumer
* @since 1.8 * @since 1.8
...@@ -42,35 +45,31 @@ import java.util.Objects; ...@@ -42,35 +45,31 @@ import java.util.Objects;
public interface BiConsumer<T, U> { public interface BiConsumer<T, U> {
/** /**
* Performs operations upon the provided objects which may modify those * Performs this operation on the given arguments.
* objects and/or external state.
* *
* @param t an input object * @param t the first input argument
* @param u an input object * @param u the second input argument
*/ */
void accept(T t, U u); void accept(T t, U u);
/** /**
* Returns a {@code BiConsumer} which performs, in sequence, the operation * Returns a composed {@code BiConsumer} that performs, in sequence, this
* represented by this object followed by the operation represented by * operation followed by the {@code after} operation. If performing either
* the other {@code BiConsumer}. * operation throws an exception, it is relayed to the caller of the
* * composed operation. If performing this operation throws an exception,
* <p>Any exceptions thrown by either {@code accept} method are relayed * the {@code after} operation will not be performed.
* to the caller; if performing this operation throws an exception, the
* other operation will not be performed.
* *
* @param other a BiConsumer which will be chained after this BiConsumer * @param after the operation to perform after this operation
* @return a BiConsumer which performs in sequence the {@code accept} method * @return a composed {@code BiConsumer} that performs in sequence this
* of this BiConsumer and the {@code accept} method of the specified * operation followed by the {@code after} operation
* BiConsumer operation * @throws NullPointerException if {@code after} is null
* @throws NullPointerException if other is null
*/ */
default BiConsumer<T, U> chain(BiConsumer<? super T, ? super U> other) { default BiConsumer<T, U> andThen(BiConsumer<? super T, ? super U> after) {
Objects.requireNonNull(other); Objects.requireNonNull(after);
return (l, r) -> { return (l, r) -> {
accept(l, r); accept(l, r);
other.accept(l, r); after.accept(l, r);
}; };
} }
} }
...@@ -27,14 +27,15 @@ package java.util.function; ...@@ -27,14 +27,15 @@ package java.util.function;
import java.util.Objects; import java.util.Objects;
/** /**
* Apply a function to the input arguments, yielding an appropriate result. This * Represents a function that accepts two arguments and produces a result.
* is the two-arity specialization of {@link Function}. A function may * This is the two-arity specialization of {@link Function}.
* 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 * <p>This is a <a href="package-summary.html">functional interface</a>
* @param <U> the type of the second argument to the {@code apply} operation * whose functional method is {@link #apply(Object, Object)}.
* @param <R> the type of results returned by the {@code apply} operation *
* @param <T> the type of the first argument to the function
* @param <U> the type of the second argument to the function
* @param <R> the type of the result of the function
* *
* @see Function * @see Function
* @since 1.8 * @since 1.8
...@@ -43,25 +44,25 @@ import java.util.Objects; ...@@ -43,25 +44,25 @@ import java.util.Objects;
public interface BiFunction<T, U, R> { public interface BiFunction<T, U, R> {
/** /**
* Compute the result of applying the function to the input arguments * Applies this function to the given arguments.
* *
* @param t an input object * @param t the first function argument
* @param u an input object * @param u the second function argument
* @return the function result * @return the function result
*/ */
R apply(T t, U u); R apply(T t, U u);
/** /**
* Returns a new function which applies this function followed by the * Returns a composed function that first applies this function to
* provided function. If either function throws an exception, it is relayed * its input, and then applies the {@code after} function to the result.
* to the caller. * If evaluation of either function throws an exception, it is relayed to
* the caller of the composed function.
* *
* @param <V> Type of output objects to the combined function. May be the * @param <V> the type of output of the {@code after} function, and of the
* same type as {@code <T>}, {@code <U>} or {@code <R>} * composed function
* @param after An additional function to be applied after this function is * @param after the function to apply after this function is applied
* applied * @return a composed function that first applies this function and then
* @return A function which performs this function followed by the provided * applies the {@code after} function
* function
* @throws NullPointerException if after is null * @throws NullPointerException if after is null
*/ */
default <V> BiFunction<T, U, V> andThen(Function<? super R, ? extends V> after) { default <V> BiFunction<T, U, V> andThen(Function<? super R, ? extends V> after) {
......
...@@ -27,11 +27,14 @@ package java.util.function; ...@@ -27,11 +27,14 @@ package java.util.function;
import java.util.Objects; import java.util.Objects;
/** /**
* Determines if the input objects match some criteria. This is the two-arity * Represents a predicate (boolean-valued function) of two arguments. This is
* specialization of {@link Predicate}. * the two-arity specialization of {@link Predicate}.
* *
* @param <T> the type of the first argument to {@code test} * <p>This is a <a href="package-summary.html">functional interface</a>
* @param <U> the type of the second argument to {@code test} * whose functional method is {@link #test(Object, Object)}.
*
* @param <T> the type of the first argument to the predicate
* @param <U> the type of the second argument the predicate
* *
* @see Predicate * @see Predicate
* @since 1.8 * @since 1.8
...@@ -40,34 +43,41 @@ import java.util.Objects; ...@@ -40,34 +43,41 @@ import java.util.Objects;
public interface BiPredicate<T, U> { public interface BiPredicate<T, U> {
/** /**
* Return {@code true} if the inputs match some criteria. * Evaluates this predicate on the given arguments.
* *
* @param t an input object * @param t the first input argument
* @param u an input object * @param u the second input argument
* @return {@code true} if the inputs match some criteria * @return {@code true} if the input arguments match the predicate,
* otherwise {@code false}
*/ */
boolean test(T t, U u); boolean test(T t, U u);
/** /**
* Returns a predicate which evaluates to {@code true} only if this * Returns a composed predicate that represents a short-circuiting logical
* predicate and the provided predicate both evaluate to {@code true}. If * AND of this predicate and another. When evaluating the composed
* this predicate returns {@code false} then the remaining predicate is not * predicate, if this predicate is {@code false}, then the {@code other}
* evaluated. * predicate is not evaluated.
*
* <p>Any exceptions thrown during evaluation of either predicate are relayed
* to the caller; if evaluation of this predicate throws an exception, the
* {@code other} predicate will not be evaluated.
* *
* @param p a predicate which will be logically-ANDed with this predicate * @param other a predicate that will be logically-ANDed with this
* @return a new predicate which returns {@code true} only if both * predicate
* predicates return {@code true} * @return a composed predicate that represents the short-circuiting logical
* @throws NullPointerException if p is null * AND of this predicate and the {@code other} predicate
* @throws NullPointerException if other is null
*/ */
default BiPredicate<T, U> and(BiPredicate<? super T, ? super U> p) { default BiPredicate<T, U> and(BiPredicate<? super T, ? super U> other) {
Objects.requireNonNull(p); Objects.requireNonNull(other);
return (T t, U u) -> test(t, u) && p.test(t, u); return (T t, U u) -> test(t, u) && other.test(t, u);
} }
/** /**
* Returns a predicate which negates the result of this predicate. * Returns a predicate that represents the logical negation of this
* predicate.
* *
* @return a new predicate who's result is always the opposite of this * @return a predicate that represents the logical negation of this
* predicate * predicate
*/ */
default BiPredicate<T, U> negate() { default BiPredicate<T, U> negate() {
...@@ -75,18 +85,23 @@ public interface BiPredicate<T, U> { ...@@ -75,18 +85,23 @@ public interface BiPredicate<T, U> {
} }
/** /**
* Returns a predicate which evaluates to {@code true} if either this * Returns a composed predicate that represents a short-circuiting logical
* predicate or the provided predicate evaluates to {@code true}. If this * OR of this predicate and another. When evaluating the composed
* predicate returns {@code true} then the remaining predicate is not * predicate, if this predicate is {@code true}, then the {@code other}
* evaluated. * predicate is not evaluated.
*
* <p>Any exceptions thrown during evaluation of either predicate are relayed
* to the caller; if evaluation of this predicate throws an exception, the
* {@code other} predicate will not be evaluated.
* *
* @param p a predicate which will be logically-ORed with this predicate * @param other a predicate that will be logically-ORed with this
* @return a new predicate which returns {@code true} if either predicate * predicate
* returns {@code true} * @return a composed predicate that represents the short-circuiting logical
* @throws NullPointerException if p is null * OR of this predicate and the {@code other} predicate
* @throws NullPointerException if other is null
*/ */
default BiPredicate<T, U> or(BiPredicate<? super T, ? super U> p) { default BiPredicate<T, U> or(BiPredicate<? super T, ? super U> other) {
Objects.requireNonNull(p); Objects.requireNonNull(other);
return (T t, U u) -> test(t, u) || p.test(t, u); return (T t, U u) -> test(t, u) || other.test(t, u);
} }
} }
...@@ -28,42 +28,48 @@ import java.util.Objects; ...@@ -28,42 +28,48 @@ import java.util.Objects;
import java.util.Comparator; import java.util.Comparator;
/** /**
* An operation upon two operands yielding a result. This is a specialization of * Represents an operation upon two operands of the same type, producing a result
* {@code BiFunction} where the operands and the result are all of the same type. * of the same type as the operands. This is a specialization of
* {@link BiFunction} for the case where the operands and the result are all of
* the same type.
* *
* @param <T> the type of operands to {@code apply} and of the result * <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #apply(Object, Object)}.
*
* @param <T> the type of the operands and result of the operator
* *
* @see BiFunction * @see BiFunction
* @see UnaryOperator
* @since 1.8 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface BinaryOperator<T> extends BiFunction<T,T,T> { public interface BinaryOperator<T> extends BiFunction<T,T,T> {
/** /**
* Returns a {@link BinaryOperator} which returns the lesser of two elements * Returns a {@link BinaryOperator} which returns the lesser of two elements
* according to the specified {@code Comparator} * according to the specified {@code Comparator}.
* *
* @param <T> the type of values to be compared and returned * @param <T> the type of the input arguments of the comparator
* @param comparator a {@code Comparator} for comparing the two values * @param comparator a {@code Comparator} for comparing the two values
* @return a {@code BinaryOperator} which returns the lesser of its operands, * @return a {@code BinaryOperator} which returns the lesser of its operands,
* according to the supplied {@code Comparator} * according to the supplied {@code Comparator}
* @throws NullPointerException if the argument is null * @throws NullPointerException if the argument is null
*/ */
public static<T> BinaryOperator<T> minBy(Comparator<? super T> comparator) { public static <T> BinaryOperator<T> minBy(Comparator<? super T> comparator) {
Objects.requireNonNull(comparator); Objects.requireNonNull(comparator);
return (a, b) -> comparator.compare(a, b) <= 0 ? a : b; return (a, b) -> comparator.compare(a, b) <= 0 ? a : b;
} }
/** /**
* Returns a {@link BinaryOperator} which returns the greater of two elements * Returns a {@link BinaryOperator} which returns the greater of two elements
* according to the specified {@code Comparator} * according to the specified {@code Comparator}.
* *
* @param <T> the type of values to be compared and returned * @param <T> the type of the input arguments of the comparator
* @param comparator a {@code Comparator} for comparing the two values * @param comparator a {@code Comparator} for comparing the two values
* @return a {@code BinaryOperator} which returns the greater of its operands, * @return a {@code BinaryOperator} which returns the greater of its operands,
* according to the supplied {@code Comparator} * according to the supplied {@code Comparator}
* @throws NullPointerException if the argument is null * @throws NullPointerException if the argument is null
*/ */
public static<T> BinaryOperator<T> maxBy(Comparator<? super T> comparator) { public static <T> BinaryOperator<T> maxBy(Comparator<? super T> comparator) {
Objects.requireNonNull(comparator); Objects.requireNonNull(comparator);
return (a, b) -> comparator.compare(a, b) >= 0 ? a : b; return (a, b) -> comparator.compare(a, b) >= 0 ? a : b;
} }
......
...@@ -26,8 +26,14 @@ package java.util.function; ...@@ -26,8 +26,14 @@ package java.util.function;
/** /**
* A supplier of {@code boolean} values. This is the {@code boolean}-providing * Represents a supplier of {@code boolean}-valued results. This is the
* primitive specialization of {@link Supplier}. * {@code boolean}-producing primitive specialization of {@link Supplier}.
*
* <p>There is no requirement that a new or distinct result be returned each
* time the supplier is invoked.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #getAsBoolean()}.
* *
* @see Supplier * @see Supplier
* @since 1.8 * @since 1.8
...@@ -36,9 +42,9 @@ package java.util.function; ...@@ -36,9 +42,9 @@ package java.util.function;
public interface BooleanSupplier { public interface BooleanSupplier {
/** /**
* Returns a {@code boolean} value. * Gets a result.
* *
* @return a {@code boolean} value * @return a result
*/ */
boolean getAsBoolean(); boolean getAsBoolean();
} }
...@@ -27,11 +27,14 @@ package java.util.function; ...@@ -27,11 +27,14 @@ package java.util.function;
import java.util.Objects; import java.util.Objects;
/** /**
* An operation which accepts a single input argument and returns no result. * Represents an operation that accepts a single input argument and returns no
* Unlike most other functional interfaces, {@code Consumer} is expected to * result. Unlike most other functional interfaces, {@code Consumer} is expected
* operate via side-effects. * to operate via side-effects.
* *
* @param <T> The type of input objects to {@code accept} * <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #accept(Object)}.
*
* @param <T> the type of the input to the operation
* *
* @since 1.8 * @since 1.8
*/ */
...@@ -39,29 +42,26 @@ import java.util.Objects; ...@@ -39,29 +42,26 @@ import java.util.Objects;
public interface Consumer<T> { public interface Consumer<T> {
/** /**
* Accept an input value. * Performs this operation on the given argument.
* *
* @param t the input object * @param t the input argument
*/ */
void accept(T t); void accept(T t);
/** /**
* Returns a {@code Consumer} which performs, in sequence, the operation * Returns a composed {@code Consumer} that performs, in sequence, this
* represented by this object followed by the operation represented by * operation followed by the {@code after} operation. If performing either
* the other {@code Consumer}. * operation throws an exception, it is relayed to the caller of the
* * composed operation. If performing this operation throws an exception,
* <p>Any exceptions thrown by either {@code accept} method are relayed * the {@code after} operation will not be performed.
* to the caller; if performing this operation throws an exception, the
* other operation will not be performed.
* *
* @param other a Consumer which will be chained after this Consumer * @param after the operation to perform after this operation
* @return a Consumer which performs in sequence the {@code accept} method * @return a composed {@code Consumer} that performs in sequence this
* of this Consumer and the {@code accept} method of the specified Consumer * operation followed by the {@code after} operation
* operation * @throws NullPointerException if {@code after} is null
* @throws NullPointerException if other is null
*/ */
default Consumer<T> chain(Consumer<? super T> other) { default Consumer<T> andThen(Consumer<? super T> after) {
Objects.requireNonNull(other); Objects.requireNonNull(after);
return (T t) -> { accept(t); other.accept(t); }; return (T t) -> { accept(t); after.accept(t); };
} }
} }
...@@ -25,23 +25,25 @@ ...@@ -25,23 +25,25 @@
package java.util.function; package java.util.function;
/** /**
* An operation on two {@code double} operands yielding a {@code double} result. * Represents an operation upon two {@code double}-valued operands and producing a
* This is the primitive type specialization of {@link BinaryOperator} for * {@code double}-valued result. This is the primitive type specialization of
* {@code double}. * {@link BinaryOperator} for {@code double}.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #applyAsDouble(double, double)}.
* *
* @see BinaryOperator * @see BinaryOperator
* @see DoubleUnaryOperator
* @since 1.8 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface DoubleBinaryOperator { public interface DoubleBinaryOperator {
/** /**
* Returns the {@code double} result of the operation upon the * Applies this operator to the given operands.
* {@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 left the first operand
* @param right the right operand value * @param right the second operand
* @return the result of the operation * @return the operator result
*/ */
double applyAsDouble(double left, double right); double applyAsDouble(double left, double right);
} }
...@@ -27,11 +27,14 @@ package java.util.function; ...@@ -27,11 +27,14 @@ package java.util.function;
import java.util.Objects; import java.util.Objects;
/** /**
* An operation which accepts a single double argument and returns no result. * Represents an operation that accepts a single {@code double}-valued argument and
* This is the primitive type specialization of {@link Consumer} for * returns no result. This is the primitive type specialization of
* {@code double}. Unlike most other functional interfaces, * {@link Consumer} for {@code double}. Unlike most other functional interfaces,
* {@code DoubleConsumer} is expected to operate via side-effects. * {@code DoubleConsumer} is expected to operate via side-effects.
* *
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #accept(double)}.
*
* @see Consumer * @see Consumer
* @since 1.8 * @since 1.8
*/ */
...@@ -39,30 +42,26 @@ import java.util.Objects; ...@@ -39,30 +42,26 @@ import java.util.Objects;
public interface DoubleConsumer { public interface DoubleConsumer {
/** /**
* Accept an input value. * Performs this operation on the given argument.
* *
* @param value the input value * @param value the input argument
*/ */
void accept(double value); void accept(double value);
/** /**
* Returns a {@code DoubleConsumer} which performs, in sequence, the operation * Returns a composed {@code DoubleConsumer} that performs, in sequence, this
* represented by this object followed by the operation represented by * operation followed by the {@code after} operation. If performing either
* another {@code DoubleConsumer}. * operation throws an exception, it is relayed to the caller of the
* * composed operation. If performing this operation throws an exception,
* <p>Any exceptions thrown by either {@code accept} method are relayed * the {@code after} operation will not be performed.
* to the caller; if performing this operation throws an exception, the
* other operation will not be performed.
* *
* @param other a DoubleConsumer which will be chained after this * @param after the operation to perform after this operation
* DoubleConsumer * @return a composed {@code DoubleConsumer} that performs in sequence this
* @return an DoubleConsumer which performs in sequence the {@code accept} method * operation followed by the {@code after} operation
* of this DoubleConsumer and the {@code accept} method of the specified IntConsumer * @throws NullPointerException if {@code after} is null
* operation
* @throws NullPointerException if other is null
*/ */
default DoubleConsumer chain(DoubleConsumer other) { default DoubleConsumer andThen(DoubleConsumer after) {
Objects.requireNonNull(other); Objects.requireNonNull(after);
return (double t) -> { accept(t); other.accept(t); }; return (double t) -> { accept(t); after.accept(t); };
} }
} }
...@@ -25,11 +25,14 @@ ...@@ -25,11 +25,14 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the double-valued input argument, yielding an appropriate * Represents a function that accepts a double-valued argument and produces a
* result. This is the {@code double}-consuming primitive specialization for * result. This is the {@code double}-consuming primitive specialization for
* {@link Function}. * {@link Function}.
* *
* @param <R> the type of output objects from the function * <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #apply(double)}.
*
* @param <R> the type of the result of the function
* *
* @see Function * @see Function
* @since 1.8 * @since 1.8
...@@ -38,9 +41,9 @@ package java.util.function; ...@@ -38,9 +41,9 @@ package java.util.function;
public interface DoubleFunction<R> { public interface DoubleFunction<R> {
/** /**
* Compute the result of applying the function to the input argument * Applies this function to the given argument.
* *
* @param value the input value * @param value the function argument
* @return the function result * @return the function result
*/ */
R apply(double value); R apply(double value);
......
...@@ -27,9 +27,12 @@ package java.util.function; ...@@ -27,9 +27,12 @@ package java.util.function;
import java.util.Objects; import java.util.Objects;
/** /**
* Determines if the {@code double} input value matches some criteria. This is * Represents a predicate (boolean-valued function) of one {@code double}-valued
* the {@code double}-consuming primitive type specialization of * argument. This is the {@code double}-consuming primitive type specialization
* {@link Predicate}. * of {@link Predicate}.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #test(double)}.
* *
* @see Predicate * @see Predicate
* @since 1.8 * @since 1.8
...@@ -38,38 +41,40 @@ import java.util.Objects; ...@@ -38,38 +41,40 @@ import java.util.Objects;
public interface DoublePredicate { public interface DoublePredicate {
/** /**
* Returns {@code true} if the input value matches some criteria. * Evaluates this predicate on the given argument.
* *
* @param value the value to be tested * @param value the input argument
* @return {@code true} if the input value matches some criteria, otherwise * @return {@code true} if the input argument matches the predicate,
* {@code false} * otherwise {@code false}
*/ */
boolean test(double value); boolean test(double value);
/** /**
* Returns a predicate which evaluates to {@code true} only if this * Returns a composed predicate that represents a short-circuiting logical
* predicate and the provided predicate both evaluate to {@code true}. If * AND of this predicate and another. When evaluating the composed
* this predicate returns {@code false} then the remaining predicate is not * predicate, if this predicate is {@code false}, then the {@code other}
* evaluated. * predicate is not evaluated.
* *
* <p>Any exceptions thrown by either {@code test} method are relayed * <p>Any exceptions thrown during evaluation of either predicate are relayed
* to the caller; if performing first operation throws an exception, the * to the caller; if evaluation of this predicate throws an exception, the
* second operation will not be performed. * {@code other} predicate will not be evaluated.
* *
* @param p a predicate which will be logically-ANDed with this predicate * @param other a predicate that will be logically-ANDed with this
* @return a new predicate which returns {@code true} only if both * predicate
* predicates return {@code true} * @return a composed predicate that represents the short-circuiting logical
* @throws NullPointerException if p is null * AND of this predicate and the {@code other} predicate
* @throws NullPointerException if other is null
*/ */
default DoublePredicate and(DoublePredicate p) { default DoublePredicate and(DoublePredicate other) {
Objects.requireNonNull(p); Objects.requireNonNull(other);
return (value) -> test(value) && p.test(value); return (value) -> test(value) && other.test(value);
} }
/** /**
* Returns a predicate which negates the result of this predicate. * Returns a predicate that represents the logical negation of this
* predicate.
* *
* @return a new predicate who's result is always the opposite of this * @return a predicate that represents the logical negation of this
* predicate * predicate
*/ */
default DoublePredicate negate() { default DoublePredicate negate() {
...@@ -77,22 +82,23 @@ public interface DoublePredicate { ...@@ -77,22 +82,23 @@ public interface DoublePredicate {
} }
/** /**
* Returns a predicate which evaluates to {@code true} if either this * Returns a composed predicate that represents a short-circuiting logical
* predicate or the provided predicate evaluates to {@code true}. If this * OR of this predicate and another. When evaluating the composed
* predicate returns {@code true} then the remaining predicate is not * predicate, if this predicate is {@code true}, then the {@code other}
* evaluated. * predicate is not evaluated.
* *
* <p>Any exceptions thrown by either {@code test} method are relayed * <p>Any exceptions thrown during evaluation of either predicate are relayed
* to the caller; if performing first operation throws an exception, the * to the caller; if evaluation of this predicate throws an exception, the
* second operation will not be performed. * {@code other} predicate will not be evaluated.
* *
* @param p a predicate which will be logically-ANDed with this predicate * @param other a predicate that will be logically-ORed with this
* @return a new predicate which returns {@code true} if either predicate * predicate
* returns {@code true} * @return a composed predicate that represents the short-circuiting logical
* @throws NullPointerException if p is null * OR of this predicate and the {@code other} predicate
* @throws NullPointerException if other is null
*/ */
default DoublePredicate or(DoublePredicate p) { default DoublePredicate or(DoublePredicate other) {
Objects.requireNonNull(p); Objects.requireNonNull(other);
return (value) -> test(value) || p.test(value); return (value) -> test(value) || other.test(value);
} }
} }
...@@ -25,8 +25,14 @@ ...@@ -25,8 +25,14 @@
package java.util.function; package java.util.function;
/** /**
* A supplier of {@code double} values. This is the {@code double}-providing * Represents a supplier of {@code double}-valued results. This is the
* primitive specialization of {@link Supplier}. * {@code double}-producing primitive specialization of {@link Supplier}.
*
* <p>There is no requirement that a distinct result be returned each
* time the supplier is invoked.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #getAsDouble()}.
* *
* @see Supplier * @see Supplier
* @since 1.8 * @since 1.8
...@@ -35,9 +41,9 @@ package java.util.function; ...@@ -35,9 +41,9 @@ package java.util.function;
public interface DoubleSupplier { public interface DoubleSupplier {
/** /**
* Returns a {@code double} value. * Gets a result.
* *
* @return a {@code double} value * @return a result
*/ */
double getAsDouble(); double getAsDouble();
} }
...@@ -25,22 +25,24 @@ ...@@ -25,22 +25,24 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the input argument, yielding an appropriate result. * Represents a function that accepts a double-valued argument and produces an
* This is the {@code double}-to-{@code int} specialization for {@link Function}. * int-valued result. This is the {@code double}-to-{@code int} primitive
* specialization for {@link Function}.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #applyAsInt(double)}.
* *
* @see Function * @see Function
* @see IntToDoubleFunction
* @see LongToIntFunction
* @since 1.8 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface DoubleToIntFunction { public interface DoubleToIntFunction {
/** /**
* Compute the result of applying the function to the input arguments. * Applies this function to the given argument.
* *
* @param value the input value * @param value the function argument
* @return the function result value * @return the function result
*/ */
int applyAsInt(double value); int applyAsInt(double value);
} }
...@@ -25,22 +25,24 @@ ...@@ -25,22 +25,24 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the input argument, yielding an appropriate result. * Represents a function that accepts a double-valued argument and produces a
* This is the {@code double}-to-{@code long} specialization for {@link Function}. * long-valued result. This is the {@code double}-to-{@code long} primitive
* specialization for {@link Function}.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #applyAsLong(double)}.
* *
* @see Function * @see Function
* @see LongToDoubleFunction
* @see IntToLongFunction
* @since 1.8 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface DoubleToLongFunction { public interface DoubleToLongFunction {
/** /**
* Compute the result of applying the function to the input arguments. * Applies this function to the given argument.
* *
* @param value the input value * @param value the function argument
* @return the function result value * @return the function result
*/ */
long applyAsLong(double value); long applyAsLong(double value);
} }
...@@ -27,9 +27,12 @@ package java.util.function; ...@@ -27,9 +27,12 @@ package java.util.function;
import java.util.Objects; import java.util.Objects;
/** /**
* An operation on a {@code double} operand yielding a {@code double} * Represents an operation on a single {@code double}-valued operand that produces
* result. This is the primitive type specialization of {@link UnaryOperator} * a {@code double}-valued result. This is the primitive type specialization of
* for {@code double}. * {@link UnaryOperator} for {@code double}.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #applyAsDouble(double)}.
* *
* @see UnaryOperator * @see UnaryOperator
* @since 1.8 * @since 1.8
...@@ -38,24 +41,25 @@ import java.util.Objects; ...@@ -38,24 +41,25 @@ import java.util.Objects;
public interface DoubleUnaryOperator { public interface DoubleUnaryOperator {
/** /**
* Returns the {@code double} result of the operation upon the * Applies this operator to the given operand.
* {@code double} operand.
* *
* @param operand the operand value * @param operand the operand
* @return the operation result value * @return the operator result
*/ */
double applyAsDouble(double operand); double applyAsDouble(double operand);
/** /**
* Compose a new function which applies the provided function followed by * Returns a composed operator that first applies the {@code before}
* this function. If either function throws an exception, it is relayed * operator to its input, and then applies this operator to the result.
* to the caller. * If evaluation of either operator throws an exception, it is relayed to
* the caller of the composed operator.
* *
* @param before An additional function to be applied before this function * @param before the operator to apply before this operator is applied
* is applied * @return a composed operator that first applies the {@code before}
* @return A function which performs the provided function followed by this * operator and then applies this operator
* function
* @throws NullPointerException if before is null * @throws NullPointerException if before is null
*
* @see #andThen(DoubleUnaryOperator)
*/ */
default DoubleUnaryOperator compose(DoubleUnaryOperator before) { default DoubleUnaryOperator compose(DoubleUnaryOperator before) {
Objects.requireNonNull(before); Objects.requireNonNull(before);
...@@ -63,15 +67,17 @@ public interface DoubleUnaryOperator { ...@@ -63,15 +67,17 @@ public interface DoubleUnaryOperator {
} }
/** /**
* Compose a new function which applies this function followed by the * Returns a composed operator that first applies this operator to
* provided function. If either function throws an exception, it is relayed * its input, and then applies the {@code after} operator to the result.
* to the caller. * If evaluation of either operator throws an exception, it is relayed to
* the caller of the composed operator.
* *
* @param after An additional function to be applied after this function is * @param after the operator to apply after this operator is applied
* applied * @return a composed operator that first applies this operator and then
* @return A function which performs this function followed by the provided * applies the {@code after} operator
* function followed
* @throws NullPointerException if after is null * @throws NullPointerException if after is null
*
* @see #compose(DoubleUnaryOperator)
*/ */
default DoubleUnaryOperator andThen(DoubleUnaryOperator after) { default DoubleUnaryOperator andThen(DoubleUnaryOperator after) {
Objects.requireNonNull(after); Objects.requireNonNull(after);
...@@ -79,9 +85,9 @@ public interface DoubleUnaryOperator { ...@@ -79,9 +85,9 @@ public interface DoubleUnaryOperator {
} }
/** /**
* Returns a unary operator that provides its input value as the result. * Returns a unary operator that always returns its input argument.
* *
* @return a unary operator that provides its input value as the result * @return a unary operator that always returns its input argument
*/ */
static DoubleUnaryOperator identity() { static DoubleUnaryOperator identity() {
return t -> t; return t -> t;
......
...@@ -27,12 +27,13 @@ package java.util.function; ...@@ -27,12 +27,13 @@ package java.util.function;
import java.util.Objects; import java.util.Objects;
/** /**
* Apply a function to the input argument, yielding an appropriate result. A * Represents a function that accepts one argument and produces a result.
* 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 input to the {@code apply} operation * <p>This is a <a href="package-summary.html">functional interface</a>
* @param <R> the type of the result of the {@code apply} operation * whose functional method is {@link #apply(Object)}.
*
* @param <T> the type of the input to the function
* @param <R> the type of the result of the function
* *
* @since 1.8 * @since 1.8
*/ */
...@@ -40,25 +41,27 @@ import java.util.Objects; ...@@ -40,25 +41,27 @@ import java.util.Objects;
public interface Function<T, R> { public interface Function<T, R> {
/** /**
* Compute the result of applying the function to the input argument * Applies this function to the given argument.
* *
* @param t the input object * @param t the function argument
* @return the function result * @return the function result
*/ */
R apply(T t); R apply(T t);
/** /**
* Returns a new function which applies the provided function followed by * Returns a composed function that first applies the {@code before}
* this function. If either function throws an exception, it is relayed * function to its input, and then applies this function to the result.
* to the caller. * If evaluation of either function throws an exception, it is relayed to
* the caller of the composed function.
* *
* @param <V> type of input objects to the combined function. May be the * @param <V> the type of input to the {@code before} function, and to the
* same type as {@code <T>} or {@code <R>} * composed function
* @param before an additional function to be applied before this function * @param before the function to apply before this function is applied
* is applied * @return a composed function that first applies the {@code before}
* @return a function which performs the provided function followed by this * function and then applies this function
* function
* @throws NullPointerException if before is null * @throws NullPointerException if before is null
*
* @see #andThen(Function)
*/ */
default <V> Function<V, R> compose(Function<? super V, ? extends T> before) { default <V> Function<V, R> compose(Function<? super V, ? extends T> before) {
Objects.requireNonNull(before); Objects.requireNonNull(before);
...@@ -66,17 +69,19 @@ public interface Function<T, R> { ...@@ -66,17 +69,19 @@ public interface Function<T, R> {
} }
/** /**
* Returns a new function which applies this function followed by the * Returns a composed function that first applies this function to
* provided function. If either function throws an exception, it is relayed * its input, and then applies the {@code after} function to the result.
* to the caller. * If evaluation of either function throws an exception, it is relayed to
* the caller of the composed function.
* *
* @param <V> type of output objects to the combined function. May be the * @param <V> the type of output of the {@code after} function, and of the
* same type as {@code <T>} or {@code <R>} * composed function
* @param after an additional function to be applied after this function is * @param after the function to apply after this function is applied
* applied * @return a composed function that first applies this function and then
* @return a function which performs this function followed by the provided * applies the {@code after} function
* function
* @throws NullPointerException if after is null * @throws NullPointerException if after is null
*
* @see #compose(Function)
*/ */
default <V> Function<T, V> andThen(Function<? super R, ? extends V> after) { default <V> Function<T, V> andThen(Function<? super R, ? extends V> after) {
Objects.requireNonNull(after); Objects.requireNonNull(after);
...@@ -84,10 +89,10 @@ public interface Function<T, R> { ...@@ -84,10 +89,10 @@ public interface Function<T, R> {
} }
/** /**
* Returns a {@code Function} whose {@code apply} method returns its input. * Returns a function that always returns its input argument.
* *
* @param <T> the type of the input and output objects to the function * @param <T> the type of the input and output objects to the function
* @return a {@code Function} whose {@code apply} method returns its input * @return a function that always returns its input argument
*/ */
static <T> Function<T, T> identity() { static <T> Function<T, T> identity() {
return t -> t; return t -> t;
......
...@@ -25,24 +25,26 @@ ...@@ -25,24 +25,26 @@
package java.util.function; package java.util.function;
/** /**
* An operation on two {@code int} operands yielding an {@code int} result. * Represents an operation upon two {@code int}-valued operands and producing an
* This is the primitive type specialization of {@link BinaryOperator} for * {@code int}-valued result. This is the primitive type specialization of
* {@code int}. * {@link BinaryOperator} for {@code int}.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #applyAsInt(int, int)}.
* *
* @see BinaryOperator * @see BinaryOperator
* @see IntUnaryOperator
* @since 1.8 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface IntBinaryOperator { public interface IntBinaryOperator {
/** /**
* Returns the {@code int} result of the operation upon the {@code int} * Applies this operator to the given operands.
* 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 left the first operand
* @param right the right operand value * @param right the second operand
* @return the result of the operation * @return the operator result
*/ */
int applyAsInt(int left, int right); int applyAsInt(int left, int right);
} }
...@@ -27,10 +27,13 @@ package java.util.function; ...@@ -27,10 +27,13 @@ package java.util.function;
import java.util.Objects; import java.util.Objects;
/** /**
* An operation which accepts a single integer argument and returns no result. * Represents an operation that accepts a single {@code int}-valued argument and
* This is the primitive type specialization of {@link Consumer} for {@code int}. * returns no result. This is the primitive type specialization of
* Unlike most other functional interfaces, {@code IntConsumer} is expected to * {@link Consumer} for {@code int}. Unlike most other functional interfaces,
* operate via side-effects. * {@code IntConsumer} is expected to operate via side-effects.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #accept(int)}.
* *
* @see Consumer * @see Consumer
* @since 1.8 * @since 1.8
...@@ -39,30 +42,26 @@ import java.util.Objects; ...@@ -39,30 +42,26 @@ import java.util.Objects;
public interface IntConsumer { public interface IntConsumer {
/** /**
* Accept an input value. * Performs this operation on the given argument.
* *
* @param value the input value * @param value the input argument
*/ */
void accept(int value); void accept(int value);
/** /**
* Returns an {@code IntConsumer} which performs, in sequence, the operation * Returns a composed {@code IntConsumer} that performs, in sequence, this
* represented by this object followed by the operation represented by * operation followed by the {@code after} operation. If performing either
* another {@code IntConsumer}. * operation throws an exception, it is relayed to the caller of the
* * composed operation. If performing this operation throws an exception,
* <p>Any exceptions thrown by either {@code accept} method are relayed * the {@code after} operation will not be performed.
* to the caller; if performing this operation throws an exception, the
* other operation will not be performed.
* *
* @param other an IntConsumer which will be chained after this * @param after the operation to perform after this operation
* IntConsumer * @return a composed {@code IntConsumer} that performs in sequence this
* @return an IntConsumer which performs in sequence the {@code accept} method * operation followed by the {@code after} operation
* of this IntConsumer and the {@code accept} method of the specified IntConsumer * @throws NullPointerException if {@code after} is null
* operation
* @throws NullPointerException if other is null
*/ */
default IntConsumer chain(IntConsumer other) { default IntConsumer andThen(IntConsumer after) {
Objects.requireNonNull(other); Objects.requireNonNull(after);
return (int t) -> { accept(t); other.accept(t); }; return (int t) -> { accept(t); after.accept(t); };
} }
} }
...@@ -25,11 +25,14 @@ ...@@ -25,11 +25,14 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the integer-valued input argument, yielding an * Represents a function that accepts an int-valued argument and produces a
* appropriate result. This is the {@code int}-consuming primitive * result. This is the {@code int}-consuming primitive specialization for
* specialization for {@link Function}. * {@link Function}.
* *
* @param <R> the type of output objects from the function * <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #apply(int)}.
*
* @param <R> the type of the result of the function
* *
* @see Function * @see Function
* @since 1.8 * @since 1.8
...@@ -38,9 +41,9 @@ package java.util.function; ...@@ -38,9 +41,9 @@ package java.util.function;
public interface IntFunction<R> { public interface IntFunction<R> {
/** /**
* Compute the result of applying the function to the input argument * Applies this function to the given argument.
* *
* @param value the input value * @param value the function argument
* @return the function result * @return the function result
*/ */
R apply(int value); R apply(int value);
......
...@@ -27,8 +27,12 @@ package java.util.function; ...@@ -27,8 +27,12 @@ package java.util.function;
import java.util.Objects; import java.util.Objects;
/** /**
* Determines if the {@code int} input value matches some criteria. This is the * Represents a predicate (boolean-valued function) of one {@code int}-valued
* {@code int}-consuming primitive type specialization of {@link Predicate}. * argument. This is the {@code int}-consuming primitive type specialization of
* {@link Predicate}.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #test(int)}.
* *
* @see Predicate * @see Predicate
* @since 1.8 * @since 1.8
...@@ -37,38 +41,40 @@ import java.util.Objects; ...@@ -37,38 +41,40 @@ import java.util.Objects;
public interface IntPredicate { public interface IntPredicate {
/** /**
* Returns {@code true} if the input value matches some criteria. * Evaluates this predicate on the given argument.
* *
* @param value the value to be tested * @param value the input argument
* @return {@code true} if the input value matches some criteria, otherwise * @return {@code true} if the input argument matches the predicate,
* {@code false} * otherwise {@code false}
*/ */
boolean test(int value); boolean test(int value);
/** /**
* Returns a predicate which evaluates to {@code true} only if this * Returns a composed predicate that represents a short-circuiting logical
* predicate and the provided predicate both evaluate to {@code true}. If * AND of this predicate and another. When evaluating the composed
* this predicate returns {@code false} then the remaining predicate is not * predicate, if this predicate is {@code false}, then the {@code other}
* evaluated. * predicate is not evaluated.
* *
* <p>Any exceptions thrown by either {@code test} method are relayed * <p>Any exceptions thrown during evaluation of either predicate are relayed
* to the caller; if performing first operation throws an exception, the * to the caller; if evaluation of this predicate throws an exception, the
* second operation will not be performed. * {@code other} predicate will not be evaluated.
* *
* @param p a predicate which will be logically-ANDed with this predicate * @param other a predicate that will be logically-ANDed with this
* @return a new predicate which returns {@code true} only if both * predicate
* predicates return {@code true} * @return a composed predicate that represents the short-circuiting logical
* @throws NullPointerException if p is null * AND of this predicate and the {@code other} predicate
* @throws NullPointerException if other is null
*/ */
default IntPredicate and(IntPredicate p) { default IntPredicate and(IntPredicate other) {
Objects.requireNonNull(p); Objects.requireNonNull(other);
return (value) -> test(value) && p.test(value); return (value) -> test(value) && other.test(value);
} }
/** /**
* Returns a predicate which negates the result of this predicate. * Returns a predicate that represents the logical negation of this
* predicate.
* *
* @return a new predicate who's result is always the opposite of this * @return a predicate that represents the logical negation of this
* predicate * predicate
*/ */
default IntPredicate negate() { default IntPredicate negate() {
...@@ -76,22 +82,23 @@ public interface IntPredicate { ...@@ -76,22 +82,23 @@ public interface IntPredicate {
} }
/** /**
* Returns a predicate which evaluates to {@code true} if either this * Returns a composed predicate that represents a short-circuiting logical
* predicate or the provided predicate evaluates to {@code true}. If this * OR of this predicate and another. When evaluating the composed
* predicate returns {@code true} then the remaining predicate is not * predicate, if this predicate is {@code true}, then the {@code other}
* evaluated. * predicate is not evaluated.
* *
* <p>Any exceptions thrown by either {@code test} method are relayed * <p>Any exceptions thrown during evaluation of either predicate are relayed
* to the caller; if performing first operation throws an exception, the * to the caller; if evaluation of this predicate throws an exception, the
* second operation will not be performed. * {@code other} predicate will not be evaluated.
* *
* @param p a predicate which will be logically-ORed with this predicate * @param other a predicate that will be logically-ORed with this
* @return a new predicate which returns {@code true} if either predicate * predicate
* returns {@code true} * @return a composed predicate that represents the short-circuiting logical
* @throws NullPointerException if p is null * OR of this predicate and the {@code other} predicate
* @throws NullPointerException if other is null
*/ */
default IntPredicate or(IntPredicate p) { default IntPredicate or(IntPredicate other) {
Objects.requireNonNull(p); Objects.requireNonNull(other);
return (value) -> test(value) || p.test(value); return (value) -> test(value) || other.test(value);
} }
} }
...@@ -25,8 +25,14 @@ ...@@ -25,8 +25,14 @@
package java.util.function; package java.util.function;
/** /**
* A supplier of {@code int} values. This is the {@code int}-providing * Represents a supplier of {@code int}-valued results. This is the
* primitive specialization of {@link Supplier}. * {@code int}-producing primitive specialization of {@link Supplier}.
*
* <p>There is no requirement that a distinct result be returned each
* time the supplier is invoked.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #getAsInt()}.
* *
* @see Supplier * @see Supplier
* @since 1.8 * @since 1.8
...@@ -35,9 +41,9 @@ package java.util.function; ...@@ -35,9 +41,9 @@ package java.util.function;
public interface IntSupplier { public interface IntSupplier {
/** /**
* Returns an {@code int} value. * Gets a result.
* *
* @return an {@code int} value * @return a result
*/ */
int getAsInt(); int getAsInt();
} }
...@@ -25,22 +25,24 @@ ...@@ -25,22 +25,24 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the input argument, yielding an appropriate result. * Represents a function that accepts an int-valued argument and produces a
* This is the {@code int}-to-{@code double} specialization for {@link Function}. * double-valued result. This is the {@code int}-to-{@code double} primitive
* specialization for {@link Function}.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #applyAsDouble(int)}.
* *
* @see Function * @see Function
* @see DoubleToIntFunction
* @see LongToDoubleFunction
* @since 1.8 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface IntToDoubleFunction { public interface IntToDoubleFunction {
/** /**
* Compute the result of applying the function to the input arguments. * Applies this function to the given argument.
* *
* @param value the input value * @param value the function argument
* @return the function result value * @return the function result
*/ */
double applyAsDouble(int value); double applyAsDouble(int value);
} }
...@@ -25,22 +25,24 @@ ...@@ -25,22 +25,24 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the input argument, yielding an appropriate result. * Represents a function that accepts an int-valued argument and produces a
* This is the {@code int}-to-{@code long} specialization for {@link Function}. * long-valued result. This is the {@code int}-to-{@code long} primitive
* specialization for {@link Function}.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #applyAsLong(int)}.
* *
* @see Function * @see Function
* @see LongToIntFunction
* @see DoubleToLongFunction
* @since 1.8 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface IntToLongFunction { public interface IntToLongFunction {
/** /**
* Compute the result of applying the function to the input arguments. * Applies this function to the given argument.
* *
* @param value the input value * @param value the function argument
* @return the function result value * @return the function result
*/ */
long applyAsLong(int value); long applyAsLong(int value);
} }
...@@ -27,9 +27,12 @@ package java.util.function; ...@@ -27,9 +27,12 @@ package java.util.function;
import java.util.Objects; import java.util.Objects;
/** /**
* An operation on a single {@code int} operand yielding an {@code int} result. * Represents an operation on a single {@code int}-valued operand that produces
* This is the primitive type specialization of {@link UnaryOperator} for * an {@code int}-valued result. This is the primitive type specialization of
* {@code int}. * {@link UnaryOperator} for {@code int}.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #applyAsInt(int)}.
* *
* @see UnaryOperator * @see UnaryOperator
* @since 1.8 * @since 1.8
...@@ -38,24 +41,25 @@ import java.util.Objects; ...@@ -38,24 +41,25 @@ import java.util.Objects;
public interface IntUnaryOperator { public interface IntUnaryOperator {
/** /**
* Returns the {@code int} value result of the operation upon the * Applies this operator to the given operand.
* {@code int} operand.
* *
* @param operand the operand value * @param operand the operand
* @return the operation result value * @return the operator result
*/ */
int applyAsInt(int operand); int applyAsInt(int operand);
/** /**
* Compose a new function which applies the provided function followed by * Returns a composed operator that first applies the {@code before}
* this function. If either function throws an exception, it is relayed * operator to its input, and then applies this operator to the result.
* to the caller. * If evaluation of either operator throws an exception, it is relayed to
* the caller of the composed operator.
* *
* @param before an additional function to be applied before this function * @param before the operator to apply before this operator is applied
* is applied * @return a composed operator that first applies the {@code before}
* @return a function which performs the provided function followed by this * operator and then applies this operator
* function
* @throws NullPointerException if before is null * @throws NullPointerException if before is null
*
* @see #andThen(IntUnaryOperator)
*/ */
default IntUnaryOperator compose(IntUnaryOperator before) { default IntUnaryOperator compose(IntUnaryOperator before) {
Objects.requireNonNull(before); Objects.requireNonNull(before);
...@@ -63,15 +67,17 @@ public interface IntUnaryOperator { ...@@ -63,15 +67,17 @@ public interface IntUnaryOperator {
} }
/** /**
* Compose a new function which applies this function followed by the * Returns a composed operator that first applies this operator to
* provided function. If either function throws an exception, it is relayed * its input, and then applies the {@code after} operator to the result.
* to the caller. * If evaluation of either operator throws an exception, it is relayed to
* the caller of the composed operator.
* *
* @param after an additional function to be applied after this function is * @param after the operator to apply after this operator is applied
* applied * @return a composed operator that first applies this operator and then
* @return a function which performs this function followed by the provided * applies the {@code after} operator
* function followed
* @throws NullPointerException if after is null * @throws NullPointerException if after is null
*
* @see #compose(IntUnaryOperator)
*/ */
default IntUnaryOperator andThen(IntUnaryOperator after) { default IntUnaryOperator andThen(IntUnaryOperator after) {
Objects.requireNonNull(after); Objects.requireNonNull(after);
...@@ -79,9 +85,9 @@ public interface IntUnaryOperator { ...@@ -79,9 +85,9 @@ public interface IntUnaryOperator {
} }
/** /**
* Returns a unary operator that provides its input value as the result. * Returns a unary operator that always returns its input argument.
* *
* @return a unary operator that provides its input value as the result * @return a unary operator that always returns its input argument
*/ */
static IntUnaryOperator identity() { static IntUnaryOperator identity() {
return t -> t; return t -> t;
......
...@@ -25,24 +25,26 @@ ...@@ -25,24 +25,26 @@
package java.util.function; package java.util.function;
/** /**
* An operation on two {@code long} operands yielding a {@code long} result. * Represents an operation upon two {@code long}-valued operands and producing a
* This is the primitive type specialization of {@link BinaryOperator} for * {@code long}-valued result. This is the primitive type specialization of
* {@code long}. * {@link BinaryOperator} for {@code long}.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #applyAsLong(long, long)}.
* *
* @see BinaryOperator * @see BinaryOperator
* @see LongUnaryOperator
* @since 1.8 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface LongBinaryOperator { public interface LongBinaryOperator {
/** /**
* Returns the {@code long} result of the operation upon the {@code long} * Applies this operator to the given operands.
* 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 left the first operand
* @param right the right operand value * @param right the second operand
* @return the result of the operation * @return the operator result
*/ */
long applyAsLong(long left, long right); long applyAsLong(long left, long right);
} }
...@@ -27,10 +27,13 @@ package java.util.function; ...@@ -27,10 +27,13 @@ package java.util.function;
import java.util.Objects; import java.util.Objects;
/** /**
* An operation which accepts a single long argument and returns no result. * Represents an operation that accepts a single {@code long}-valued argument and
* This is the {@code long}-consuming primitive type specialization of * returns no result. This is the primitive type specialization of
* {@link Consumer}. Unlike most other functional interfaces, {@code LongConsumer} * {@link Consumer} for {@code long}. Unlike most other functional interfaces,
* is expected to operate via side-effects. * {@code LongConsumer} is expected to operate via side-effects.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #accept(long)}.
* *
* @see Consumer * @see Consumer
* @since 1.8 * @since 1.8
...@@ -39,30 +42,26 @@ import java.util.Objects; ...@@ -39,30 +42,26 @@ import java.util.Objects;
public interface LongConsumer { public interface LongConsumer {
/** /**
* Accept an input value. * Performs this operation on the given argument.
* *
* @param value the input value * @param value the input argument
*/ */
void accept(long value); void accept(long value);
/** /**
* Returns a {@code LongConsumer} which performs, in sequence, the operation * Returns a composed {@code LongConsumer} that performs, in sequence, this
* represented by this object followed by the operation represented by * operation followed by the {@code after} operation. If performing either
* another {@code LongConsumer}. * operation throws an exception, it is relayed to the caller of the
* * composed operation. If performing this operation throws an exception,
* <p>Any exceptions thrown by either {@code accept} method are relayed * the {@code after} operation will not be performed.
* to the caller; if performing this operation throws an exception, the
* other operation will not be performed.
* *
* @param other a LongConsumer which will be chained after this * @param after the operation to perform after this operation
* LongConsumer * @return a composed {@code LongConsumer} that performs in sequence this
* @return a LongConsumer which performs in sequence the {@code accept} method * operation followed by the {@code after} operation
* of this LongConsumer and the {@code accept} method of the specified LongConsumer * @throws NullPointerException if {@code after} is null
* operation
* @throws NullPointerException if other is null
*/ */
default LongConsumer chain(LongConsumer other) { default LongConsumer andThen(LongConsumer after) {
Objects.requireNonNull(other); Objects.requireNonNull(after);
return (long t) -> { accept(t); other.accept(t); }; return (long t) -> { accept(t); after.accept(t); };
} }
} }
...@@ -25,11 +25,14 @@ ...@@ -25,11 +25,14 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the long-valued input argument, yielding an appropriate * Represents a function that accepts a long-valued argument and produces a
* result. This is the {@code long}-consuming primitive specialization for * result. This is the {@code long}-consuming primitive specialization for
* {@link Function}. * {@link Function}.
* *
* @param <R> the type of output objects from the function * <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #apply(long)}.
*
* @param <R> the type of the result of the function
* *
* @see Function * @see Function
* @since 1.8 * @since 1.8
...@@ -38,9 +41,9 @@ package java.util.function; ...@@ -38,9 +41,9 @@ package java.util.function;
public interface LongFunction<R> { public interface LongFunction<R> {
/** /**
* Compute the result of applying the function to the input argument * Applies this function to the given argument.
* *
* @param value the input value * @param value the function argument
* @return the function result * @return the function result
*/ */
R apply(long value); R apply(long value);
......
...@@ -27,8 +27,12 @@ package java.util.function; ...@@ -27,8 +27,12 @@ package java.util.function;
import java.util.Objects; import java.util.Objects;
/** /**
* Determines if the {@code long} input value matches some criteria. This is the * Represents a predicate (boolean-valued function) of one {@code long}-valued
* {@code long}-consuming primitive type specialization of {@link Predicate}. * argument. This is the {@code long}-consuming primitive type specialization of
* {@link Predicate}.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #test(long)}.
* *
* @see Predicate * @see Predicate
* @since 1.8 * @since 1.8
...@@ -37,37 +41,40 @@ import java.util.Objects; ...@@ -37,37 +41,40 @@ import java.util.Objects;
public interface LongPredicate { public interface LongPredicate {
/** /**
* Returns {@code true} if the input value matches some criteria. * Evaluates this predicate on the given argument.
* *
* @param value the value to be tested * @param value the input argument
* @return {@code true} if the input value matches some criteria, otherwise * @return {@code true} if the input argument matches the predicate,
* {@code false} * otherwise {@code false}
*/ */
boolean test(long value); boolean test(long value);
/** /**
* Returns a predicate which evaluates to {@code true} only if this * Returns a composed predicate that represents a short-circuiting logical
* predicate and the provided predicate both evaluate to {@code true}. If * AND of this predicate and another. When evaluating the composed
* this predicate returns {@code false} then the remaining predicate is not * predicate, if this predicate is {@code false}, then the {@code other}
* evaluated. * predicate is not evaluated.
* *
* <p>Any exceptions thrown by either {@code test} method are relayed * <p>Any exceptions thrown during evaluation of either predicate are relayed
* to the caller; if performing first operation throws an exception, the * to the caller; if evaluation of this predicate throws an exception, the
* second operation will not be performed. * {@code other} predicate will not be evaluated.
* *
* @param p a predicate which will be logically-ANDed with this predicate * @param other a predicate that will be logically-ANDed with this
* @return a new predicate which returns {@code true} only if both * predicate
* predicates return {@code true} * @return a composed predicate that represents the short-circuiting logical
* AND of this predicate and the {@code other} predicate
* @throws NullPointerException if other is null
*/ */
default LongPredicate and(LongPredicate p) { default LongPredicate and(LongPredicate other) {
Objects.requireNonNull(p); Objects.requireNonNull(other);
return (value) -> test(value) && p.test(value); return (value) -> test(value) && other.test(value);
} }
/** /**
* Returns a predicate which negates the result of this predicate. * Returns a predicate that represents the logical negation of this
* predicate.
* *
* @return a new predicate who's result is always the opposite of this * @return a predicate that represents the logical negation of this
* predicate * predicate
*/ */
default LongPredicate negate() { default LongPredicate negate() {
...@@ -75,22 +82,23 @@ public interface LongPredicate { ...@@ -75,22 +82,23 @@ public interface LongPredicate {
} }
/** /**
* Returns a predicate which evaluates to {@code true} if either this * Returns a composed predicate that represents a short-circuiting logical
* predicate or the provided predicate evaluates to {@code true}. If this * OR of this predicate and another. When evaluating the composed
* predicate returns {@code true} then the remaining predicate is not * predicate, if this predicate is {@code true}, then the {@code other}
* evaluated. * predicate is not evaluated.
* *
* <p>Any exceptions thrown by either {@code test} method are relayed * <p>Any exceptions thrown during evaluation of either predicate are relayed
* to the caller; if performing first operation throws an exception, the * to the caller; if evaluation of this predicate throws an exception, the
* second operation will not be performed. * {@code other} predicate will not be evaluated.
* *
* @param p a predicate which will be logically-ORed with this predicate * @param other a predicate that will be logically-ORed with this
* @return a new predicate which returns {@code true} if either predicate * predicate
* returns {@code true} * @return a composed predicate that represents the short-circuiting logical
* @throws NullPointerException if p is null * OR of this predicate and the {@code other} predicate
* @throws NullPointerException if other is null
*/ */
default LongPredicate or(LongPredicate p) { default LongPredicate or(LongPredicate other) {
Objects.requireNonNull(p); Objects.requireNonNull(other);
return (value) -> test(value) || p.test(value); return (value) -> test(value) || other.test(value);
} }
} }
...@@ -25,8 +25,14 @@ ...@@ -25,8 +25,14 @@
package java.util.function; package java.util.function;
/** /**
* A supplier of {@code long} values. This is the {@code long}-providing * Represents a supplier of {@code long}-valued results. This is the
* primitive specialization of {@link Supplier}. * {@code long}-producing primitive specialization of {@link Supplier}.
*
* <p>There is no requirement that a distinct result be returned each
* time the supplier is invoked.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #getAsLong()}.
* *
* @see Supplier * @see Supplier
* @since 1.8 * @since 1.8
...@@ -35,9 +41,9 @@ package java.util.function; ...@@ -35,9 +41,9 @@ package java.util.function;
public interface LongSupplier { public interface LongSupplier {
/** /**
* Returns a {@code long} value. * Gets a result.
* *
* @return a {@code long} value * @return a result
*/ */
long getAsLong(); long getAsLong();
} }
...@@ -25,22 +25,24 @@ ...@@ -25,22 +25,24 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the input argument, yielding an appropriate result. * Represents a function that accepts a long-valued argument and produces a
* This is the {@code long}-to-{@code double} specialization for {@link Function}. * double-valued result. This is the {@code long}-to-{@code double} primitive
* specialization for {@link Function}.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #applyAsDouble(long)}.
* *
* @see Function * @see Function
* @see DoubleToLongFunction
* @see IntToDoubleFunction
* @since 1.8 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface LongToDoubleFunction { public interface LongToDoubleFunction {
/** /**
* Compute the result of applying the function to the input arguments. * Applies this function to the given argument.
* *
* @param value the input value * @param value the function argument
* @return the function result value * @return the function result
*/ */
double applyAsDouble(long value); double applyAsDouble(long value);
} }
...@@ -25,22 +25,24 @@ ...@@ -25,22 +25,24 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the input argument, yielding an appropriate result. * Represents a function that accepts a long-valued argument and produces an
* This is the {@code long}-to-{@code int} specialization for {@link Function}. * int-valued result. This is the {@code long}-to-{@code int} primitive
* specialization for {@link Function}.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #applyAsInt(long)}.
* *
* @see Function * @see Function
* @see IntToLongFunction
* @see DoubleToIntFunction
* @since 1.8 * @since 1.8
*/ */
@FunctionalInterface @FunctionalInterface
public interface LongToIntFunction { public interface LongToIntFunction {
/** /**
* Compute the result of applying the function to the input arguments. * Applies this function to the given argument.
* *
* @param value the input value * @param value the function argument
* @return the function result value * @return the function result
*/ */
int applyAsInt(long value); int applyAsInt(long value);
} }
...@@ -27,9 +27,12 @@ package java.util.function; ...@@ -27,9 +27,12 @@ package java.util.function;
import java.util.Objects; import java.util.Objects;
/** /**
* An operation on a single {@code long} operand yielding a {@code long} result. * Represents an operation on a single {@code long}-valued operand that produces
* This is the primitive type specialization of {@link UnaryOperator} for * a {@code long}-valued result. This is the primitive type specialization of
* {@code long}. * {@link UnaryOperator} for {@code long}.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #applyAsLong(long)}.
* *
* @see UnaryOperator * @see UnaryOperator
* @since 1.8 * @since 1.8
...@@ -38,24 +41,25 @@ import java.util.Objects; ...@@ -38,24 +41,25 @@ import java.util.Objects;
public interface LongUnaryOperator { public interface LongUnaryOperator {
/** /**
* Returns the {@code long} result of the operation upon the {@code long} * Applies this operator to the given operand.
* operand.
* *
* @param operand the operand value * @param operand the operand
* @return the operation result value * @return the operator result
*/ */
long applyAsLong(long operand); long applyAsLong(long operand);
/** /**
* Compose a new function which applies the provided function followed by * Returns a composed operator that first applies the {@code before}
* this function. If either function throws an exception, it is relayed * operator to its input, and then applies this operator to the result.
* to the caller. * If evaluation of either operator throws an exception, it is relayed to
* the caller of the composed operator.
* *
* @param before An additional function to be applied before this function * @param before the operator to apply before this operator is applied
* is applied * @return a composed operator that first applies the {@code before}
* @return A function which performs the provided function followed by this * operator and then applies this operator
* function
* @throws NullPointerException if before is null * @throws NullPointerException if before is null
*
* @see #andThen(LongUnaryOperator)
*/ */
default LongUnaryOperator compose(LongUnaryOperator before) { default LongUnaryOperator compose(LongUnaryOperator before) {
Objects.requireNonNull(before); Objects.requireNonNull(before);
...@@ -63,15 +67,17 @@ public interface LongUnaryOperator { ...@@ -63,15 +67,17 @@ public interface LongUnaryOperator {
} }
/** /**
* Compose a new function which applies this function followed by the * Returns a composed operator that first applies this operator to
* provided function. If either function throws an exception, it is relayed * its input, and then applies the {@code after} operator to the result.
* to the caller. * If evaluation of either operator throws an exception, it is relayed to
* the caller of the composed operator.
* *
* @param after An additional function to be applied after this function is * @param after the operator to apply after this operator is applied
* applied * @return a composed operator that first applies this operator and then
* @return A function which performs this function followed by the provided * applies the {@code after} operator
* function followed
* @throws NullPointerException if after is null * @throws NullPointerException if after is null
*
* @see #compose(LongUnaryOperator)
*/ */
default LongUnaryOperator andThen(LongUnaryOperator after) { default LongUnaryOperator andThen(LongUnaryOperator after) {
Objects.requireNonNull(after); Objects.requireNonNull(after);
...@@ -79,9 +85,9 @@ public interface LongUnaryOperator { ...@@ -79,9 +85,9 @@ public interface LongUnaryOperator {
} }
/** /**
* Returns a unary operator that provides its input value as the result. * Returns a unary operator that always returns its input argument.
* *
* @return a unary operator that provides its input value as the result * @return a unary operator that always returns its input argument
*/ */
static LongUnaryOperator identity() { static LongUnaryOperator identity() {
return t -> t; return t -> t;
......
...@@ -25,12 +25,16 @@ ...@@ -25,12 +25,16 @@
package java.util.function; package java.util.function;
/** /**
* An operation which accepts an object reference and a double, and returns no * Represents an operation that accepts an object-valued and a
* result. This is the {@code (reference, double)} specialization of * {@code double}-valued argument, and returns no result. This is the
* {@link BiConsumer}. Unlike most other functional interfaces, * {@code (reference, double)} specialization of {@link BiConsumer}.
* {@code ObjDoubleConsumer} is expected to operate via side-effects. * Unlike most other functional interfaces, {@code ObjDoubleConsumer} is
* expected to operate via side-effects.
* *
* @param <T> Type of reference argument to {@code accept()}. * <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #accept(Object, double)}.
*
* @param <T> the type of the object argument to the operation
* *
* @see BiConsumer * @see BiConsumer
* @since 1.8 * @since 1.8
...@@ -39,10 +43,10 @@ package java.util.function; ...@@ -39,10 +43,10 @@ package java.util.function;
public interface ObjDoubleConsumer<T> { public interface ObjDoubleConsumer<T> {
/** /**
* Accept a set of input values. * Performs this operation on the given arguments.
* *
* @param t an input object * @param t the first input argument
* @param value an input value * @param value the second input argument
*/ */
void accept(T t, double value); void accept(T t, double value);
} }
...@@ -25,12 +25,16 @@ ...@@ -25,12 +25,16 @@
package java.util.function; package java.util.function;
/** /**
* An operation which accepts an object reference and an int, and returns no * Represents an operation that accepts an object-valued and a
* result. This is the {@code (reference, int)} specialization of * {@code int}-valued argument, and returns no result. This is the
* {@link BiConsumer}. Unlike most other functional interfaces, * {@code (reference, int)} specialization of {@link BiConsumer}.
* {@code ObjIntConsumer} is expected to operate via side-effects. * Unlike most other functional interfaces, {@code ObjIntConsumer} is
* expected to operate via side-effects.
* *
* @param <T> Type of reference argument to {@code accept()} * <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #accept(Object, int)}.
*
* @param <T> the type of the object argument to the operation
* *
* @see BiConsumer * @see BiConsumer
* @since 1.8 * @since 1.8
...@@ -39,10 +43,10 @@ package java.util.function; ...@@ -39,10 +43,10 @@ package java.util.function;
public interface ObjIntConsumer<T> { public interface ObjIntConsumer<T> {
/** /**
* Accept a set of input values. * Performs this operation on the given arguments.
* *
* @param t an input object * @param t the first input argument
* @param value an input value * @param value the second input argument
*/ */
void accept(T t, int value); void accept(T t, int value);
} }
...@@ -25,12 +25,16 @@ ...@@ -25,12 +25,16 @@
package java.util.function; package java.util.function;
/** /**
* An operation which accepts an object reference and a long, and returns no * Represents an operation that accepts an object-valued and a
* result. This is the {@code (reference, long)} specialization of * {@code long}-valued argument, and returns no result. This is the
* {@link BiConsumer}. Unlike most other functional interfaces, * {@code (reference, long)} specialization of {@link BiConsumer}.
* {@code ObjLongConsumer} is expected to operate via side-effects. * Unlike most other functional interfaces, {@code ObjLongConsumer} is
* expected to operate via side-effects.
* *
* @param <T> Type of reference argument to {@code accept()} * <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #accept(Object, long)}.
*
* @param <T> the type of the object argument to the operation
* *
* @see BiConsumer * @see BiConsumer
* @since 1.8 * @since 1.8
...@@ -39,10 +43,10 @@ package java.util.function; ...@@ -39,10 +43,10 @@ package java.util.function;
public interface ObjLongConsumer<T> { public interface ObjLongConsumer<T> {
/** /**
* Accept a set of input values. * Performs this operation on the given arguments.
* *
* @param t an input object * @param t the first input argument
* @param value an input value * @param value the second input argument
*/ */
void accept(T t, long value); void accept(T t, long value);
} }
...@@ -27,9 +27,12 @@ package java.util.function; ...@@ -27,9 +27,12 @@ package java.util.function;
import java.util.Objects; import java.util.Objects;
/** /**
* Determines if the input object matches some criteria. * Represents a predicate (boolean-valued function) of one argument.
* *
* @param <T> the type of argument to {@code test} * <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #test(Object)}.
*
* @param <T> the type of the input to the predicate
* *
* @since 1.8 * @since 1.8
*/ */
...@@ -37,76 +40,80 @@ import java.util.Objects; ...@@ -37,76 +40,80 @@ import java.util.Objects;
public interface Predicate<T> { public interface Predicate<T> {
/** /**
* Returns {@code true} if the input object matches some criteria. * Evaluates this predicate on the given argument.
* *
* @param t the input object * @param t the input argument
* @return {@code true} if the input object matches some criteria, otherwise * @return {@code true} if the input argument matches the predicate,
* {@code false} * otherwise {@code false}
*/ */
boolean test(T t); boolean test(T t);
/** /**
* Returns a predicate which evaluates to {@code true} only if this * Returns a composed predicate that represents a short-circuiting logical
* predicate and the provided predicate both evaluate to {@code true}. If * AND of this predicate and another. When evaluating the composed
* this predicate returns {@code false} then the remaining predicate is not * predicate, if this predicate is {@code false}, then the {@code other}
* evaluated. * predicate is not evaluated.
* *
* <p>Any exceptions thrown by either {@code test} method are relayed * <p>Any exceptions thrown during evaluation of either predicate are relayed
* to the caller; if performing first operation throws an exception, the * to the caller; if evaluation of this predicate throws an exception, the
* second operation will not be performed. * {@code other} predicate will not be evaluated.
* *
* @param p a predicate which will be logically-ANDed with this predicate * @param other a predicate that will be logically-ANDed with this
* @return a new predicate which returns {@code true} only if both * predicate
* predicates return {@code true} * @return a composed predicate that represents the short-circuiting logical
* @throws NullPointerException if p is null * AND of this predicate and the {@code other} predicate
* @throws NullPointerException if other is null
*/ */
default Predicate<T> and(Predicate<? super T> p) { default Predicate<T> and(Predicate<? super T> other) {
Objects.requireNonNull(p); Objects.requireNonNull(other);
return (t) -> test(t) && p.test(t); return (t) -> test(t) && other.test(t);
} }
/** /**
* Returns a predicate which negates the result of this predicate. * Returns a predicate that represents the logical negation of this
*
* @return a new predicate who's result is always the opposite of this
* predicate. * predicate.
*
* @return a predicate that represents the logical negation of this
* predicate
*/ */
default Predicate<T> negate() { default Predicate<T> negate() {
return (t) -> !test(t); return (t) -> !test(t);
} }
/** /**
* Returns a predicate which evaluates to {@code true} if either this * Returns a composed predicate that represents a short-circuiting logical
* predicate or the provided predicate evaluates to {@code true}. If this * OR of this predicate and another. When evaluating the composed
* predicate returns {@code true} then the remaining predicate is not * predicate, if this predicate is {@code true}, then the {@code other}
* evaluated. * predicate is not evaluated.
* *
* <p>Any exceptions thrown by either {@code test} method are relayed * <p>Any exceptions thrown during evaluation of either predicate are relayed
* to the caller; if performing first operation throws an exception, the * to the caller; if evaluation of this predicate throws an exception, the
* second operation will not be performed. * {@code other} predicate will not be evaluated.
* *
* @param p a predicate which will be logically-ORed with this predicate * @param other a predicate that will be logically-ORed with this
* @return a new predicate which returns {@code true} if either predicate * predicate
* returns {@code true} * @return a composed predicate that represents the short-circuiting logical
* @throws NullPointerException if p is null * OR of this predicate and the {@code other} predicate
* @throws NullPointerException if other is null
*/ */
default Predicate<T> or(Predicate<? super T> p) { default Predicate<T> or(Predicate<? super T> other) {
Objects.requireNonNull(p); Objects.requireNonNull(other);
return (t) -> test(t) || p.test(t); return (t) -> test(t) || other.test(t);
} }
/** /**
* Returns a predicate who's result matches * Returns a predicate that tests if two arguments are equal according
* {@code Objects.equals(target, t)}. * to {@link Objects#equals(Object, Object)}.
* *
* @param <T> the type of values evaluated by the predicate * @param <T> the type of arguments to the predicate
* @param target the target value to be compared for equality * @param targetRef the object reference with which to compare for equality,
* @return a predicate who's result matches * which may be {@code null}
* {@code Objects.equals(target, t)} * @return a predicate that tests if two arguments are equal according
* to {@link Objects#equals(Object, Object)}
*/ */
static <T> Predicate<T> isEqual(Object target) { static <T> Predicate<T> isEqual(Object targetRef) {
return (null == target) return (null == targetRef)
? Objects::isNull ? Objects::isNull
: object -> target.equals(object); : object -> targetRef.equals(object);
} }
} }
...@@ -25,10 +25,15 @@ ...@@ -25,10 +25,15 @@
package java.util.function; package java.util.function;
/** /**
* A supplier of objects. The result objects are either created during the * Represents a supplier of results.
* invocation of {@link #get} or by some prior action.
* *
* @param <T> The type of objects returned by {@code get} * <p>There is no requirement that a new or distinct result be returned each
* time the supplier is invoked.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #get()}.
*
* @param <T> the type of results supplied by this supplier
* *
* @since 1.8 * @since 1.8
*/ */
...@@ -36,9 +41,9 @@ package java.util.function; ...@@ -36,9 +41,9 @@ package java.util.function;
public interface Supplier<T> { public interface Supplier<T> {
/** /**
* Returns an object. * Gets a result.
* *
* @return an object * @return a result
*/ */
T get(); T get();
} }
...@@ -25,13 +25,15 @@ ...@@ -25,13 +25,15 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the input arguments, yielding an appropriate result. * Represents a function that accepts two arguments and produces a double-valued
* This is the {@code double}-bearing specialization for {@link BiFunction}. * result. This is the {@code double}-producing primitive specialization for
* {@link BiFunction}.
* *
* @param <T> the type of the first argument to the {@code applyAsDouble} * <p>This is a <a href="package-summary.html">functional interface</a>
* operation. * whose functional method is {@link #applyAsDouble(Object, Object)}.
* @param <U> the type of the second argument to the {@code applyAsDouble} *
* operation. * @param <T> the type of the first argument to the function
* @param <U> the type of the second argument to the function
* *
* @see BiFunction * @see BiFunction
* @since 1.8 * @since 1.8
...@@ -40,11 +42,11 @@ package java.util.function; ...@@ -40,11 +42,11 @@ package java.util.function;
public interface ToDoubleBiFunction<T, U> { public interface ToDoubleBiFunction<T, U> {
/** /**
* Compute the result of applying the function to the input arguments * Applies this function to the given arguments.
* *
* @param t an input object * @param t the first function argument
* @param u an input object * @param u the second function argument
* @return the function result value * @return the function result
*/ */
double applyAsDouble(T t, U u); double applyAsDouble(T t, U u);
} }
...@@ -25,10 +25,13 @@ ...@@ -25,10 +25,13 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the input argument, yielding an appropriate result. * Represents a function that produces a double-valued result. This is the
* This is the {@code double}-bearing specialization for {@link Function}. * {@code double}-producing primitive specialization for {@link Function}.
* *
* @param <T> the type of input objects to the function * <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #applyAsDouble(Object)}.
*
* @param <T> the type of the input to the function
* *
* @see Function * @see Function
* @since 1.8 * @since 1.8
...@@ -37,10 +40,10 @@ package java.util.function; ...@@ -37,10 +40,10 @@ package java.util.function;
public interface ToDoubleFunction<T> { public interface ToDoubleFunction<T> {
/** /**
* Compute the result of applying the function to the input argument * Applies this function to the given argument.
* *
* @param t the input object * @param value the function argument
* @return the function result value * @return the function result
*/ */
double applyAsDouble(T t); double applyAsDouble(T value);
} }
...@@ -25,13 +25,15 @@ ...@@ -25,13 +25,15 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the input arguments, yielding an appropriate result. * Represents a function that accepts two arguments and produces an int-valued
* This is the {@code int}-bearing specialization for {@link BiFunction}. * result. This is the {@code int}-producing primitive specialization for
* {@link BiFunction}.
* *
* @param <T> the type of the first argument to the {@code applyAsInt} * <p>This is a <a href="package-summary.html">functional interface</a>
* operation * whose functional method is {@link #applyAsInt(Object, Object)}.
* @param <U> the type of the second argument to the {@code applyAsInt} *
* operation * @param <T> the type of the first argument to the function
* @param <U> the type of the second argument to the function
* *
* @see BiFunction * @see BiFunction
* @since 1.8 * @since 1.8
...@@ -40,11 +42,11 @@ package java.util.function; ...@@ -40,11 +42,11 @@ package java.util.function;
public interface ToIntBiFunction<T, U> { public interface ToIntBiFunction<T, U> {
/** /**
* Compute the result of applying the function to the input arguments * Applies this function to the given arguments.
* *
* @param t an input object * @param t the first function argument
* @param u an input object * @param u the second function argument
* @return the function result value * @return the function result
*/ */
int applyAsInt(T t, U u); int applyAsInt(T t, U u);
} }
...@@ -25,10 +25,13 @@ ...@@ -25,10 +25,13 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the input argument, yielding an appropriate result. * Represents a function that produces an int-valued result. This is the
* This is the {@code int}-bearing specialization for {@link Function}. * {@code int}-producing primitive specialization for {@link Function}.
* *
* @param <T> the type of input objects to the function * <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #applyAsInt(Object)}.
*
* @param <T> the type of the input to the function
* *
* @see Function * @see Function
* @since 1.8 * @since 1.8
...@@ -37,10 +40,10 @@ package java.util.function; ...@@ -37,10 +40,10 @@ package java.util.function;
public interface ToIntFunction<T> { public interface ToIntFunction<T> {
/** /**
* Compute the result of applying the function to the input arguments * Applies this function to the given argument.
* *
* @param t the input object * @param value the function argument
* @return the function result value * @return the function result
*/ */
int applyAsInt(T t); int applyAsInt(T value);
} }
...@@ -25,13 +25,15 @@ ...@@ -25,13 +25,15 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the input arguments, yielding an appropriate result. * Represents a function that accepts two arguments and produces a long-valued
* This is the {@code long}-bearing specialization for {@link BiFunction}. * result. This is the {@code long}-producing primitive specialization for
* {@link BiFunction}.
* *
* @param <T> the type of the first argument to the {@code applyAsLong} * <p>This is a <a href="package-summary.html">functional interface</a>
* operation. * whose functional method is {@link #applyAsLong(Object, Object)}.
* @param <U> the type of the second argument to the {@code applyAsLong} *
* operation. * @param <T> the type of the first argument to the function
* @param <U> the type of the second argument to the function
* *
* @see BiFunction * @see BiFunction
* @since 1.8 * @since 1.8
...@@ -40,11 +42,11 @@ package java.util.function; ...@@ -40,11 +42,11 @@ package java.util.function;
public interface ToLongBiFunction<T, U> { public interface ToLongBiFunction<T, U> {
/** /**
* Compute the result of applying the function to the input arguments. * Applies this function to the given arguments.
* *
* @param t an input object * @param t the first function argument
* @param u an input object * @param u the second function argument
* @return the function result value * @return the function result
*/ */
long applyAsLong(T t, U u); long applyAsLong(T t, U u);
} }
...@@ -25,10 +25,13 @@ ...@@ -25,10 +25,13 @@
package java.util.function; package java.util.function;
/** /**
* Apply a function to the input argument, yielding an appropriate result. * Represents a function that produces a long-valued result. This is the
* This is the {@code long}-bearing specialization for {@link Function}. * {@code long}-producing primitive specialization for {@link Function}.
* *
* @param <T> the type of input objects to the function * <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #applyAsLong(Object)}.
*
* @param <T> the type of the input to the function
* *
* @see Function * @see Function
* @since 1.8 * @since 1.8
...@@ -37,10 +40,10 @@ package java.util.function; ...@@ -37,10 +40,10 @@ package java.util.function;
public interface ToLongFunction<T> { public interface ToLongFunction<T> {
/** /**
* Compute the result of applying the function to the input arguments. * Applies this function to the given argument.
* *
* @param t the input object * @param value the function argument
* @return the function result value * @return the function result
*/ */
long applyAsLong(T t); long applyAsLong(T value);
} }
...@@ -25,11 +25,14 @@ ...@@ -25,11 +25,14 @@
package java.util.function; package java.util.function;
/** /**
* An operation upon a single operand yielding a result. The operand and the * Represents an operation on a single operand that produces a result of the
* result are of the same type. This is a specialization of {@code Function} for * same type as its operand. This is a specialization of {@code Function} for
* the case where the operand and result are of the same type. * the case where the operand and result are of the same type.
* *
* @param <T> the type of operand to {@code apply} and of the result * <p>This is a <a href="package-summary.html">functional interface</a>
* whose functional method is {@link #apply(Object)}.
*
* @param <T> the type of the operand and result of the operator
* *
* @see Function * @see Function
* @since 1.8 * @since 1.8
...@@ -38,10 +41,10 @@ package java.util.function; ...@@ -38,10 +41,10 @@ package java.util.function;
public interface UnaryOperator<T> extends Function<T, T> { public interface UnaryOperator<T> extends Function<T, T> {
/** /**
* Returns a unary operator that provides its input value as the result. * Returns a unary operator that always returns its input argument.
* *
* @param <T> the type of the input and output objects to the function * @param <T> the type of the input and output of the operator
* @return a unary operator that provides its input value as the result * @return a unary operator that always returns its input argument
*/ */
static <T> UnaryOperator<T> identity() { static <T> UnaryOperator<T> identity() {
return t -> t; return t -> t;
......
/* /*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,56 +25,82 @@ ...@@ -25,56 +25,82 @@
/** /**
* <em>Functional interfaces</em> provide target types for lambda expressions * <em>Functional interfaces</em> provide target types for lambda expressions
* and method references. Each functional interface has a single abstract method * and method references. Each functional interface has a single abstract
* method, called the <em>functional method</em> for that functional interface,
* to which the lambda expression's parameter and return types are matched or * to which the lambda expression's parameter and return types are matched or
* adapted. Functional interfaces can provide a target type in multiple contexts, * adapted. Functional interfaces can provide a target type in multiple
* such as assignment context, method invocation, or cast context: * contexts, such as assignment context, method invocation, or cast context:
* *
* <pre>{@code * <pre>{@code
* // Assignment context
* Predicate<String> p = String::isEmpty; * Predicate<String> p = String::isEmpty;
* *
* // Method invocation context
* stream.filter(e -> e.getSize() > 10)... * stream.filter(e -> e.getSize() > 10)...
* *
* // Cast context
* stream.map((ToIntFunction) e -> e.getSize())... * stream.map((ToIntFunction) e -> e.getSize())...
* }</pre> * }</pre>
* *
* <p>The interfaces in this package are functional interfaces used by the JDK, * <p>The interfaces in this package are general purpose functional interfaces
* and are available to be used by user code as well. While they do not identify * used by the JDK, and are available to be used by user code as well. While
* a complete set of function shapes to which lambda expressions might be adapted, * they do not identify a complete set of function shapes to which lambda
* they provide enough to cover common requirements. * expressions might be adapted, they provide enough to cover common
* requirements. Other functional interfaces provided for specific purposes,
* such as {@link java.io.FileFilter}, are defined in the packages where they
* are used.
* *
* <p>The interfaces in this package are annotated with @{link FunctionalInterface}. * <p>The interfaces in this package are annotated with
* This annotation is not a requirement for the compiler to recognize an interface * {@link java.lang.FunctionalInterface}. This annotation is not a requirement
* as a functional interface, but merely an aid to capture design intent and enlist the * for the compiler to recognize an interface as a functional interface, but
* help of the compiler in identifying accidental violations of design intent. * 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, * <p>Functional interfaces often represent abstract concepts like functions,
* as follows: * actions, or predicates. In documenting functional interfaces, or referring
* to variables typed as functional interfaces, it is common to refer directly
* to those abstract concepts, for example using "this function" instead of
* "the function represented by this object".
*
* <p>The functional interfaces in this package follow an extensible naming
* convention, as follows:
* *
* <ul> * <ul>
* <li>There are several basic function shapes, including {@link java.util.function.Function} ({@code T -> R}), * <li>There are several basic function shapes, including
* {@link java.util.function.Consumer} ({@code T -> void}), * {@link java.util.function.Function} (unary function from {@code T} to {@code R}),
* {@link java.util.function.Predicate} ({@code T -> boolean}), * {@link java.util.function.Consumer} (unary function from {@code T} to {@code void}),
* and {@link java.util.function.Supplier} ({@code () -> T}). * {@link java.util.function.Predicate} (unary function from {@code T} to {@code boolean}),
* and {@link java.util.function.Supplier} (nilary function to {@code R}).
* </li> * </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, * <li>Function shapes have a natural arity based on how they are most
* such as {@link java.util.function.BiFunction} ({@code (T, U) -> R}). * commonly used. The basic shapes can be modified by an arity prefix to
* indicate a different arity, such as
* {@link java.util.function.BiFunction} (binary function from {@code T} and
* {@code U} to {@code R}).
* </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 * <li>There are additional derived function shapes which extend the basic
* {@link java.util.function.BinaryOperator} (extends {@code BiFunction}). * function shapes, including {@link java.util.function.UnaryOperator}
* (extends {@code Function}) and {@link java.util.function.BinaryOperator}
* (extends {@code BiFunction}).
* </li> * </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 * <li>Type parameters of functional interfaces can be specialized to
* generic return type and generic arguments, we prefix {@code ToXxx}, as in * primitives with additional type prefixes. To specialize the return type
* {@link java.util.function.ToIntFunction}. Otherwise, type arguments are specialized left-to-right, * for a type that has both generic return type and generic arguments, we
* as in {@link java.util.function.DoubleConsumer} or {@link java.util.function.ObjIntConsumer}. * prefix {@code ToXxx}, as in {@link java.util.function.ToIntFunction}.
* (The type prefix {@code Obj} is used to indicate that we don't want to specialize this parameter, * Otherwise, type arguments are specialized left-to-right, as in
* but want to move on to the next parameter.) These schemes can be combined as in {@code IntToDoubleFunction}. * {@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,
* as in {@link java.util.function.ObjIntConsumer}.)
* These schemes can be combined, as in {@code IntToDoubleFunction}.
* </li> * </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>If there are specialization prefixes for all arguments, the arity
* prefix may be left out (as in {@link java.util.function.ObjIntConsumer}).
* </li> * </li>
* </ul> * </ul>
* *
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册