src/share/classes/java/util/function/IntConsumer.java
Print this page
rev 7675 : 8019840: Spec updates for java.util.function
Reviewed-by: mduigou
Contributed-by: brian.goetz@oracle.com
*** 25,68 ****
package java.util.function;
import java.util.Objects;
/**
! * An operation which accepts a single integer argument and returns no result.
! * This is the primitive type specialization of {@link Consumer} for {@code int}.
! * Unlike most other functional interfaces, {@code IntConsumer} is expected to
! * operate via side-effects.
*
* @see Consumer
* @since 1.8
*/
@FunctionalInterface
public interface IntConsumer {
/**
! * Accept an input value.
*
! * @param value the input value
*/
void accept(int value);
/**
! * Returns an {@code IntConsumer} which performs, in sequence, the operation
! * represented by this object followed by the operation represented by
! * another {@code IntConsumer}.
! *
! * <p>Any exceptions thrown by either {@code accept} method are relayed
! * 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
! * IntConsumer
! * @return an IntConsumer which performs in sequence the {@code accept} method
! * of this IntConsumer and the {@code accept} method of the specified IntConsumer
! * operation
! * @throws NullPointerException if other is null
*/
! default IntConsumer chain(IntConsumer other) {
! Objects.requireNonNull(other);
! return (int t) -> { accept(t); other.accept(t); };
}
}
--- 25,67 ----
package java.util.function;
import java.util.Objects;
/**
! * Represents an operation that accepts a single {@code int}-valued argument and
! * returns no result. This is the primitive type specialization of
! * {@link Consumer} for {@code int}. Unlike most other functional interfaces,
! * {@code IntConsumer} is expected to operate via side-effects.
! *
! * <p>This is a <a href="package-summary.html">functional interface</a>
! * whose functional method is {@link #accept(int)}.
*
* @see Consumer
* @since 1.8
*/
@FunctionalInterface
public interface IntConsumer {
/**
! * Performs this operation on the given argument.
*
! * @param value the input argument
*/
void accept(int value);
/**
! * Returns a composed {@code IntConsumer} that performs, in sequence, this
! * operation followed by the {@code after} operation. If performing either
! * operation throws an exception, it is relayed to the caller of the
! * composed operation. If performing this operation throws an exception,
! * the {@code after} operation will not be performed.
*
! * @param after the operation to perform after this operation
! * @return a composed {@code IntConsumer} that performs in sequence this
! * operation followed by the {@code after} operation
! * @throws NullPointerException if {@code after} is null
*/
! default IntConsumer andThen(IntConsumer after) {
! Objects.requireNonNull(after);
! return (int t) -> { accept(t); after.accept(t); };
}
}