ebul-func/src/main/java/info/ebenoit/ebul/func/ThrowingIntFunction.java

54 lines
1.1 KiB
Java
Raw Normal View History

package info.ebenoit.ebul.func;
import java.util.function.IntFunction;
/**
* This interface supports a {@link IntFunction} that can throw checked exceptions. Checked exceptions are transmitted
* using a {@link FunctionException} runtime exception.
*
* @author <a href="mailto:ebenoit@ebenoit.info">E. Benoît</a>
*/
@FunctionalInterface
public interface ThrowingIntFunction< R >
extends IntFunction< R >
{
/**
* Applies this function to the given argument.
*
* @param t
* the argument
* @return the result
* @throws FunctionException
* if a checked exception occurs
*/
@Override
default R apply( final int t )
{
try {
return this.throwingApply( t );
} catch ( final RuntimeException e ) {
throw e;
} catch ( final Throwable e ) {
throw new FunctionException( e );
}
}
/**
* Applies this function to the given argument.
*
* @param t
* the argument
* @return the result
* @throws Throwable
* any exception
*/
public R throwingApply( int t )
throws Throwable;
}