Skip to content

Commit 728921b

Browse files
committed
javadoc/throwingcallable.
1 parent 9c64d92 commit 728921b

File tree

11 files changed

+84
-2
lines changed

11 files changed

+84
-2
lines changed

mihxil-functional/src/main/java/org/meeuw/functional/Functions.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public static <A, R> Function<A, R> always(R returnValue, String description) {
3535
}
3636

3737
/**
38+
* Provides an implementation of {@link Function} always returning the same value
39+
*
3840
* @param <A> the type of the argument to the function (which will be ignored)
3941
* @param <R> the type of the return value of the function
4042
* @param returnValue the desired value to always return
@@ -60,6 +62,8 @@ public static <A1, A2, R> BiFunction<A1, A2, R> biAlways(R returnValue, String
6062
}
6163

6264
/**
65+
* Provides an implementation of {@link BiFunction} always returning the same value
66+
*
6367
* @param <A1> the type of the first argument to the function (which will be ignored)
6468
* @param <A2> the type of the second argument to the function (which will be ignored)
6569
* @param <R> the type of the return value
@@ -87,6 +91,7 @@ public static <A1, A2, A3, R> TriFunction<A1, A2, A3, R> triAlways(R returnVal
8791
}
8892

8993
/**
94+
* Provides an implementation of {@link TriFunction} always returning the same value
9095
*
9196
* @param <A1> the type of the first argument to the function (which will be ignored)
9297
* @param <A2> the type of the second argument to the function (which will be ignored)
@@ -116,6 +121,8 @@ public static <A1, A2, A3, A4, R> QuadriFunction<A1, A2, A3, A4, R> quadriAlwa
116121
}
117122

118123
/**
124+
* Provides an implementation of {@link QuadriFunction} always returning the same value
125+
*
119126
* @param <A1> the type of the first argument to the function (which will be ignored)
120127
* @param <A2> the type of the second argument to the function (which will be ignored)
121128
* @param <A3> the type of the third argument to the function (which will be ignored)

mihxil-functional/src/main/java/org/meeuw/functional/OptionalBoolean.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,15 @@ public enum OptionalBoolean {
3838
*/
3939
EMPTY,
4040

41+
/**
42+
* Common instance for {@code true}.
43+
*/
4144
TRUE(true),
4245

46+
47+
/**
48+
* Common instance for {@code false}.
49+
*/
4350
FALSE(false);
4451

4552

mihxil-functional/src/main/java/org/meeuw/functional/Suppliers.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,15 @@ public static <T> UnwrappableSupplier<T, Supplier<T>> memoize(Supplier<T> suppli
5656
return new MemoizeSupplier<T>(supplier);
5757
}
5858

59+
/**
60+
* Wrap a given supplier. The result of the suppletion is memoized after the first call. Subsequent calls will give the same value, without calling the supplier again. The result is als {@link CloseableSupplier}
61+
*
62+
* @param supplier the supplier to memoize
63+
* @param <T> The type of the objects to supply
64+
* @return a new supplier that uses the argument supplier only once
65+
*/
5966
public static <T, S extends CloseableSupplier<T>> UnwrappableCloseableSupplier<T, Supplier<T>> memoize(S supplier) {
60-
return new CloseableSupplierWrapper<>(memoize((Supplier<T>) supplier),
67+
return new CloseableSupplierWrapper<>(memoize((Supplier<T>) supplier),
6168
new SupplierConsumerWrapper<>(supplier), null);
6269
}
6370

@@ -72,6 +79,13 @@ public static <T> UnwrappableCloseableSupplier<T, Supplier<T>> closeable(Supplie
7279
return new CloseableSupplierWrapper<>(supplier, closer, "closeable");
7380
}
7481

82+
83+
/**
84+
* Wraps a {@link Supplier} in a {@link UnwrappableCloseableSupplier}, which can be closed to release resources.
85+
* @param supplier the supplier to wrap to make it closeable.
86+
* @return A new {@link UnwrappableCloseableSupplier} that wraps the given supplier and can be closed.
87+
* @param <T> the type of the value supplied
88+
*/
7589
public static <T, S extends Supplier<T> & AutoCloseable> UnwrappableCloseableSupplier<T, Supplier<T>> closeable(S supplier) {
7690
SupplierConsumerWrapper<T, S> consumerWrapper = new SupplierConsumerWrapper<>(supplier);
7791
return new CloseableSupplierWrapper<>(supplier, consumerWrapper, "wrapper");

mihxil-functional/src/main/java/org/meeuw/functional/ThrowingBiFunction.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ default R apply(A a, B b) {
2424
}
2525
}
2626

27+
/**
28+
* Applies this function to the given arguments.
29+
* @param a the first function argument
30+
* @param b the second function argument
31+
* @return the function result
32+
* @throws E Checked exception that might occur.
33+
*/
2734
R applyWithException(A a, B b) throws E;
2835

2936
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.meeuw.functional;
2+
3+
import java.util.concurrent.Callable;
4+
5+
6+
/**
7+
* An extension of {@link Callable} with a type of the exception
8+
* @since 1.15
9+
* @param <R> the return type of the callable
10+
* @param <E> the type of the exception that can be thrown
11+
*/
12+
@FunctionalInterface
13+
public interface ThrowingCallable<R, E extends Exception> extends Callable<R> {
14+
15+
@Override
16+
R call() throws E;
17+
18+
}

mihxil-functional/src/main/java/org/meeuw/functional/ThrowingFunction.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ default R apply(A a) {
2323
}
2424
}
2525

26+
/**
27+
* Applies this function to the given arguments.
28+
* @param a the first function argument
29+
* @return the function result
30+
* @throws E Checked exception that might occur.
31+
*/
2632
R applyWithException(A a) throws E;
2733

2834
}

mihxil-functional/src/main/java/org/meeuw/functional/ThrowingQuadriFunction.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ default R apply(A a, B b, C c, D d) {
2323
return sneakyThrow(e);
2424
}
2525
}
26+
/**
27+
* Applies this function to the given arguments.
28+
* @param a the first function argument
29+
* @param b the second function argument
30+
* @param c the third function argument
31+
* @param d the fourth function argument
32+
* @return the function result
33+
* @throws E Checked exception that might occur.
34+
*/
2635

2736
R applyWithException(A a, B b, C c, D d) throws E;
2837

mihxil-functional/src/main/java/org/meeuw/functional/ThrowingTriFunction.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ default R apply(A a, B b, C c) {
2525
}
2626
}
2727

28+
29+
/**
30+
* Applies this function to the given arguments.
31+
* @param a the first function argument
32+
* @param b the second function argument
33+
* @param c the third function argument
34+
* @return the function result
35+
* @throws E Checked exception that might occur.
36+
*/
37+
2838
R applyWithException(A a, B b, C c) throws E;
2939

3040
}

mihxil-functional/src/main/java/org/meeuw/functional/TriConsumer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public interface TriConsumer<T, U, V> {
3131
void accept(T t, U u, V v);
3232

3333
/**
34+
* Returns a composed TriConsumer that performs, in sequence, this operation followed by the after operation. If performing either operation throws an exception, it is relayed to the caller of the composed operation. If performing this operation throws an exception, the after operation will not be performed.
35+
*
3436
* @param after the operation to perform after this operation
3537
* @return a composed {@code TriConsumer} that performs in sequence this operation followed by the {@code after} operation
3638
* @throws NullPointerException if {@code after} is null

mihxil-functional/src/main/java/org/meeuw/functional/TriFunction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public interface TriFunction <T,U,V,R> {
3131
R apply(T t, U u, V v);
3232

3333
/**
34+
* Returns a composed function that first applies this function to its input, and then applies the after function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.
35+
*
3436
* @param <S> – the type of output of the after function, and of the composed function
3537
* @param after the function to apply after this function is applied
3638
* @return a composed function that first applies this function and then

0 commit comments

Comments
 (0)