Float functions - Throwing* variants

Added variants of the float primitive functions with support for checked
exception.
This commit is contained in:
Emmanuel BENOîT 2015-09-11 15:16:32 +02:00
parent ea2fc5a632
commit 52e685311a
15 changed files with 740 additions and 0 deletions

View file

@ -0,0 +1,49 @@
package info.ebenoit.ebul.func;
/**
* This interface supports a {@link DoubleToFloatFunction} 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 ThrowingDoubleToFloatFunction
extends DoubleToFloatFunction
{
/**
* Applies this function to the given argument.
*
* @param t
* the argument
* @return the result
* @throws FunctionException
* if a checked exception occurs
*/
@Override
default float applyAsFloat( final double t )
{
try {
return this.throwingApplyAsFloat( 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
* if a checked exception occurs
*/
public float throwingApplyAsFloat( double t )
throws Throwable;
}

View file

@ -0,0 +1,53 @@
package info.ebenoit.ebul.func;
/**
* This interface supports a {@link FloatBinaryOperator} 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 ThrowingFloatBinaryOperator
extends FloatBinaryOperator
{
/**
* Applies this function to the given arguments.
*
* @param t
* the first argument
* @param u
* the second argument
* @return the result
* @throws FunctionException
* if a checked exception occurs
*/
@Override
default float applyAsFloat( final float t , final float u )
{
try {
return this.throwingApplyAsFloat( t , u );
} catch ( final RuntimeException e ) {
throw e;
} catch ( final Throwable e ) {
throw new FunctionException( e );
}
}
/**
* Applies this function to the given arguments.
*
* @param t
* the first argument
* @param u
* the second argument
* @return the result
* @throws Throwable
* any exception
*/
public float throwingApplyAsFloat( float t , float u )
throws Throwable;
}

View file

@ -0,0 +1,47 @@
package info.ebenoit.ebul.func;
/**
* This interface supports a {@link FloatConsumer} 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 ThrowingFloatConsumer
extends FloatConsumer
{
/**
* Performs the operation on the given argument.
*
* @param t
* the input argument
* @throws FunctionException
* if a checked exception occurs during the operation's execution
*/
@Override
default void accept( final float t )
{
try {
this.throwingAccept( t );
} catch ( final RuntimeException e ) {
throw e;
} catch ( final Throwable e ) {
throw new FunctionException( e );
}
}
/**
* Performs the operation on the given argument.
*
* @param t
* the input argument
* @throws Throwable
* any exception
*/
public void throwingAccept( float t )
throws Throwable;
}

View file

@ -0,0 +1,49 @@
package info.ebenoit.ebul.func;
/**
* This interface supports a {@link FloatFunction} 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 ThrowingFloatFunction< R >
extends FloatFunction< 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 float 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( float t )
throws Throwable;
}

View file

@ -0,0 +1,49 @@
package info.ebenoit.ebul.func;
/**
* This interface supports a {@link FloatPredicate} 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 ThrowingFloatPredicate
extends FloatPredicate
{
/**
* Evaluates this predicate on the given argument.
*
* @param t
* the argument
* @return <code>true</code> if the input argument matches the predicate, otherwise <code>false</code>
* @throws FunctionException
* if a checked exception occurs
*/
@Override
default boolean test( final float 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 <code>true</code> if the input argument matches the predicate, otherwise <code>false</code>
* @throws Throwable
* any exception
*/
public boolean throwingTest( float t )
throws Throwable;
}

View file

@ -0,0 +1,45 @@
package info.ebenoit.ebul.func;
/**
* This interface supports a {@link FloatSupplier} 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 ThrowingFloatSupplier
extends FloatSupplier
{
/**
* Gets a result, or throws a {@link FunctionException} if an exception occurs.
*
* @return the result
* @throws FunctionException
* if any exception occurs during the function's execution
*/
@Override
default float getAsFloat( )
{
try {
return this.throwingGetAsFloat( );
} catch ( final RuntimeException e ) {
throw e;
} catch ( final Throwable e ) {
throw new FunctionException( e );
}
}
/**
* Gets a result or throws an exception
*
* @return the result
* @throws Throwable
* any exception
*/
public float throwingGetAsFloat( )
throws Throwable;
}

View file

@ -0,0 +1,49 @@
package info.ebenoit.ebul.func;
/**
* This interface supports a {@link FloatToDoubleFunction} 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 ThrowingFloatToDoubleFunction
extends FloatToDoubleFunction
{
/**
* Applies this function to the given argument.
*
* @param t
* the argument
* @return the result
* @throws FunctionException
* if a checked exception occurs
*/
@Override
default double applyAsDouble( final float t )
{
try {
return this.throwingApplyAsDouble( 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
* if a checked exception occurs
*/
public double throwingApplyAsDouble( float t )
throws Throwable;
}

View file

@ -0,0 +1,49 @@
package info.ebenoit.ebul.func;
/**
* This interface supports a {@link FloatToIntFunction} 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 ThrowingFloatToIntFunction
extends FloatToIntFunction
{
/**
* Applies this function to the given argument.
*
* @param t
* the argument
* @return the result
* @throws FunctionException
* if a checked exception occurs
*/
@Override
default int applyAsInt( final float t )
{
try {
return this.throwingApplyAsInt( 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
* if a checked exception occurs
*/
public int throwingApplyAsInt( float t )
throws Throwable;
}

View file

@ -0,0 +1,49 @@
package info.ebenoit.ebul.func;
/**
* This interface supports a {@link FloatToLongFunction} 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 ThrowingFloatToLongFunction
extends FloatToLongFunction
{
/**
* Applies this function to the given argument.
*
* @param t
* the argument
* @return the result
* @throws FunctionException
* if a checked exception occurs
*/
@Override
default long applyAsLong( final float t )
{
try {
return this.throwingApplyAsLong( 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
* if a checked exception occurs
*/
public long throwingApplyAsLong( float t )
throws Throwable;
}

View file

@ -0,0 +1,49 @@
package info.ebenoit.ebul.func;
/**
* This interface supports a {@link FloatUnaryOperator} 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 ThrowingFloatUnaryOperator
extends FloatUnaryOperator
{
/**
* Applies this function to the given argument.
*
* @param t
* the first argument
* @return the result
* @throws FunctionException
* if a checked exception occurs
*/
@Override
default float applyAsFloat( final float t )
{
try {
return this.throwingApplyAsFloat( 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 first argument
* @return the result
* @throws Throwable
* any exception
*/
public float throwingApplyAsFloat( float t )
throws Throwable;
}

View file

@ -0,0 +1,49 @@
package info.ebenoit.ebul.func;
/**
* This interface supports a {@link IntToFloatFunction} 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 ThrowingIntToFloatFunction
extends IntToFloatFunction
{
/**
* Applies this function to the given argument.
*
* @param t
* the argument
* @return the result
* @throws FunctionException
* if a checked exception occurs
*/
@Override
default float applyAsFloat( final int t )
{
try {
return this.throwingApplyAsFloat( 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
* if a checked exception occurs
*/
public float throwingApplyAsFloat( int t )
throws Throwable;
}

View file

@ -0,0 +1,49 @@
package info.ebenoit.ebul.func;
/**
* This interface supports a {@link LongToFloatFunction} 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 ThrowingLongToFloatFunction
extends LongToFloatFunction
{
/**
* Applies this function to the given argument.
*
* @param t
* the argument
* @return the result
* @throws FunctionException
* if a checked exception occurs
*/
@Override
default float applyAsFloat( final long t )
{
try {
return this.throwingApplyAsFloat( 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
* if a checked exception occurs
*/
public float throwingApplyAsFloat( long t )
throws Throwable;
}

View file

@ -0,0 +1,52 @@
package info.ebenoit.ebul.func;
/**
* This interface supports a {@link ObjFloatConsumer} that can throw checked exceptions. Checked exceptions are then
* transmitted using a {@link FunctionException} runtime exception.
*
* @author <a href="mailto:ebenoit@ebenoit.info">E. Benoît</a>
*/
@FunctionalInterface
public interface ThrowingObjFloatConsumer< T >
extends ObjFloatConsumer< T >
{
/**
* Performs the operation on the given arguments, or throws a {@link FunctionException} if a checked exception
* occurs.
*
* @param t
* the first argument
* @param u
* the second argument
* @throws FunctionException
* if any checked exception occurs during the function's execution
*/
@Override
default void accept( final T t , final float u )
{
try {
this.throwingAccept( t , u );
} catch ( final RuntimeException e ) {
throw e;
} catch ( final Throwable e ) {
throw new FunctionException( e );
}
}
/**
* Performs the operation on the given arguments, or throws an arbitrary exception
*
* @param t
* the first argument
* @param u
* the second argument
* @throws Throwable
* any exception
*/
public void throwingAccept( T t , float u )
throws Throwable;
}

View file

@ -0,0 +1,53 @@
package info.ebenoit.ebul.func;
/**
* This interface supports a {@link ToFloatBiFunction} 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 ThrowingToFloatBiFunction< T , U >
extends ToFloatBiFunction< T , U >
{
/**
* Applies this function to the given arguments.
*
* @param t
* the first argument
* @param u
* the second argument
* @return the result
* @throws FunctionException
* if a checked exception occurs
*/
@Override
default float applyAsFloat( final T t , final U u )
{
try {
return this.throwingApplyAsFloat( t , u );
} catch ( final RuntimeException e ) {
throw e;
} catch ( final Throwable e ) {
throw new FunctionException( e );
}
}
/**
* Applies this function to the given arguments.
*
* @param t
* the first argument
* @param u
* the second argument
* @return the result
* @throws Throwable
* any exception
*/
public float throwingApplyAsFloat( T t , U u )
throws Throwable;
}

View file

@ -0,0 +1,49 @@
package info.ebenoit.ebul.func;
/**
* This interface supports a {@link ToFloatFunction} 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 ThrowingToFloatFunction< T >
extends ToFloatFunction< T >
{
/**
* Applies this function to the given argument.
*
* @param t
* the argument
* @return the result
* @throws FunctionException
* if a checked exception occurs
*/
@Override
default float applyAsFloat( final T t )
{
try {
return this.throwingApplyAsFloat( 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 float throwingApplyAsFloat( T t )
throws Throwable;
}