1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.commons.lang3.function; 19 20 import java.util.Objects; 21 import java.util.function.Consumer; 22 23 /** 24 * Represents an operation that accepts three input arguments and returns no result. This is the three-arity 25 * specialization of {@link Consumer}. Unlike most other functional interfaces, {@link TriConsumer} is expected to 26 * operate via side effects. 27 * 28 * <p> 29 * This is a {@link FunctionalInterface} whose functional method is {@link #accept(Object, Object, Object)}. 30 * </p> 31 * <p> 32 * Provenance: Apache Log4j 2.7 33 * </p> 34 * 35 * @param <T> type of the first argument 36 * @param <U> type of the second argument 37 * @param <V> type of the third argument 38 * @since 3.13.0 39 */ 40 @FunctionalInterface 41 public interface TriConsumer<T, U, V> { 42 43 /** 44 * Performs the operation given the specified arguments. 45 * 46 * @param k the first input argument 47 * @param v the second input argument 48 * @param s the third input argument 49 */ 50 void accept(T k, U v, V s); 51 52 /** 53 * Returns a composed {@link TriConsumer} that performs, in sequence, this operation followed by the {@code after} 54 * operation. If performing either operation throws an exception, it is relayed to the caller of the composed 55 * operation. If performing this operation throws an exception, the {@code after} operation will not be performed. 56 * 57 * @param after the operation to perform after this operation. 58 * @return a composed {@link TriConsumer} that performs in sequence this operation followed by the {@code after} 59 * operation. 60 * @throws NullPointerException if {@code after} is null. 61 */ 62 default TriConsumer<T, U, V> andThen(final TriConsumer<? super T, ? super U, ? super V> after) { 63 Objects.requireNonNull(after); 64 65 return (t, u, v) -> { 66 accept(t, u, v); 67 after.accept(t, u, v); 68 }; 69 } 70 71 }