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