equal
deleted
inserted
replaced
22 * or visit www.oracle.com if you need additional information or have any |
22 * or visit www.oracle.com if you need additional information or have any |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 package java.util.function; |
25 package java.util.function; |
26 |
26 |
|
27 import java.util.Objects; |
|
28 |
27 /** |
29 /** |
28 * An operation which accepts a single integer argument and returns no result. |
30 * An operation which accepts a single integer argument and returns no result. |
29 * This is the primitive type specialization of {@link Consumer} for {@code int}. |
31 * This is the primitive type specialization of {@link Consumer} for {@code int}. |
30 * Unlike most other functional interfaces, {@code IntConsumer} is expected to |
32 * Unlike most other functional interfaces, {@code IntConsumer} is expected to |
31 * operate via side-effects. |
33 * operate via side-effects. |
39 /** |
41 /** |
40 * Accept an input value. |
42 * Accept an input value. |
41 * |
43 * |
42 * @param value the input value |
44 * @param value the input value |
43 */ |
45 */ |
44 public void accept(int value); |
46 void accept(int value); |
|
47 |
|
48 /** |
|
49 * Returns an {@code IntConsumer} which performs, in sequence, the operation |
|
50 * represented by this object followed by the operation represented by |
|
51 * another {@code IntConsumer}. |
|
52 * |
|
53 * <p>Any exceptions thrown by either {@code accept} method are relayed |
|
54 * to the caller; if performing this operation throws an exception, the |
|
55 * other operation will not be performed. |
|
56 * |
|
57 * @param other an IntConsumer which will be chained after this |
|
58 * IntConsumer |
|
59 * @return an IntConsumer which performs in sequence the {@code accept} method |
|
60 * of this IntConsumer and the {@code accept} method of the specified IntConsumer |
|
61 * operation |
|
62 * @throws NullPointerException if other is null |
|
63 */ |
|
64 default IntConsumer chain(IntConsumer other) { |
|
65 Objects.requireNonNull(other); |
|
66 return (int t) -> { accept(t); other.accept(t); }; |
|
67 } |
45 } |
68 } |