All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.markozajc.ef.predicate.except.EPredicate Maven / Gradle / Ivy

package com.github.markozajc.ef.predicate.except;

import static com.github.markozajc.ef.Utilities.asUnchecked;

import java.util.function.Predicate;

/**
 * Variant of {@link Predicate} capable of throwing a generic {@link Throwable}.
 *
 * @author Marko Zajc
 *
 * @param 
 *            the type of the input to the predicate
 * @param 
 *            {@link Throwable} type
 */
@FunctionalInterface
public interface EPredicate extends Predicate {

	@Override
	default boolean test(T t) {
		try {
			return testChecked(t);
		} catch (Throwable e) { // NOSONAR can't catch generic exceptions
			throw asUnchecked(e);
		}
	}

	/**
	 * Same as {@link #test(Object)}, but throws a checked exception.
	 *
	 * @param t
	 *            the input argument
	 *
	 * @return {@code true} if the input argument matches the predicate, otherwise
	 *         {@code false}
	 *
	 * @throws E
	 *             the defined exception type
	 */
	boolean testChecked(T t) throws E;

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy