net.openhft.chronicle.testframework.function.ThrowingConsumer Maven / Gradle / Ivy
package net.openhft.chronicle.testframework.function;
import net.openhft.chronicle.testframework.internal.VanillaThrowingConsumer;
import java.util.function.Consumer;
import static java.util.Objects.requireNonNull;
/**
* Represents an operation that accepts a single input argument and returns no
* result and that can throw an Exception. Unlike most other functional interfaces, {@code Consumer} is expected
* to operate via side-effects.
*
* This is a functional interface
* whose functional method is {@link #accept(Object)}.
*
* @param the type of the input to the operation
*/
@FunctionalInterface
public interface ThrowingConsumer {
/**
* Performs this operation on the given argument.
*
* @param t the input argument
* @throws X if an exception occurs
*/
void accept(T t) throws X;
/**
* Creates and returns a new Consumer that will wrap any exceptions thrown by the
* provided {@code throwingConsumer} in a {@link ThrowingConsumerException}
* @param throwingConsumer to wrap (non-null)
* @param consumed type
* @return a wrapped Consumer
*/
static Consumer of(final ThrowingConsumer throwingConsumer) {
requireNonNull(throwingConsumer);
return new VanillaThrowingConsumer<>(throwingConsumer);
}
}