com.github.markozajc.ef.predicate.except.EBytePredicate Maven / Gradle / Ivy
package com.github.markozajc.ef.predicate.except;
import static com.github.markozajc.ef.Utilities.asUnchecked;
import com.github.markozajc.ef.predicate.BytePredicate;
/**
* Variant of {@link BytePredicate} capable of throwing a generic {@link Throwable}.
*
* @author Marko Zajc
*
* @param
* {@link Throwable} type
*/
@FunctionalInterface
public interface EBytePredicate extends BytePredicate {
@Override
default boolean test(byte p) {
try {
return testChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
}
/**
* Same as {@link #test(byte)}, but throws a checked exception.
*
* @param p
* the input argument
*
* @return {@code true} if the input argument matches the predicate, otherwise
* {@code false}
*
* @throws E
* the defined exception type
*/
boolean testChecked(byte p) throws E;
}