Skip to content

Commit

Permalink
Formatting and naming cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
esocode committed Dec 29, 2023
1 parent df6b4a2 commit 7367c2b
Show file tree
Hide file tree
Showing 91 changed files with 1,342 additions and 1,546 deletions.
14 changes: 3 additions & 11 deletions src/main/java/de/esoco/lib/expression/FunctionException.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package de.esoco.lib.expression;

/********************************************************************
/**
* A special runtime exception subclass for function errors. As functions are
* not allowed to throw checked exceptions this class provides a way to throw
* exceptions from functions. It is intended to be used always as a wrapper
Expand All @@ -30,17 +30,11 @@
*/
public class FunctionException extends RuntimeException {

//~ Static fields/initializers ---------------------------------------------

private static final long serialVersionUID = 1L;

//~ Instance fields --------------------------------------------------------

private final Object fCausingFunction;

//~ Constructors -----------------------------------------------------------

/***************************************
/**
* Creates a new instance. The function argument is of type object so that
* it can contain the different function types of Java 8.
*
Expand All @@ -54,9 +48,7 @@ public FunctionException(Object fCausingFunction, Throwable eCause) {
this.fCausingFunction = fCausingFunction;
}

//~ Methods ----------------------------------------------------------------

/***************************************
/**
* Returns the function instance that caused this exception.
*
* @return The causing function
Expand Down
43 changes: 18 additions & 25 deletions src/main/java/de/esoco/lib/expression/ThrowingBinaryFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

import java.util.function.BiFunction;


/********************************************************************
/**
* A sub-interface that allows implementations to throw checked exceptions. If
* an exception occurs it will be converted into a runtime exception of the type
* {@link FunctionException}.
Expand All @@ -29,41 +28,21 @@
@FunctionalInterface
public interface ThrowingBinaryFunction<L, R, O> extends BiFunction<L, R, O> {

//~ Static methods ---------------------------------------------------------

/***************************************
/**
* Factory method that allows to declare a throwing function from a lambda
* expression that is mapped to a regular function. Otherwise an anonymous
* inner class expression would be needed because of the similar signatures
* of throwing and non-throwing functions.
*
* @param fThrowing The throwing function expression
*
* @param fThrowing The throwing function expression
* @return The resulting function
*/
static <L, R, O> BiFunction<L, R, O> of(
ThrowingBinaryFunction<L, R, O> fThrowing) {
return fThrowing;
}

//~ Methods ----------------------------------------------------------------

/***************************************
* The version of {@link #apply(Object, Object)} that allows implementations
* to throw an exception.
*
* @param rLeft The left argument
* @param rRight The right argument
*
* @return The function result
*
* @throws Exception Any kind of exception may be thrown
*/
O tryApply(L rLeft, R rRight) throws Exception;

// ~ Methods ------------------------------------------------------------

/***************************************
/**
* Overridden to forward the invocation to the actual function
* implementation in {@link #tryApply(Object, Object)} and to convert
* occurring exceptions into {@link FunctionException}.
Expand All @@ -80,4 +59,18 @@ default O apply(L rLeft, R rRight) {
throw new FunctionException(this, e);
}
}

// ~ Methods ------------------------------------------------------------

/**
* The version of {@link #apply(Object, Object)} that allows
* implementations
* to throw an exception.
*
* @param rLeft The left argument
* @param rRight The right argument
* @return The function result
* @throws Exception Any kind of exception may be thrown
*/
O tryApply(L rLeft, R rRight) throws Exception;
}
18 changes: 6 additions & 12 deletions src/main/java/de/esoco/lib/expression/ThrowingConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.function.Consumer;
import java.util.function.Supplier;

/********************************************************************
/**
* A {@link Supplier} extension that maps any occurring exception to a runtime
* {@link FunctionException}.
*
Expand All @@ -28,25 +28,20 @@
@FunctionalInterface
public interface ThrowingConsumer<T> extends Consumer<T> {

//~ Static methods ---------------------------------------------------------

/***************************************
/**
* Factory method that allows to declare a throwing consumer from a lambda
* expression that is mapped to a regular consumer. Otherwise an anonymous
* inner class expression would be needed because of the similar signatures
* of throwing and non-throwing consumers.
*
* @param fThrowing The throwing consumer expression
*
* @param fThrowing The throwing consumer expression
* @return The resulting function
*/
static <T> Consumer<T> of(ThrowingConsumer<T> fThrowing) {
return fThrowing;
}

//~ Methods ----------------------------------------------------------------

/***************************************
/**
* Overridden to forward the invocation to the actual function
* implementation in {@link #tryAccept(Object)} and to convert occurring
* exceptions into {@link FunctionException}.
Expand All @@ -64,12 +59,11 @@ default void accept(T rValue) {
}
}

/***************************************
/**
* Replaces {@link #accept(Object)} and allows implementations to throw any
* kind of exception.
*
* @param rValue The value to consume
*
* @param rValue The value to consume
* @throws Exception If the invocation fails
*/
void tryAccept(T rValue) throws Exception;
Expand Down
19 changes: 6 additions & 13 deletions src/main/java/de/esoco/lib/expression/ThrowingFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.function.Function;

/********************************************************************
/**
* A sub-interface that allows implementations to throw checked exceptions. If
* an exception occurs it will be converted into a runtime exception of the type
* {@link FunctionException}.
Expand All @@ -28,25 +28,20 @@
@FunctionalInterface
public interface ThrowingFunction<I, O> extends Function<I, O> {

//~ Static methods ---------------------------------------------------------

/***************************************
/**
* Factory method that allows to declare a throwing function from a lambda
* expression that is mapped to a regular function. Otherwise an anonymous
* inner class expression would be needed because of the similar signatures
* of throwing and non-throwing functions.
*
* @param fThrowing The throwing function expression
*
* @param fThrowing The throwing function expression
* @return The resulting function
*/
static <I, O> Function<I, O> of(ThrowingFunction<I, O> fThrowing) {
return fThrowing;
}

//~ Methods ----------------------------------------------------------------

/***************************************
/**
* Overridden to forward the invocation to the actual function
* implementation in {@link #tryApply(Object)} and to convert occurring
* exceptions into {@link FunctionException}.
Expand All @@ -64,14 +59,12 @@ default O apply(I rInput) {
}
}

/***************************************
/**
* Replaces {@link #apply(Object)} and allows implementations to throw an
* exception.
*
* @param rInput The input value
*
* @param rInput The input value
* @return The function result
*
* @throws Exception An exception in the case of errors
*/
O tryApply(I rInput) throws Exception;
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/de/esoco/lib/expression/ThrowingRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package de.esoco.lib.expression;

/********************************************************************
/**
* A {@link Runnable} extension that maps any occurring exception to a runtime
* {@link FunctionException}.
*
Expand All @@ -25,25 +25,20 @@
@FunctionalInterface
public interface ThrowingRunnable extends Runnable {

//~ Static methods ---------------------------------------------------------

/***************************************
/**
* Factory method that allows to declare a throwing runnable from a lambda
* expression that is mapped to a regular runnable. Otherwise an anonymous
* inner class expression would be needed because of the similar signatures
* of the throwing and non-throwing runnable interfaces
*
* @param fThrowing The throwing runnable expression
*
* @param fThrowing The throwing runnable expression
* @return The resulting function
*/
static Runnable of(ThrowingRunnable fThrowing) {
return fThrowing;
}

//~ Methods ----------------------------------------------------------------

/***************************************
/**
* Overridden to forward the invocation to the actual function
* implementation in {@link #tryRun()} and to convert occurring exceptions
* into {@link FunctionException}.
Expand All @@ -61,7 +56,7 @@ default void run() {
}
}

/***************************************
/**
* An alternative to {@link #run()} that is allowed to throw any kind of
* exception.
*
Expand Down
19 changes: 7 additions & 12 deletions src/main/java/de/esoco/lib/expression/ThrowingSupplier.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.function.Supplier;

/********************************************************************
/**
* A {@link Supplier} extension that maps any occurring exception to a runtime
* {@link FunctionException}.
*
Expand All @@ -27,25 +27,20 @@
@FunctionalInterface
public interface ThrowingSupplier<T> extends Supplier<T> {

//~ Static methods ---------------------------------------------------------

/***************************************
/**
* Factory method that allows to declare a throwing supplier from a lambda
* expression that is mapped to a regular supplier. Otherwise an anonymous
* inner class expression would be needed because of the similar signatures
* of throwing and non-throwing suppliers.
*
* @param fThrowing The throwing supplier expression
*
* @param fThrowing The throwing supplier expression
* @return The resulting function
*/
static <T> Supplier<T> of(ThrowingSupplier<T> fThrowing) {
return fThrowing;
}

//~ Methods ----------------------------------------------------------------

/***************************************
/**
* Overridden to forward the invocation to the actual function
* implementation in {@link #tryGet()} and to convert occurring exceptions
* into {@link FunctionException}.
Expand All @@ -63,11 +58,11 @@ default T get() {
}
}

/***************************************
* Replaces {@link #get()} and allows implementations to throw an exception.
/**
* Replaces {@link #get()} and allows implementations to throw an
* exception.
*
* @return The function result
*
* @throws Exception If the invocation fails
*/
T tryGet() throws Exception;
Expand Down
Loading

0 comments on commit 7367c2b

Please sign in to comment.