com.github.markozajc.ef.predicate.except.EShortPredicate Maven / Gradle / Ivy
package com.github.markozajc.ef.predicate.except;
import static com.github.markozajc.ef.Utilities.asUnchecked;
import com.github.markozajc.ef.predicate.ShortPredicate;
/**
* Variant of {@link ShortPredicate} capable of throwing a generic {@link Throwable}.
*
* @author Marko Zajc
*
* @param
* {@link Throwable} type
*/
@FunctionalInterface
public interface EShortPredicate extends ShortPredicate {
@Override
default boolean test(short p) {
try {
return testChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
}
/**
* Same as {@link #test(short)}, 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(short p) throws E;
}