1607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller/* 2607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * 5607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * This code is free software; you can redistribute it and/or modify it 6607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * under the terms of the GNU General Public License version 2 only, as 7607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * published by the Free Software Foundation. Oracle designates this 8607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * particular file as subject to the "Classpath" exception as provided 9607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * by Oracle in the LICENSE file that accompanied this code. 10607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * 11607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * This code is distributed in the hope that it will be useful, but WITHOUT 12607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * version 2 for more details (a copy is included in the LICENSE file that 15607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * accompanied this code). 16607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * 17607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * You should have received a copy of the GNU General Public License version 18607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * 2 along with this work; if not, write to the Free Software Foundation, 19607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * 21607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * or visit www.oracle.com if you need additional information or have any 23607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * questions. 24607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller */ 25607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fullerpackage java.util.function; 26607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller 27607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fullerimport java.util.Objects; 28607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller 29607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller/** 30607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * Represents an operation that accepts a single {@code int}-valued argument and 31607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * returns no result. This is the primitive type specialization of 32607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * {@link Consumer} for {@code int}. Unlike most other functional interfaces, 33607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * {@code IntConsumer} is expected to operate via side-effects. 34607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * 35607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * <p>This is a <a href="package-summary.html">functional interface</a> 36607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * whose functional method is {@link #accept(int)}. 37607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * 38607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * @see Consumer 39607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * @since 1.8 40607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller */ 41607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller@FunctionalInterface 42607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fullerpublic interface IntConsumer { 43607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller 44607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller /** 45607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * Performs this operation on the given argument. 46607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * 47607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * @param value the input argument 48607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller */ 49607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller void accept(int value); 50607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller 51607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller /** 52607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * Returns a composed {@code IntConsumer} that performs, in sequence, this 53607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * operation followed by the {@code after} operation. If performing either 54607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * operation throws an exception, it is relayed to the caller of the 55607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * composed operation. If performing this operation throws an exception, 56607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * the {@code after} operation will not be performed. 57607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * 58607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * @param after the operation to perform after this operation 59607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * @return a composed {@code IntConsumer} that performs in sequence this 60607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * operation followed by the {@code after} operation 61607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller * @throws NullPointerException if {@code after} is null 62607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller */ 63607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller default IntConsumer andThen(IntConsumer after) { 64607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller Objects.requireNonNull(after); 65607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller return (int t) -> { accept(t); after.accept(t); }; 66607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller } 67607050af5a16c46ae53ff4d2c3f47b4ef694b559Neil Fuller} 68