package info.ebenoit.ebul.func;
import java.util.function.Predicate;
/**
* This interface supports a {@link Predicate} that can throw checked exceptions. Checked exceptions are transmitted
* using a {@link FunctionException} runtime exception.
*
* @author E. BenoƮt
*/
@FunctionalInterface
public interface ThrowingPredicate< T >
extends Predicate< T >
{
/**
* Evaluates this predicate on the given argument.
*
* @param t
* the argument
* @return true
if the input argument matches the predicate, otherwise false
* @throws FunctionException
* if a checked exception occurs
*/
@Override
default boolean test( final T t )
{
try {
return this.throwingTest( t );
} catch ( final RuntimeException e ) {
throw e;
} catch ( final Throwable e ) {
throw new FunctionException( e );
}
}
/**
* Evaluates this predicate on the given argument.
*
* @param t
* the argument
* @return true
if the input argument matches the predicate, otherwise false
* @throws Throwable
* any exception
*/
public boolean throwingTest( T t )
throws Throwable;
}