net.openhft.chronicle.wire.TriConsumer Maven / Gradle / Ivy
/*
* Copyright 2016-2020 chronicle.software
*
* https://chronicle.software
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.openhft.chronicle.wire;
import net.openhft.chronicle.core.io.InvalidMarshallableException;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
/**
* Represents an operation that accepts three input arguments and returns no result.
* This is a three-arity specialization of {@code Consumer}.
* Unlike most other functional interfaces, {@code TriConsumer} is expected to operate
* via side effects. This interface is useful in scenarios where lambda expressions
* or method references would benefit from custom manipulations of three separate arguments.
*
* @param the type of the first argument to the operation
* @param the type of the second argument to the operation
* @param the type of the third argument to the operation
*/
@FunctionalInterface
public interface TriConsumer {
/**
* Performs this operation on the given arguments.
*
* @param t the first input argument
* @param u the second input argument
* @param v the third input argument
* @throws InvalidMarshallableException if there are issues with marshalling
* during the accept operation.
*/
void accept(T t, U u, V v) throws InvalidMarshallableException;
/**
* Returns a composed {@code TriConsumer} that performs, in sequence, this
* operation followed by the {@code after} operation. If performing either
* operation throws an exception, it is relayed to the caller of the
* composed operation. If performing this operation throws an exception,
* the {@code after} operation will not be performed.
*
* @param after the operation to perform after this operation
* @return a composed {@code TriConsumer} that performs in sequence this
* operation followed by the {@code after} operation
* @throws NullPointerException if {@code after} is null
*/
@NotNull
default TriConsumer andThen(@NotNull TriConsumer super T, ? super U, ? super V> after) {
Objects.requireNonNull(after);
return (t, u, v) -> {
accept(t, u, v);
after.accept(t, u, v);
};
}
}