001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.apache.commons.lang3.function;
019
020import java.util.Objects;
021import java.util.function.Consumer;
022
023/**
024 * Represents an operation that accepts three input arguments and returns no result. This is the three-arity
025 * specialization of {@link Consumer}. Unlike most other functional interfaces, {@link TriConsumer} is expected to
026 * operate via side effects.
027 *
028 * <p>
029 * This is a {@link FunctionalInterface} whose functional method is {@link #accept(Object, Object, Object)}.
030 * </p>
031 * <p>
032 * Provenance: Apache Log4j 2.7
033 * </p>
034 *
035 * @param <T> type of the first argument
036 * @param <U> type of the second argument
037 * @param <V> type of the third argument
038 * @since 3.13.0
039 */
040@FunctionalInterface
041public interface TriConsumer<T, U, V> {
042
043    /**
044     * Performs the operation given the specified arguments.
045     *
046     * @param k the first input argument
047     * @param v the second input argument
048     * @param s the third input argument
049     */
050    void accept(T k, U v, V s);
051
052    /**
053     * Returns a composed {@link TriConsumer} that performs, in sequence, this operation followed by the {@code after}
054     * operation. If performing either operation throws an exception, it is relayed to the caller of the composed
055     * operation. If performing this operation throws an exception, the {@code after} operation will not be performed.
056     *
057     * @param after the operation to perform after this operation.
058     * @return a composed {@link TriConsumer} that performs in sequence this operation followed by the {@code after}
059     *         operation.
060     * @throws NullPointerException if {@code after} is null.
061     */
062    default TriConsumer<T, U, V> andThen(final TriConsumer<? super T, ? super U, ? super V> after) {
063        Objects.requireNonNull(after);
064
065        return (t, u, v) -> {
066            accept(t, u, v);
067            after.accept(t, u, v);
068        };
069    }
070
071}