|
19 | 19 | */ |
20 | 20 | package ch.powerunit.extensions.exceptions; |
21 | 21 |
|
| 22 | +import static ch.powerunit.extensions.exceptions.Constants.verifySupplier; |
22 | 23 | import static ch.powerunit.extensions.exceptions.Constants.verifyPredicate; |
23 | 24 |
|
24 | 25 | import java.util.function.Function; |
25 | | -import java.util.function.Predicate; |
26 | 26 |
|
| 27 | +import org.apache.commons.collections4.Factory; |
27 | 28 | import org.apache.commons.collections4.FunctorException; |
28 | 29 |
|
29 | 30 | /** |
@@ -68,4 +69,25 @@ private CommonsCollections4Helper() { |
68 | 69 | public static <T> org.apache.commons.collections4.Predicate<T> asPredicate(PredicateWithException<T, ?> predicate) { |
69 | 70 | return PredicateWithException.unchecked(verifyPredicate(predicate), DEFAULT_EXCEPTION_MAPPER)::test; |
70 | 71 | } |
| 72 | + |
| 73 | + /** |
| 74 | + * Transforms a {@link SupplierWithException} to the one from |
| 75 | + * commons-collections. |
| 76 | + * |
| 77 | + * @param supplier |
| 78 | + * the {@link SupplierWithException} to be transformed to the one |
| 79 | + * from commons-collections. |
| 80 | + * @param <T> |
| 81 | + * the type of the result of the supplier |
| 82 | + * @return the {@link Factory factory} from commons-collections. The exception |
| 83 | + * are wrapped in a FunctorException. |
| 84 | + * @throws NoClassDefFoundError |
| 85 | + * In case the commons-collections4 library is not available. |
| 86 | + * @throws NullPointerException |
| 87 | + * if supplier is null. |
| 88 | + * @see org.apache.commons.collections4.Factory |
| 89 | + */ |
| 90 | + public static <T> Factory<T> asFactory(SupplierWithException<T, ?> supplier) { |
| 91 | + return SupplierWithException.unchecked(verifySupplier(supplier), FunctorException::new)::get; |
| 92 | + } |
71 | 93 | } |
0 commit comments