From ec2c870f7b33c76b4b476740fcc2606bea59a056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Fri, 11 Sep 2015 13:59:02 +0200 Subject: [PATCH] Initial import Contains POM (probably incomplete) as well as all Throwing versions of java.util.function interfaces + the Runnable interface. --- .gitignore | 13 +++++ pom.xml | 39 +++++++++++++ .../ebenoit/ebul/func/FunctionException.java | 27 +++++++++ .../ebenoit/ebul/func/ThrowingBiConsumer.java | 56 ++++++++++++++++++ .../ebenoit/ebul/func/ThrowingBiFunction.java | 57 +++++++++++++++++++ .../ebul/func/ThrowingBiPredicate.java | 57 +++++++++++++++++++ .../ebul/func/ThrowingBinaryOperator.java | 55 ++++++++++++++++++ .../ebul/func/ThrowingBooleanSupplier.java | 49 ++++++++++++++++ .../ebenoit/ebul/func/ThrowingConsumer.java | 52 +++++++++++++++++ .../func/ThrowingDoubleBinaryOperator.java | 57 +++++++++++++++++++ .../ebul/func/ThrowingDoubleConsumer.java | 51 +++++++++++++++++ .../ebul/func/ThrowingDoubleFunction.java | 53 +++++++++++++++++ .../ebul/func/ThrowingDoublePredicate.java | 53 +++++++++++++++++ .../ebul/func/ThrowingDoubleSupplier.java | 49 ++++++++++++++++ .../func/ThrowingDoubleToIntFunction.java | 53 +++++++++++++++++ .../func/ThrowingDoubleToLongFunction.java | 53 +++++++++++++++++ .../func/ThrowingDoubleUnaryOperator.java | 53 +++++++++++++++++ .../ebenoit/ebul/func/ThrowingFunction.java | 53 +++++++++++++++++ .../ebul/func/ThrowingIntBinaryOperator.java | 57 +++++++++++++++++++ .../ebul/func/ThrowingIntConsumer.java | 51 +++++++++++++++++ .../ebul/func/ThrowingIntFunction.java | 53 +++++++++++++++++ .../ebul/func/ThrowingIntPredicate.java | 53 +++++++++++++++++ .../ebul/func/ThrowingIntSupplier.java | 49 ++++++++++++++++ .../func/ThrowingIntToDoubleFunction.java | 53 +++++++++++++++++ .../ebul/func/ThrowingIntToLongFunction.java | 53 +++++++++++++++++ .../ebul/func/ThrowingIntUnaryOperator.java | 53 +++++++++++++++++ .../ebul/func/ThrowingLongBinaryOperator.java | 57 +++++++++++++++++++ .../ebul/func/ThrowingLongConsumer.java | 51 +++++++++++++++++ .../ebul/func/ThrowingLongFunction.java | 53 +++++++++++++++++ .../ebul/func/ThrowingLongPredicate.java | 53 +++++++++++++++++ .../ebul/func/ThrowingLongSupplier.java | 49 ++++++++++++++++ .../func/ThrowingLongToDoubleFunction.java | 53 +++++++++++++++++ .../ebul/func/ThrowingLongToIntFunction.java | 53 +++++++++++++++++ .../ebul/func/ThrowingLongUnaryOperator.java | 53 +++++++++++++++++ .../ebul/func/ThrowingObjDoubleConsumer.java | 56 ++++++++++++++++++ .../ebul/func/ThrowingObjIntConsumer.java | 56 ++++++++++++++++++ .../ebul/func/ThrowingObjLongConsumer.java | 56 ++++++++++++++++++ .../ebenoit/ebul/func/ThrowingPredicate.java | 53 +++++++++++++++++ .../ebenoit/ebul/func/ThrowingRunnable.java | 42 ++++++++++++++ .../ebenoit/ebul/func/ThrowingSupplier.java | 49 ++++++++++++++++ .../ebul/func/ThrowingToDoubleBiFunction.java | 57 +++++++++++++++++++ .../ebul/func/ThrowingToDoubleFunction.java | 53 +++++++++++++++++ .../ebul/func/ThrowingToIntBiFunction.java | 57 +++++++++++++++++++ .../ebul/func/ThrowingToIntFunction.java | 53 +++++++++++++++++ .../ebul/func/ThrowingToLongBiFunction.java | 57 +++++++++++++++++++ .../ebul/func/ThrowingToLongFunction.java | 53 +++++++++++++++++ .../ebul/func/ThrowingUnaryOperator.java | 53 +++++++++++++++++ .../info/ebenoit/ebul/func/package-info.java | 8 +++ 48 files changed, 2427 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/info/ebenoit/ebul/func/FunctionException.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingBiConsumer.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingBiFunction.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingBiPredicate.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingBinaryOperator.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingBooleanSupplier.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingConsumer.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingDoubleBinaryOperator.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingDoubleConsumer.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingDoubleFunction.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingDoublePredicate.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingDoubleSupplier.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingDoubleToIntFunction.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingDoubleToLongFunction.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingDoubleUnaryOperator.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingFunction.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingIntBinaryOperator.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingIntConsumer.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingIntFunction.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingIntPredicate.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingIntSupplier.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingIntToDoubleFunction.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingIntToLongFunction.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingIntUnaryOperator.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingLongBinaryOperator.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingLongConsumer.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingLongFunction.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingLongPredicate.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingLongSupplier.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingLongToDoubleFunction.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingLongToIntFunction.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingLongUnaryOperator.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingObjDoubleConsumer.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingObjIntConsumer.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingObjLongConsumer.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingPredicate.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingRunnable.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingSupplier.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingToDoubleBiFunction.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingToDoubleFunction.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingToIntBiFunction.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingToIntFunction.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingToLongBiFunction.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingToLongFunction.java create mode 100644 src/main/java/info/ebenoit/ebul/func/ThrowingUnaryOperator.java create mode 100644 src/main/java/info/ebenoit/ebul/func/package-info.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..18f4cd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +/.metadata/* + +/**/.classpath +/**/.project +/**/.settings/ + +/**/log/ +/**/target/ +/**/*.log + +/**/.attach_pid* + +/**/pom.xml.versionsBackup diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e0c2356 --- /dev/null +++ b/pom.xml @@ -0,0 +1,39 @@ + + 4.0.0 + + info.ebenoit + ebul-func + 0.0.1-SNAPSHOT + E.B.'s utility libraries - Functional interfaces + Various utilities related to Java 8's functional interfaces. This includes interfaces for functions that can throw exceptions. + + + GNU Lesser General Public License, version 3.0 + http://www.gnu.org/licenses/lgpl-3.0.en.html + repo + + + + Emmanuel Benoît + http://www.ebenoit.info + + + + UTF-8 + + + + + + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + + + + + + diff --git a/src/main/java/info/ebenoit/ebul/func/FunctionException.java b/src/main/java/info/ebenoit/ebul/func/FunctionException.java new file mode 100644 index 0000000..ea79114 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/FunctionException.java @@ -0,0 +1,27 @@ +package info.ebenoit.ebul.func; + + +/** + * Runtime exception thrown by Throwing* functional interfaces. Carries the cause of the problem. + * + * @author E. Benoît + */ +public class FunctionException + extends RuntimeException +{ + + private static final long serialVersionUID = -2690556374343638022L; + + + /** + * Initialises the exception from a cause + * + * @param cause + * the exception that happened while the function was being executed. + */ + public FunctionException( final Throwable cause ) + { + super( "checked exception in function" , cause ); + } + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingBiConsumer.java b/src/main/java/info/ebenoit/ebul/func/ThrowingBiConsumer.java new file mode 100644 index 0000000..a49da48 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingBiConsumer.java @@ -0,0 +1,56 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.BiConsumer; + + + +/** + * This interface supports a {@link BiConsumer} that can throw checked exceptions. Checked exceptions are then + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingBiConsumer< T , U > + extends BiConsumer< T , U > +{ + + /** + * 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 U 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 , U u ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingBiFunction.java b/src/main/java/info/ebenoit/ebul/func/ThrowingBiFunction.java new file mode 100644 index 0000000..0257d95 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingBiFunction.java @@ -0,0 +1,57 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.BiFunction; + + + +/** + * This interface supports a {@link BiFunction} that can throw checked exceptions. Checked exceptions are transmitted + * using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingBiFunction< T , U , R > + extends BiFunction< T , U , R > +{ + + /** + * 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 R apply( final T t , final U u ) + { + try { + return this.throwingApply( 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 R throwingApply( T t , U u ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingBiPredicate.java b/src/main/java/info/ebenoit/ebul/func/ThrowingBiPredicate.java new file mode 100644 index 0000000..7ec0bae --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingBiPredicate.java @@ -0,0 +1,57 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.BiPredicate; + + + +/** + * This interface supports a {@link BiPredicate} that can throw checked exceptions. Checked exceptions are transmitted + * using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingBiPredicate< T , U > + extends BiPredicate< T , U > +{ + + /** + * Evaluates this predicate on the given arguments. + * + * @param t + * the first input argument + * @param u + * the second input argument + * @return true if the input arguments match the predicate, otherwise false + * @throws FunctionException + * if a checked exception occurred during evaluation + */ + @Override + default boolean test( final T t , final U u ) + { + try { + return this.throwingTest( t , u ); + } catch ( final RuntimeException e ) { + throw e; + } catch ( final Throwable e ) { + throw new FunctionException( e ); + } + } + + + /** + * Evaluates this predicate on the given arguments. + * + * @param t + * the first input argument + * @param u + * the second input argument + * @return true if the input arguments match the predicate, otherwise false + * @throws Throwable + * any checked exception + */ + public boolean throwingTest( T t , U u ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingBinaryOperator.java b/src/main/java/info/ebenoit/ebul/func/ThrowingBinaryOperator.java new file mode 100644 index 0000000..4232902 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingBinaryOperator.java @@ -0,0 +1,55 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.BinaryOperator; + + + +/** + * This interface supports a {@link BinaryOperator} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingBinaryOperator< T > + extends BinaryOperator< T > +{ + /** + * 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 T apply( final T t , final T u ) + { + try { + return this.throwingApply( 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 T throwingApply( T t , T u ) + throws Throwable; +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingBooleanSupplier.java b/src/main/java/info/ebenoit/ebul/func/ThrowingBooleanSupplier.java new file mode 100644 index 0000000..12a6381 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingBooleanSupplier.java @@ -0,0 +1,49 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.BooleanSupplier; + + + +/** + * This interface supports a {@link BooleanSupplier} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingBooleanSupplier + extends BooleanSupplier +{ + + /** + * Gets a result + * + * @return a result + * @throws FunctionException + * if a checked exception occurred + */ + @Override + default boolean getAsBoolean( ) + { + try { + return this.throwingGetAsBoolean( ); + } catch ( final RuntimeException e ) { + throw e; + } catch ( final Throwable e ) { + throw new FunctionException( e ); + } + } + + + /** + * Gets a result + * + * @return a result + * @throws Throwable + * any exception + */ + public boolean throwingGetAsBoolean( ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingConsumer.java b/src/main/java/info/ebenoit/ebul/func/ThrowingConsumer.java new file mode 100644 index 0000000..3b4a5ba --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingConsumer.java @@ -0,0 +1,52 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.Consumer; + + + +/** + * This interface supports a {@link Consumer} that can throw checked exceptions. Checked exceptions are transmitted + * using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingConsumer< T > + extends Consumer< T > +{ + + /** + * Performs the operation on the given argument, or throws a {@link FunctionException} if a checked exception + * occurs. + * + * @param t + * the input argument + * @throws FunctionException + * if any exception occurs during the function's execution + */ + @Override + default void accept( final T 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, or throws an exception. + * + * @param t + * the input argument + * @throws Throwable + * any exception + */ + public void throwingAccept( T t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleBinaryOperator.java b/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleBinaryOperator.java new file mode 100644 index 0000000..f0f3ebe --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleBinaryOperator.java @@ -0,0 +1,57 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.DoubleBinaryOperator; + + + +/** + * This interface supports a {@link DoubleBinaryOperator} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingDoubleBinaryOperator + extends DoubleBinaryOperator +{ + + /** + * 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 double applyAsDouble( final double t , final double u ) + { + try { + return this.throwingApplyAsDouble( 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 double throwingApplyAsDouble( double t , double u ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleConsumer.java b/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleConsumer.java new file mode 100644 index 0000000..4a78ee7 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleConsumer.java @@ -0,0 +1,51 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.DoubleConsumer; + + + +/** + * This interface supports a {@link DoubleConsumer} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingDoubleConsumer + extends DoubleConsumer +{ + + /** + * 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 double 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( double t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleFunction.java b/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleFunction.java new file mode 100644 index 0000000..59e5be1 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleFunction.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.DoubleFunction; + + + +/** + * This interface supports a {@link DoubleFunction} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingDoubleFunction< R > + extends DoubleFunction< 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 double 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( double t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingDoublePredicate.java b/src/main/java/info/ebenoit/ebul/func/ThrowingDoublePredicate.java new file mode 100644 index 0000000..c271026 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingDoublePredicate.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.DoublePredicate; + + + +/** + * This interface supports a {@link DoublePredicate} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingDoublePredicate + extends DoublePredicate +{ + + /** + * Evaluates this predicate on the given argument. + * + * @param t + * the argument + * @return true if the input argument matches the predicate, otherwise false + * @throws FunctionException + * if a checked exception occurs + */ + @Override + default boolean test( final double 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 true if the input argument matches the predicate, otherwise false + * @throws Throwable + * any exception + */ + public boolean throwingTest( double t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleSupplier.java b/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleSupplier.java new file mode 100644 index 0000000..9e7c72e --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleSupplier.java @@ -0,0 +1,49 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.DoubleSupplier; + + + +/** + * This interface supports a {@link DoubleSupplier} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingDoubleSupplier + extends DoubleSupplier +{ + + /** + * 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 double getAsDouble( ) + { + try { + return this.throwingGetAsDouble( ); + } 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 double throwingGetAsDouble( ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleToIntFunction.java b/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleToIntFunction.java new file mode 100644 index 0000000..5c28af1 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleToIntFunction.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.DoubleToIntFunction; + + + +/** + * This interface supports a {@link DoubleToIntFunction} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingDoubleToIntFunction + extends DoubleToIntFunction +{ + + /** + * 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 double 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( double t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleToLongFunction.java b/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleToLongFunction.java new file mode 100644 index 0000000..21f4231 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleToLongFunction.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.DoubleToLongFunction; + + + +/** + * This interface supports a {@link DoubleToLongFunction} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingDoubleToLongFunction + extends DoubleToLongFunction +{ + + /** + * 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 double 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( double t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleUnaryOperator.java b/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleUnaryOperator.java new file mode 100644 index 0000000..62b94df --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingDoubleUnaryOperator.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.DoubleUnaryOperator; + + + +/** + * This interface supports a {@link DoubleUnaryOperator} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingDoubleUnaryOperator + extends DoubleUnaryOperator +{ + + /** + * Applies this function to the given argument. + * + * @param t + * the first argument + * @return the result + * @throws FunctionException + * if a checked exception occurs + */ + @Override + default double applyAsDouble( final double 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 first argument + * @return the result + * @throws Throwable + * any exception + */ + public double throwingApplyAsDouble( double t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingFunction.java b/src/main/java/info/ebenoit/ebul/func/ThrowingFunction.java new file mode 100644 index 0000000..d0a0c2f --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingFunction.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.Function; + + + +/** + * This interface supports a {@link Function} that can throw checked exceptions. Checked exceptions are transmitted + * using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingFunction< T , R > + extends Function< T , 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 T 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( T t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingIntBinaryOperator.java b/src/main/java/info/ebenoit/ebul/func/ThrowingIntBinaryOperator.java new file mode 100644 index 0000000..6ca0fa9 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingIntBinaryOperator.java @@ -0,0 +1,57 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.IntBinaryOperator; + + + +/** + * This interface supports a {@link IntBinaryOperator} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingIntBinaryOperator + extends IntBinaryOperator +{ + + /** + * 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 int applyAsInt( final int t , final int u ) + { + try { + return this.throwingApplyAsInt( 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 int throwingApplyAsInt( int t , int u ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingIntConsumer.java b/src/main/java/info/ebenoit/ebul/func/ThrowingIntConsumer.java new file mode 100644 index 0000000..d48e684 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingIntConsumer.java @@ -0,0 +1,51 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.IntConsumer; + + + +/** + * This interface supports a {@link IntConsumer} that can throw checked exceptions. Checked exceptions are transmitted + * using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingIntConsumer + extends IntConsumer +{ + + /** + * 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 int 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( int t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingIntFunction.java b/src/main/java/info/ebenoit/ebul/func/ThrowingIntFunction.java new file mode 100644 index 0000000..1c685f4 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingIntFunction.java @@ -0,0 +1,53 @@ +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 E. Benoît + */ +@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; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingIntPredicate.java b/src/main/java/info/ebenoit/ebul/func/ThrowingIntPredicate.java new file mode 100644 index 0000000..e08ed98 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingIntPredicate.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.IntPredicate; + + + +/** + * This interface supports a {@link IntPredicate} that can throw checked exceptions. Checked exceptions are transmitted + * using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingIntPredicate + extends IntPredicate +{ + + /** + * Evaluates this predicate on the given argument. + * + * @param t + * the argument + * @return true if the input argument matches the predicate, otherwise false + * @throws FunctionException + * if a checked exception occurs + */ + @Override + default boolean test( final int 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 true if the input argument matches the predicate, otherwise false + * @throws Throwable + * any exception + */ + public boolean throwingTest( int t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingIntSupplier.java b/src/main/java/info/ebenoit/ebul/func/ThrowingIntSupplier.java new file mode 100644 index 0000000..e535512 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingIntSupplier.java @@ -0,0 +1,49 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.IntSupplier; + + + +/** + * This interface supports a {@link IntSupplier} that can throw checked exceptions. Checked exceptions are transmitted + * using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingIntSupplier + extends IntSupplier +{ + + /** + * 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 int getAsInt( ) + { + try { + return this.throwingGetAsInt( ); + } 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 int throwingGetAsInt( ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingIntToDoubleFunction.java b/src/main/java/info/ebenoit/ebul/func/ThrowingIntToDoubleFunction.java new file mode 100644 index 0000000..e2b23bc --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingIntToDoubleFunction.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.IntToDoubleFunction; + + + +/** + * This interface supports a {@link IntToDoubleFunction} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingIntToDoubleFunction + extends IntToDoubleFunction +{ + + /** + * 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 int 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( int t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingIntToLongFunction.java b/src/main/java/info/ebenoit/ebul/func/ThrowingIntToLongFunction.java new file mode 100644 index 0000000..be08657 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingIntToLongFunction.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.IntToLongFunction; + + + +/** + * This interface supports a {@link IntToLongFunction} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingIntToLongFunction + extends IntToLongFunction +{ + + /** + * 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 int 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( int t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingIntUnaryOperator.java b/src/main/java/info/ebenoit/ebul/func/ThrowingIntUnaryOperator.java new file mode 100644 index 0000000..7526564 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingIntUnaryOperator.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.IntUnaryOperator; + + + +/** + * This interface supports a {@link IntUnaryOperator} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingIntUnaryOperator + extends IntUnaryOperator +{ + + /** + * Applies this function to the given argument. + * + * @param t + * the first argument + * @return the result + * @throws FunctionException + * if a checked exception occurs + */ + @Override + default int applyAsInt( final int 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 first argument + * @return the result + * @throws Throwable + * any exception + */ + public int throwingApplyAsInt( int t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingLongBinaryOperator.java b/src/main/java/info/ebenoit/ebul/func/ThrowingLongBinaryOperator.java new file mode 100644 index 0000000..77ba432 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingLongBinaryOperator.java @@ -0,0 +1,57 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.LongBinaryOperator; + + + +/** + * This interface supports a {@link LongBinaryOperator} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingLongBinaryOperator + extends LongBinaryOperator +{ + + /** + * 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 long applyAsLong( final long t , final long u ) + { + try { + return this.throwingApplyAsLong( 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 long throwingApplyAsLong( long t , long u ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingLongConsumer.java b/src/main/java/info/ebenoit/ebul/func/ThrowingLongConsumer.java new file mode 100644 index 0000000..5c6aaf9 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingLongConsumer.java @@ -0,0 +1,51 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.LongConsumer; + + + +/** + * This interface supports a {@link LongConsumer} that can throw checked exceptions. Checked exceptions are transmitted + * using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingLongConsumer + extends LongConsumer +{ + + /** + * 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 long 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( long t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingLongFunction.java b/src/main/java/info/ebenoit/ebul/func/ThrowingLongFunction.java new file mode 100644 index 0000000..a0d6f71 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingLongFunction.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.LongFunction; + + + +/** + * This interface supports a {@link LongFunction} that can throw checked exceptions. Checked exceptions are transmitted + * using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingLongFunction< R > + extends LongFunction< 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 long 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( long t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingLongPredicate.java b/src/main/java/info/ebenoit/ebul/func/ThrowingLongPredicate.java new file mode 100644 index 0000000..c9718b3 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingLongPredicate.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.LongPredicate; + + + +/** + * This interface supports a {@link LongPredicate} that can throw checked exceptions. Checked exceptions are transmitted + * using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingLongPredicate + extends LongPredicate +{ + + /** + * Evaluates this predicate on the given argument. + * + * @param t + * the argument + * @return true if the input argument matches the predicate, otherwise false + * @throws FunctionException + * if a checked exception occurs + */ + @Override + default boolean test( final long 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 true if the input argument matches the predicate, otherwise false + * @throws Throwable + * any exception + */ + public boolean throwingTest( long t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingLongSupplier.java b/src/main/java/info/ebenoit/ebul/func/ThrowingLongSupplier.java new file mode 100644 index 0000000..fdb37ca --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingLongSupplier.java @@ -0,0 +1,49 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.LongSupplier; + + + +/** + * This interface supports a {@link LongSupplier} that can throw checked exceptions. Checked exceptions are transmitted + * using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingLongSupplier + extends LongSupplier +{ + + /** + * 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 long getAsLong( ) + { + try { + return this.throwingGetAsLong( ); + } 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 long throwingGetAsLong( ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingLongToDoubleFunction.java b/src/main/java/info/ebenoit/ebul/func/ThrowingLongToDoubleFunction.java new file mode 100644 index 0000000..c7ce6cc --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingLongToDoubleFunction.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.LongToDoubleFunction; + + + +/** + * This interface supports a {@link LongToDoubleFunction} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingLongToDoubleFunction + extends LongToDoubleFunction +{ + + /** + * 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 long 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( long t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingLongToIntFunction.java b/src/main/java/info/ebenoit/ebul/func/ThrowingLongToIntFunction.java new file mode 100644 index 0000000..55208b7 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingLongToIntFunction.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.LongToIntFunction; + + + +/** + * This interface supports a {@link LongToIntFunction} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingLongToIntFunction + extends LongToIntFunction +{ + + /** + * 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 long 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( long t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingLongUnaryOperator.java b/src/main/java/info/ebenoit/ebul/func/ThrowingLongUnaryOperator.java new file mode 100644 index 0000000..70f67d8 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingLongUnaryOperator.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.LongUnaryOperator; + + + +/** + * This interface supports a {@link LongUnaryOperator} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingLongUnaryOperator + extends LongUnaryOperator +{ + + /** + * Applies this function to the given argument. + * + * @param t + * the first argument + * @return the result + * @throws FunctionException + * if a checked exception occurs + */ + @Override + default long applyAsLong( final long 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 first argument + * @return the result + * @throws Throwable + * any exception + */ + public long throwingApplyAsLong( long t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingObjDoubleConsumer.java b/src/main/java/info/ebenoit/ebul/func/ThrowingObjDoubleConsumer.java new file mode 100644 index 0000000..8ed28f5 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingObjDoubleConsumer.java @@ -0,0 +1,56 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.ObjDoubleConsumer; + + + +/** + * This interface supports a {@link ObjDoubleConsumer} that can throw checked exceptions. Checked exceptions are then + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingObjDoubleConsumer< T > + extends ObjDoubleConsumer< 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 double 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 , double u ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingObjIntConsumer.java b/src/main/java/info/ebenoit/ebul/func/ThrowingObjIntConsumer.java new file mode 100644 index 0000000..4909b52 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingObjIntConsumer.java @@ -0,0 +1,56 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.ObjIntConsumer; + + + +/** + * This interface supports a {@link ObjIntConsumer} that can throw checked exceptions. Checked exceptions are then + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingObjIntConsumer< T > + extends ObjIntConsumer< 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 int 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 , int u ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingObjLongConsumer.java b/src/main/java/info/ebenoit/ebul/func/ThrowingObjLongConsumer.java new file mode 100644 index 0000000..00fa7ac --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingObjLongConsumer.java @@ -0,0 +1,56 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.ObjLongConsumer; + + + +/** + * This interface supports a {@link ObjLongConsumer} that can throw checked exceptions. Checked exceptions are then + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingObjLongConsumer< T > + extends ObjLongConsumer< 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 long 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 , long u ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingPredicate.java b/src/main/java/info/ebenoit/ebul/func/ThrowingPredicate.java new file mode 100644 index 0000000..d8d548c --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingPredicate.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.Predicate; + + + +/** + * This interface supports a {@link Predicate} that can throw checked exceptions. Checked exceptions are transmitted + * using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingPredicate< T > + extends Predicate< T > +{ + + /** + * Evaluates this predicate on the given argument. + * + * @param t + * the argument + * @return true if the input argument matches the predicate, otherwise false + * @throws FunctionException + * if a checked exception occurs + */ + @Override + default boolean test( final T 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 true if the input argument matches the predicate, otherwise false + * @throws Throwable + * any exception + */ + public boolean throwingTest( T t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingRunnable.java b/src/main/java/info/ebenoit/ebul/func/ThrowingRunnable.java new file mode 100644 index 0000000..d84cc90 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingRunnable.java @@ -0,0 +1,42 @@ +package info.ebenoit.ebul.func; + + +/** + * This interface supports a {@link Runnable} that can throw checked exceptions. Checked exceptions are transmitted + * using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingRunnable + extends Runnable +{ + + /** + * Executes the procedure + * + * @throws FunctionException + * if a checked exception occurs + */ + @Override + default void run( ) + { + try { + this.throwingRun( ); + } catch ( final RuntimeException e ) { + throw e; + } catch ( final Throwable e ) { + throw new FunctionException( e ); + } + } + + + /** + * Executes the procedure, may throw any exception + * + * @throws Throwable + * any exception + */ + public void throwingRun( ) + throws Throwable; +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingSupplier.java b/src/main/java/info/ebenoit/ebul/func/ThrowingSupplier.java new file mode 100644 index 0000000..e91e310 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingSupplier.java @@ -0,0 +1,49 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.Supplier; + + + +/** + * This interface supports a {@link Supplier} that can throw checked exceptions. Checked exceptions are transmitted + * using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingSupplier< T > + extends Supplier< T > +{ + + /** + * 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 T get( ) + { + try { + return this.throwingGet( ); + } 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 T throwingGet( ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingToDoubleBiFunction.java b/src/main/java/info/ebenoit/ebul/func/ThrowingToDoubleBiFunction.java new file mode 100644 index 0000000..360446c --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingToDoubleBiFunction.java @@ -0,0 +1,57 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.ToDoubleBiFunction; + + + +/** + * This interface supports a {@link ToDoubleBiFunction} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingToDoubleBiFunction< T , U > + extends ToDoubleBiFunction< 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 double applyAsDouble( final T t , final U u ) + { + try { + return this.throwingApplyAsDouble( 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 double throwingApplyAsDouble( T t , U u ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingToDoubleFunction.java b/src/main/java/info/ebenoit/ebul/func/ThrowingToDoubleFunction.java new file mode 100644 index 0000000..bec2de8 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingToDoubleFunction.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.ToDoubleFunction; + + + +/** + * This interface supports a {@link ToDoubleFunction} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingToDoubleFunction< T > + extends ToDoubleFunction< T > +{ + + /** + * 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 T 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 + * any exception + */ + public double throwingApplyAsDouble( T t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingToIntBiFunction.java b/src/main/java/info/ebenoit/ebul/func/ThrowingToIntBiFunction.java new file mode 100644 index 0000000..b79f94f --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingToIntBiFunction.java @@ -0,0 +1,57 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.ToIntBiFunction; + + + +/** + * This interface supports a {@link ToIntBiFunction} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingToIntBiFunction< T , U > + extends ToIntBiFunction< 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 int applyAsInt( final T t , final U u ) + { + try { + return this.throwingApplyAsInt( 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 int throwingApplyAsInt( T t , U u ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingToIntFunction.java b/src/main/java/info/ebenoit/ebul/func/ThrowingToIntFunction.java new file mode 100644 index 0000000..a2b9c4c --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingToIntFunction.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.ToIntFunction; + + + +/** + * This interface supports a {@link ToIntFunction} that can throw checked exceptions. Checked exceptions are transmitted + * using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingToIntFunction< T > + extends ToIntFunction< T > +{ + + /** + * 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 T 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 + * any exception + */ + public int throwingApplyAsInt( T t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingToLongBiFunction.java b/src/main/java/info/ebenoit/ebul/func/ThrowingToLongBiFunction.java new file mode 100644 index 0000000..d692d29 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingToLongBiFunction.java @@ -0,0 +1,57 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.ToLongBiFunction; + + + +/** + * This interface supports a {@link ToLongBiFunction} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingToLongBiFunction< T , U > + extends ToLongBiFunction< 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 long applyAsLong( final T t , final U u ) + { + try { + return this.throwingApplyAsLong( 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 long throwingApplyAsLong( T t , U u ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingToLongFunction.java b/src/main/java/info/ebenoit/ebul/func/ThrowingToLongFunction.java new file mode 100644 index 0000000..f671c63 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingToLongFunction.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.ToLongFunction; + + + +/** + * This interface supports a {@link ToLongFunction} that can throw checked exceptions. Checked exceptions are + * transmitted using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingToLongFunction< T > + extends ToLongFunction< T > +{ + + /** + * 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 T 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 + * any exception + */ + public long throwingApplyAsLong( T t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/ThrowingUnaryOperator.java b/src/main/java/info/ebenoit/ebul/func/ThrowingUnaryOperator.java new file mode 100644 index 0000000..4034a30 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/ThrowingUnaryOperator.java @@ -0,0 +1,53 @@ +package info.ebenoit.ebul.func; + + +import java.util.function.UnaryOperator; + + + +/** + * This interface supports a {@link UnaryOperator} that can throw checked exceptions. Checked exceptions are transmitted + * using a {@link FunctionException} runtime exception. + * + * @author E. Benoît + */ +@FunctionalInterface +public interface ThrowingUnaryOperator< T > + extends UnaryOperator< T > +{ + + /** + * Applies this function to the given argument. + * + * @param t + * the argument + * @return the result + * @throws FunctionException + * if a checked exception occurs + */ + @Override + default T apply( final T 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 T throwingApply( T t ) + throws Throwable; + +} diff --git a/src/main/java/info/ebenoit/ebul/func/package-info.java b/src/main/java/info/ebenoit/ebul/func/package-info.java new file mode 100644 index 0000000..6451708 --- /dev/null +++ b/src/main/java/info/ebenoit/ebul/func/package-info.java @@ -0,0 +1,8 @@ +/** + * This package contains various utilities to be used along with {@link java.util.function}. This includes support for + * the float primitive type as well as versions of all interfaces capable of rethrowing checked exceptions as runtime + * exceptions. + * + * @author E. Benoît + */ +package info.ebenoit.ebul.func; \ No newline at end of file