    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.io.function;
    019
    020import java.io.IOException;
    021import java.util.Objects;
    022import java.util.function.BiConsumer;
    023
    024/**
    025 * Like {@link BiConsumer} but throws {@link IOException}.
    026 *
    027 * @param <T> the type of the first argument to the operation
    028 * @param <U> the type of the second argument to the operation
    029 * @param <V> the type of the third argument to the operation
    030 *
    031 * @see BiConsumer
    032 * @since 2.12.0
    033 */
    034@FunctionalInterface
    035public interface IOTriConsumer<T, U, V> {
    036
    037    /**
    038     * Returns the no-op singleton.
    039     *
    040     * @param <T> the type of the first argument to the operation
    041     * @param <U> the type of the second argument to the operation
    042     * @param <V> the type of the third argument to the operation
    043     * @return The no-op singleton.
    044     */
    045    @SuppressWarnings("unchecked")
    046    static <T, U, V> IOTriConsumer<T, U, V> noop() {
    047        return Constants.IO_TRI_CONSUMER;
    048    }
    049
    050    /**
    051     * Performs this operation on the given arguments.
    052     *
    053     * @param t the first input argument
    054     * @param u the second input argument
    055     * @param v the second third argument
    056     * @throws IOException if an I/O error occurs.
    057     */
    058    void accept(T t, U u, V v) throws IOException;
    059
    060    /**
    061     * Creates a composed {@link IOTriConsumer} that performs, in sequence, this operation followed by the {@code after}
    062     * operation. If performing either operation throws an exception, it is relayed to the caller of the composed operation.
    063     * If performing this operation throws an exception, the {@code after} operation will not be performed.
    064     *
    065     * @param after the operation to perform after this operation
    066     * @return a composed {@link IOTriConsumer} that performs in sequence this operation followed by the {@code after}
    067     *         operation
    068     * @throws NullPointerException if {@code after} is null
    069     */
    070    default IOTriConsumer<T, U, V> andThen(final IOTriConsumer<? super T, ? super U, ? super V> after) {
    071        Objects.requireNonNull(after);
    072        return (t, u, v) -> {
    073            accept(t, u, v);
    074            after.accept(t, u, v);
    075        };
    076    }
    077}