jdk/src/share/classes/java/util/function/IntUnaryOperator.java
changeset 19040 7b25fde2a4ed
parent 17695 032254f2467b
equal deleted inserted replaced
19037:18aee3cc498f 19040:7b25fde2a4ed
    25 package java.util.function;
    25 package java.util.function;
    26 
    26 
    27 import java.util.Objects;
    27 import java.util.Objects;
    28 
    28 
    29 /**
    29 /**
    30  * An operation on a single {@code int} operand yielding an {@code int} result.
    30  * Represents an operation on a single {@code int}-valued operand that produces
    31  * This is the primitive type specialization of {@link UnaryOperator} for
    31  * an {@code int}-valued result.  This is the primitive type specialization of
    32  * {@code int}.
    32  * {@link UnaryOperator} for {@code int}.
       
    33  *
       
    34  * <p>This is a <a href="package-summary.html">functional interface</a>
       
    35  * whose functional method is {@link #applyAsInt(int)}.
    33  *
    36  *
    34  * @see UnaryOperator
    37  * @see UnaryOperator
    35  * @since 1.8
    38  * @since 1.8
    36  */
    39  */
    37 @FunctionalInterface
    40 @FunctionalInterface
    38 public interface IntUnaryOperator {
    41 public interface IntUnaryOperator {
    39 
    42 
    40     /**
    43     /**
    41      * Returns the {@code int} value result of the operation upon the
    44      * Applies this operator to the given operand.
    42      * {@code int} operand.
       
    43      *
    45      *
    44      * @param operand the operand value
    46      * @param operand the operand
    45      * @return the operation result value
    47      * @return the operator result
    46      */
    48      */
    47     int applyAsInt(int operand);
    49     int applyAsInt(int operand);
    48 
    50 
    49     /**
    51     /**
    50      * Compose a new function which applies the provided function followed by
    52      * Returns a composed operator that first applies the {@code before}
    51      * this function.  If either function throws an exception, it is relayed
    53      * operator to its input, and then applies this operator to the result.
    52      * to the caller.
    54      * If evaluation of either operator throws an exception, it is relayed to
       
    55      * the caller of the composed operator.
    53      *
    56      *
    54      * @param before an additional function to be applied before this function
    57      * @param before the operator to apply before this operator is applied
    55      * is applied
    58      * @return a composed operator that first applies the {@code before}
    56      * @return a function which performs the provided function followed by this
    59      * operator and then applies this operator
    57      * function
       
    58      * @throws NullPointerException if before is null
    60      * @throws NullPointerException if before is null
       
    61      *
       
    62      * @see #andThen(IntUnaryOperator)
    59      */
    63      */
    60     default IntUnaryOperator compose(IntUnaryOperator before) {
    64     default IntUnaryOperator compose(IntUnaryOperator before) {
    61         Objects.requireNonNull(before);
    65         Objects.requireNonNull(before);
    62         return (int v) -> applyAsInt(before.applyAsInt(v));
    66         return (int v) -> applyAsInt(before.applyAsInt(v));
    63     }
    67     }
    64 
    68 
    65     /**
    69     /**
    66      * Compose a new function which applies this function followed by the
    70      * Returns a composed operator that first applies this operator to
    67      * provided function.  If either function throws an exception, it is relayed
    71      * its input, and then applies the {@code after} operator to the result.
    68      * to the caller.
    72      * If evaluation of either operator throws an exception, it is relayed to
       
    73      * the caller of the composed operator.
    69      *
    74      *
    70      * @param after an additional function to be applied after this function is
    75      * @param after the operator to apply after this operator is applied
    71      * applied
    76      * @return a composed operator that first applies this operator and then
    72      * @return a function which performs this function followed by the provided
    77      * applies the {@code after} operator
    73      * function followed
       
    74      * @throws NullPointerException if after is null
    78      * @throws NullPointerException if after is null
       
    79      *
       
    80      * @see #compose(IntUnaryOperator)
    75      */
    81      */
    76     default IntUnaryOperator andThen(IntUnaryOperator after) {
    82     default IntUnaryOperator andThen(IntUnaryOperator after) {
    77         Objects.requireNonNull(after);
    83         Objects.requireNonNull(after);
    78         return (int t) -> after.applyAsInt(applyAsInt(t));
    84         return (int t) -> after.applyAsInt(applyAsInt(t));
    79     }
    85     }
    80 
    86 
    81     /**
    87     /**
    82      * Returns a unary operator that provides its input value as the result.
    88      * Returns a unary operator that always returns its input argument.
    83      *
    89      *
    84      * @return a unary operator that provides its input value as the result
    90      * @return a unary operator that always returns its input argument
    85      */
    91      */
    86     static IntUnaryOperator identity() {
    92     static IntUnaryOperator identity() {
    87         return t -> t;
    93         return t -> t;
    88     }
    94     }
    89 }
    95 }