1 /* 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package java.util.function; 26 27 import java.util.Objects; 28 29 /** 30 * An operation which accepts two input arguments and returns no result. This is 31 * the two-arity specialization of {@link Consumer}. Unlike most other 32 * functional interfaces, {@code BiConsumer} is expected to operate via 33 * side-effects. 34 * 35 * @param <T> the type of the first argument to the {@code accept} operation 36 * @param <U> the type of the second argument to the {@code accept} operation 37 * 38 * @see Consumer 39 * @since 1.8 40 */ 41 @FunctionalInterface 42 public interface BiConsumer<T, U> { 43 44 /** 45 * Performs operations upon the provided objects which may modify those 46 * objects and/or external state. 47 * 48 * @param t an input object 49 * @param u an input object 50 */ 51 void accept(T t, U u); 52 53 /** 54 * Returns a BiConsumer which performs in sequence the {@code accept} 55 * methods of multiple BiConsumers. This BiConsumer's {@code accept} method 56 * is performed followed by the {@code accept} method of the specified 57 * BiConsumer operation. 58 * 59 * @param other an additional BiConsumer which will be chained after this 60 * BiConsumer 61 * @return a BiConsumer which performs in sequence the {@code accept} method 62 * of this BiConsumer and the {@code accept} method of the specified 63 * BiConsumer operation 64 * @throws NullPointerException if other is null 65 */ 66 default BiConsumer<T, U> chain(BiConsumer<? super T, ? super U> other) { 67 Objects.requireNonNull(other); 68 69 return (l, r) -> { 70 accept(l, r); 71 other.accept(l, r); 72 }; 73 } 74 }