diff options
author | Marko Zajc <marko@zajc.eu.org> | 2023-04-16 01:21:33 +0200 |
---|---|---|
committer | Marko Zajc <marko@zajc.eu.org> | 2023-04-16 01:21:33 +0200 |
commit | ec4753f61d22b69dee50cb8e440f632f1ba8d3e4 (patch) | |
tree | d048a7ced09749bbb49717734e18f5938814986b | |
parent | 2922f6e9b9c0f11b50f78e405675db0bfb052e47 (diff) |
Add handleThrowing variants that rethrow the same (checked) exception
-rw-r--r-- | src/main/java/com/github/markozajc/ef/EHandle.java | 1141 |
1 files changed, 1141 insertions, 0 deletions
diff --git a/src/main/java/com/github/markozajc/ef/EHandle.java b/src/main/java/com/github/markozajc/ef/EHandle.java index fe7f579..1a7da95 100644 --- a/src/main/java/com/github/markozajc/ef/EHandle.java +++ b/src/main/java/com/github/markozajc/ef/EHandle.java | |||
@@ -96,6 +96,32 @@ public class EHandle { | |||
96 | 96 | ||
97 | /** | 97 | /** |
98 | * Handles a generic exception type that may occur in the handled consumer by | 98 | * Handles a generic exception type that may occur in the handled consumer by |
99 | * throwing it explicitly. | ||
100 | * | ||
101 | * @param <E> | ||
102 | * The handled function's exception type | ||
103 | * @param handled | ||
104 | * The function that may throw an exception | ||
105 | * | ||
106 | * @return An exception-proofed consumer | ||
107 | * | ||
108 | * @throws E | ||
109 | * The checked exception | ||
110 | */ | ||
111 | @Nonnull | ||
112 | @SuppressWarnings("unused") | ||
113 | public static <T, E extends Throwable> Consumer<T> handleThrowing(@Nonnull EConsumer<T, E> handled) throws E { | ||
114 | return t -> { | ||
115 | try { | ||
116 | handled.acceptChecked(t); | ||
117 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
118 | throw asUnchecked(e); | ||
119 | } | ||
120 | }; | ||
121 | } | ||
122 | |||
123 | /** | ||
124 | * Handles a generic exception type that may occur in the handled consumer by | ||
99 | * throwing a different exception. | 125 | * throwing a different exception. |
100 | * | 126 | * |
101 | * @param <E> | 127 | * @param <E> |
@@ -151,6 +177,32 @@ public class EHandle { | |||
151 | } | 177 | } |
152 | 178 | ||
153 | /** | 179 | /** |
180 | * Handles a generic exception type that may occur in the handled consumer by | ||
181 | * throwing it explicitly. | ||
182 | * | ||
183 | * @param <E> | ||
184 | * The handled function's exception type | ||
185 | * @param handled | ||
186 | * The function that may throw an exception | ||
187 | * | ||
188 | * @return An exception-proofed consumer | ||
189 | * | ||
190 | * @throws E | ||
191 | * The checked exception | ||
192 | */ | ||
193 | @Nonnull | ||
194 | @SuppressWarnings("unused") | ||
195 | public static <E extends Throwable> BooleanConsumer handleThrowing(@Nonnull EBooleanConsumer<E> handled) throws E { | ||
196 | return p -> { | ||
197 | try { | ||
198 | handled.acceptChecked(p); | ||
199 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
200 | throw asUnchecked(e); | ||
201 | } | ||
202 | }; | ||
203 | } | ||
204 | |||
205 | /** | ||
154 | * Handles a generic exception type that may occur in the handled consumer with a | 206 | * Handles a generic exception type that may occur in the handled consumer with a |
155 | * provided handler. | 207 | * provided handler. |
156 | * | 208 | * |
@@ -207,6 +259,32 @@ public class EHandle { | |||
207 | } | 259 | } |
208 | 260 | ||
209 | /** | 261 | /** |
262 | * Handles a generic exception type that may occur in the handled consumer by | ||
263 | * throwing it explicitly. | ||
264 | * | ||
265 | * @param <E> | ||
266 | * The handled function's exception type | ||
267 | * @param handled | ||
268 | * The function that may throw an exception | ||
269 | * | ||
270 | * @return An exception-proofed consumer | ||
271 | * | ||
272 | * @throws E | ||
273 | * The checked exception | ||
274 | */ | ||
275 | @Nonnull | ||
276 | @SuppressWarnings("unused") | ||
277 | public static <E extends Throwable> ByteConsumer handleThrowing(@Nonnull EByteConsumer<E> handled) throws E { | ||
278 | return p -> { | ||
279 | try { | ||
280 | handled.acceptChecked(p); | ||
281 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
282 | throw asUnchecked(e); | ||
283 | } | ||
284 | }; | ||
285 | } | ||
286 | |||
287 | /** | ||
210 | * Handles a generic exception type that may occur in the handled consumer with a | 288 | * Handles a generic exception type that may occur in the handled consumer with a |
211 | * provided handler. | 289 | * provided handler. |
212 | * | 290 | * |
@@ -263,6 +341,32 @@ public class EHandle { | |||
263 | } | 341 | } |
264 | 342 | ||
265 | /** | 343 | /** |
344 | * Handles a generic exception type that may occur in the handled consumer by | ||
345 | * throwing it explicitly. | ||
346 | * | ||
347 | * @param <E> | ||
348 | * The handled function's exception type | ||
349 | * @param handled | ||
350 | * The function that may throw an exception | ||
351 | * | ||
352 | * @return An exception-proofed consumer | ||
353 | * | ||
354 | * @throws E | ||
355 | * The checked exception | ||
356 | */ | ||
357 | @Nonnull | ||
358 | @SuppressWarnings("unused") | ||
359 | public static <E extends Throwable> IntConsumer handleThrowing(@Nonnull EIntConsumer<E> handled) throws E { | ||
360 | return p -> { | ||
361 | try { | ||
362 | handled.acceptChecked(p); | ||
363 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
364 | throw asUnchecked(e); | ||
365 | } | ||
366 | }; | ||
367 | } | ||
368 | |||
369 | /** | ||
266 | * Handles a generic exception type that may occur in the handled consumer with a | 370 | * Handles a generic exception type that may occur in the handled consumer with a |
267 | * provided handler. | 371 | * provided handler. |
268 | * | 372 | * |
@@ -319,6 +423,32 @@ public class EHandle { | |||
319 | } | 423 | } |
320 | 424 | ||
321 | /** | 425 | /** |
426 | * Handles a generic exception type that may occur in the handled consumer by | ||
427 | * throwing it explicitly. | ||
428 | * | ||
429 | * @param <E> | ||
430 | * The handled function's exception type | ||
431 | * @param handled | ||
432 | * The function that may throw an exception | ||
433 | * | ||
434 | * @return An exception-proofed consumer | ||
435 | * | ||
436 | * @throws E | ||
437 | * The checked exception | ||
438 | */ | ||
439 | @Nonnull | ||
440 | @SuppressWarnings("unused") | ||
441 | public static <E extends Throwable> LongConsumer handleThrowing(@Nonnull ELongConsumer<E> handled) throws E { | ||
442 | return p -> { | ||
443 | try { | ||
444 | handled.acceptChecked(p); | ||
445 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
446 | throw asUnchecked(e); | ||
447 | } | ||
448 | }; | ||
449 | } | ||
450 | |||
451 | /** | ||
322 | * Handles a generic exception type that may occur in the handled consumer with a | 452 | * Handles a generic exception type that may occur in the handled consumer with a |
323 | * provided handler. | 453 | * provided handler. |
324 | * | 454 | * |
@@ -374,6 +504,32 @@ public class EHandle { | |||
374 | }; | 504 | }; |
375 | } | 505 | } |
376 | 506 | ||
507 | /** | ||
508 | * Handles a generic exception type that may occur in the handled consumer by | ||
509 | * throwing it explicitly. | ||
510 | * | ||
511 | * @param <E> | ||
512 | * The handled function's exception type | ||
513 | * @param handled | ||
514 | * The function that may throw an exception | ||
515 | * | ||
516 | * @return An exception-proofed consumer | ||
517 | * | ||
518 | * @throws E | ||
519 | * The checked exception | ||
520 | */ | ||
521 | @Nonnull | ||
522 | @SuppressWarnings("unused") | ||
523 | public static <E extends Throwable> ShortConsumer handleThrowing(@Nonnull EShortConsumer<E> handled) throws E { | ||
524 | return p -> { | ||
525 | try { | ||
526 | handled.acceptChecked(p); | ||
527 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
528 | throw asUnchecked(e); | ||
529 | } | ||
530 | }; | ||
531 | } | ||
532 | |||
377 | /* | 533 | /* |
378 | * ================== BiConsumers ================== | 534 | * ================== BiConsumers ================== |
379 | */ | 535 | */ |
@@ -435,6 +591,32 @@ public class EHandle { | |||
435 | } | 591 | } |
436 | 592 | ||
437 | /** | 593 | /** |
594 | * Handles a generic exception type that may occur in the handled consumer by | ||
595 | * throwing it explicitly. | ||
596 | * | ||
597 | * @param <E> | ||
598 | * The handled function's exception type | ||
599 | * @param handled | ||
600 | * The function that may throw an exception | ||
601 | * | ||
602 | * @return An exception-proofed consumer | ||
603 | * | ||
604 | * @throws E | ||
605 | * The checked exception | ||
606 | */ | ||
607 | @Nonnull | ||
608 | @SuppressWarnings("unused") | ||
609 | public static <T, U, E extends Throwable> BiConsumer<T, U> handleThrowing(@Nonnull EBiConsumer<T, U, E> handled) throws E { | ||
610 | return (t, u) -> { | ||
611 | try { | ||
612 | handled.acceptChecked(t, u); | ||
613 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
614 | throw asUnchecked(e); | ||
615 | } | ||
616 | }; | ||
617 | } | ||
618 | |||
619 | /** | ||
438 | * Handles a generic exception type that may occur in the handled consumer with a | 620 | * Handles a generic exception type that may occur in the handled consumer with a |
439 | * provided handler. | 621 | * provided handler. |
440 | * | 622 | * |
@@ -491,6 +673,32 @@ public class EHandle { | |||
491 | } | 673 | } |
492 | 674 | ||
493 | /** | 675 | /** |
676 | * Handles a generic exception type that may occur in the handled consumer by | ||
677 | * throwing it explicitly. | ||
678 | * | ||
679 | * @param <E> | ||
680 | * The handled function's exception type | ||
681 | * @param handled | ||
682 | * The function that may throw an exception | ||
683 | * | ||
684 | * @return An exception-proofed consumer | ||
685 | * | ||
686 | * @throws E | ||
687 | * The checked exception | ||
688 | */ | ||
689 | @Nonnull | ||
690 | @SuppressWarnings("unused") | ||
691 | public static <T, E extends Throwable> ObjBooleanConsumer<T> handleThrowing(@Nonnull EObjBooleanConsumer<T, E> handled) throws E { | ||
692 | return (t, p) -> { | ||
693 | try { | ||
694 | handled.acceptChecked(t, p); | ||
695 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
696 | throw asUnchecked(e); | ||
697 | } | ||
698 | }; | ||
699 | } | ||
700 | |||
701 | /** | ||
494 | * Handles a generic exception type that may occur in the handled consumer with a | 702 | * Handles a generic exception type that may occur in the handled consumer with a |
495 | * provided handler. | 703 | * provided handler. |
496 | * | 704 | * |
@@ -547,6 +755,32 @@ public class EHandle { | |||
547 | } | 755 | } |
548 | 756 | ||
549 | /** | 757 | /** |
758 | * Handles a generic exception type that may occur in the handled consumer by | ||
759 | * throwing it explicitly. | ||
760 | * | ||
761 | * @param <E> | ||
762 | * The handled function's exception type | ||
763 | * @param handled | ||
764 | * The function that may throw an exception | ||
765 | * | ||
766 | * @return An exception-proofed consumer | ||
767 | * | ||
768 | * @throws E | ||
769 | * The checked exception | ||
770 | */ | ||
771 | @Nonnull | ||
772 | @SuppressWarnings("unused") | ||
773 | public static <T, E extends Throwable> ObjByteConsumer<T> handleThrowing(@Nonnull EObjByteConsumer<T, E> handled) throws E { | ||
774 | return (t, p) -> { | ||
775 | try { | ||
776 | handled.acceptChecked(t, p); | ||
777 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
778 | throw asUnchecked(e); | ||
779 | } | ||
780 | }; | ||
781 | } | ||
782 | |||
783 | /** | ||
550 | * Handles a generic exception type that may occur in the handled consumer with a | 784 | * Handles a generic exception type that may occur in the handled consumer with a |
551 | * provided handler. | 785 | * provided handler. |
552 | * | 786 | * |
@@ -603,6 +837,32 @@ public class EHandle { | |||
603 | } | 837 | } |
604 | 838 | ||
605 | /** | 839 | /** |
840 | * Handles a generic exception type that may occur in the handled consumer by | ||
841 | * throwing it explicitly. | ||
842 | * | ||
843 | * @param <E> | ||
844 | * The handled function's exception type | ||
845 | * @param handled | ||
846 | * The function that may throw an exception | ||
847 | * | ||
848 | * @return An exception-proofed consumer | ||
849 | * | ||
850 | * @throws E | ||
851 | * The checked exception | ||
852 | */ | ||
853 | @Nonnull | ||
854 | @SuppressWarnings("unused") | ||
855 | public static <T, E extends Throwable> ObjIntConsumer<T> handleThrowing(@Nonnull EObjIntConsumer<T, E> handled) throws E { | ||
856 | return (t, p) -> { | ||
857 | try { | ||
858 | handled.acceptChecked(t, p); | ||
859 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
860 | throw asUnchecked(e); | ||
861 | } | ||
862 | }; | ||
863 | } | ||
864 | |||
865 | /** | ||
606 | * Handles a generic exception type that may occur in the handled consumer with a | 866 | * Handles a generic exception type that may occur in the handled consumer with a |
607 | * provided handler. | 867 | * provided handler. |
608 | * | 868 | * |
@@ -659,6 +919,32 @@ public class EHandle { | |||
659 | } | 919 | } |
660 | 920 | ||
661 | /** | 921 | /** |
922 | * Handles a generic exception type that may occur in the handled consumer by | ||
923 | * throwing it explicitly. | ||
924 | * | ||
925 | * @param <E> | ||
926 | * The handled function's exception type | ||
927 | * @param handled | ||
928 | * The function that may throw an exception | ||
929 | * | ||
930 | * @return An exception-proofed consumer | ||
931 | * | ||
932 | * @throws E | ||
933 | * The checked exception | ||
934 | */ | ||
935 | @Nonnull | ||
936 | @SuppressWarnings("unused") | ||
937 | public static <T, E extends Throwable> ObjLongConsumer<T> handleThrowing(@Nonnull EObjLongConsumer<T, E> handled) throws E { | ||
938 | return (t, p) -> { | ||
939 | try { | ||
940 | handled.acceptChecked(t, p); | ||
941 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
942 | throw asUnchecked(e); | ||
943 | } | ||
944 | }; | ||
945 | } | ||
946 | |||
947 | /** | ||
662 | * Handles a generic exception type that may occur in the handled consumer with a | 948 | * Handles a generic exception type that may occur in the handled consumer with a |
663 | * provided handler. | 949 | * provided handler. |
664 | * | 950 | * |
@@ -714,6 +1000,32 @@ public class EHandle { | |||
714 | }; | 1000 | }; |
715 | } | 1001 | } |
716 | 1002 | ||
1003 | /** | ||
1004 | * Handles a generic exception type that may occur in the handled consumer by | ||
1005 | * throwing it explicitly. | ||
1006 | * | ||
1007 | * @param <E> | ||
1008 | * The handled function's exception type | ||
1009 | * @param handled | ||
1010 | * The function that may throw an exception | ||
1011 | * | ||
1012 | * @return An exception-proofed consumer | ||
1013 | * | ||
1014 | * @throws E | ||
1015 | * The checked exception | ||
1016 | */ | ||
1017 | @Nonnull | ||
1018 | @SuppressWarnings("unused") | ||
1019 | public static <T, E extends Throwable> ObjShortConsumer<T> handleThrowing(@Nonnull EObjShortConsumer<T, E> handled) throws E { | ||
1020 | return (t, p) -> { | ||
1021 | try { | ||
1022 | handled.acceptChecked(t, p); | ||
1023 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
1024 | throw asUnchecked(e); | ||
1025 | } | ||
1026 | }; | ||
1027 | } | ||
1028 | |||
717 | /* | 1029 | /* |
718 | * ================== Functions ================== | 1030 | * ================== Functions ================== |
719 | */ | 1031 | */ |
@@ -775,6 +1087,32 @@ public class EHandle { | |||
775 | } | 1087 | } |
776 | 1088 | ||
777 | /** | 1089 | /** |
1090 | * Handles a generic exception type that may occur in the handled function by | ||
1091 | * throwing it explicitly. | ||
1092 | * | ||
1093 | * @param <E> | ||
1094 | * The handled function's exception type | ||
1095 | * @param handled | ||
1096 | * The function that may throw an exception | ||
1097 | * | ||
1098 | * @return An exception-proofed function | ||
1099 | * | ||
1100 | * @throws E | ||
1101 | * The checked exception | ||
1102 | */ | ||
1103 | @Nonnull | ||
1104 | @SuppressWarnings("unused") | ||
1105 | public static <T, R, E extends Throwable> Function<T, R> handleThrowing(@Nonnull EFunction<T, R, E> handled) throws E { | ||
1106 | return t -> { | ||
1107 | try { | ||
1108 | return handled.applyChecked(t); | ||
1109 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
1110 | throw asUnchecked(e); | ||
1111 | } | ||
1112 | }; | ||
1113 | } | ||
1114 | |||
1115 | /** | ||
778 | * Handles a generic exception type that may occur in the handled function with a | 1116 | * Handles a generic exception type that may occur in the handled function with a |
779 | * provided handler. | 1117 | * provided handler. |
780 | * | 1118 | * |
@@ -831,6 +1169,32 @@ public class EHandle { | |||
831 | } | 1169 | } |
832 | 1170 | ||
833 | /** | 1171 | /** |
1172 | * Handles a generic exception type that may occur in the handled function by | ||
1173 | * throwing it explicitly. | ||
1174 | * | ||
1175 | * @param <E> | ||
1176 | * The handled function's exception type | ||
1177 | * @param handled | ||
1178 | * The function that may throw an exception | ||
1179 | * | ||
1180 | * @return An exception-proofed function | ||
1181 | * | ||
1182 | * @throws E | ||
1183 | * The checked exception | ||
1184 | */ | ||
1185 | @Nonnull | ||
1186 | @SuppressWarnings("unused") | ||
1187 | public static <R, E extends Throwable> BooleanFunction<R> handleThrowing(@Nonnull EBooleanFunction<R, E> handled) throws E { | ||
1188 | return p -> { | ||
1189 | try { | ||
1190 | return handled.applyChecked(p); | ||
1191 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
1192 | throw asUnchecked(e); | ||
1193 | } | ||
1194 | }; | ||
1195 | } | ||
1196 | |||
1197 | /** | ||
834 | * Handles a generic exception type that may occur in the handled function with a | 1198 | * Handles a generic exception type that may occur in the handled function with a |
835 | * provided handler. | 1199 | * provided handler. |
836 | * | 1200 | * |
@@ -887,6 +1251,32 @@ public class EHandle { | |||
887 | } | 1251 | } |
888 | 1252 | ||
889 | /** | 1253 | /** |
1254 | * Handles a generic exception type that may occur in the handled function by | ||
1255 | * throwing it explicitly. | ||
1256 | * | ||
1257 | * @param <E> | ||
1258 | * The handled function's exception type | ||
1259 | * @param handled | ||
1260 | * The function that may throw an exception | ||
1261 | * | ||
1262 | * @return An exception-proofed function | ||
1263 | * | ||
1264 | * @throws E | ||
1265 | * The checked exception | ||
1266 | */ | ||
1267 | @Nonnull | ||
1268 | @SuppressWarnings("unused") | ||
1269 | public static <R, E extends Throwable> ByteFunction<R> handleThrowing(@Nonnull EByteFunction<R, E> handled) throws E { | ||
1270 | return p -> { | ||
1271 | try { | ||
1272 | return handled.applyChecked(p); | ||
1273 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
1274 | throw asUnchecked(e); | ||
1275 | } | ||
1276 | }; | ||
1277 | } | ||
1278 | |||
1279 | /** | ||
890 | * Handles a generic exception type that may occur in the handled function with a | 1280 | * Handles a generic exception type that may occur in the handled function with a |
891 | * provided handler. | 1281 | * provided handler. |
892 | * | 1282 | * |
@@ -943,6 +1333,32 @@ public class EHandle { | |||
943 | } | 1333 | } |
944 | 1334 | ||
945 | /** | 1335 | /** |
1336 | * Handles a generic exception type that may occur in the handled function by | ||
1337 | * throwing it explicitly. | ||
1338 | * | ||
1339 | * @param <E> | ||
1340 | * The handled function's exception type | ||
1341 | * @param handled | ||
1342 | * The function that may throw an exception | ||
1343 | * | ||
1344 | * @return An exception-proofed function | ||
1345 | * | ||
1346 | * @throws E | ||
1347 | * The checked exception | ||
1348 | */ | ||
1349 | @Nonnull | ||
1350 | @SuppressWarnings("unused") | ||
1351 | public static <R, E extends Throwable> IntFunction<R> handleThrowing(@Nonnull EIntFunction<R, E> handled) throws E { | ||
1352 | return p -> { | ||
1353 | try { | ||
1354 | return handled.applyChecked(p); | ||
1355 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
1356 | throw asUnchecked(e); | ||
1357 | } | ||
1358 | }; | ||
1359 | } | ||
1360 | |||
1361 | /** | ||
946 | * Handles a generic exception type that may occur in the handled function with a | 1362 | * Handles a generic exception type that may occur in the handled function with a |
947 | * provided handler. | 1363 | * provided handler. |
948 | * | 1364 | * |
@@ -999,6 +1415,32 @@ public class EHandle { | |||
999 | } | 1415 | } |
1000 | 1416 | ||
1001 | /** | 1417 | /** |
1418 | * Handles a generic exception type that may occur in the handled function by | ||
1419 | * throwing it explicitly. | ||
1420 | * | ||
1421 | * @param <E> | ||
1422 | * The handled function's exception type | ||
1423 | * @param handled | ||
1424 | * The function that may throw an exception | ||
1425 | * | ||
1426 | * @return An exception-proofed function | ||
1427 | * | ||
1428 | * @throws E | ||
1429 | * The checked exception | ||
1430 | */ | ||
1431 | @Nonnull | ||
1432 | @SuppressWarnings("unused") | ||
1433 | public static <R, E extends Throwable, X extends Throwable> LongFunction<R> handleThrowing(@Nonnull ELongFunction<R, E> handled) throws E { | ||
1434 | return p -> { | ||
1435 | try { | ||
1436 | return handled.applyChecked(p); | ||
1437 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
1438 | throw asUnchecked(e); | ||
1439 | } | ||
1440 | }; | ||
1441 | } | ||
1442 | |||
1443 | /** | ||
1002 | * Handles a generic exception type that may occur in the handled function with a | 1444 | * Handles a generic exception type that may occur in the handled function with a |
1003 | * provided handler. | 1445 | * provided handler. |
1004 | * | 1446 | * |
@@ -1054,6 +1496,32 @@ public class EHandle { | |||
1054 | }; | 1496 | }; |
1055 | } | 1497 | } |
1056 | 1498 | ||
1499 | /** | ||
1500 | * Handles a generic exception type that may occur in the handled function by | ||
1501 | * throwing it explicitly. | ||
1502 | * | ||
1503 | * @param <E> | ||
1504 | * The handled function's exception type | ||
1505 | * @param handled | ||
1506 | * The function that may throw an exception | ||
1507 | * | ||
1508 | * @return An exception-proofed function | ||
1509 | * | ||
1510 | * @throws E | ||
1511 | * The checked exception | ||
1512 | */ | ||
1513 | @Nonnull | ||
1514 | @SuppressWarnings("unused") | ||
1515 | public static <R, E extends Throwable> ShortFunction<R> handleThrowing(@Nonnull EShortFunction<R, E> handled) throws E { | ||
1516 | return p -> { | ||
1517 | try { | ||
1518 | return handled.applyChecked(p); | ||
1519 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
1520 | throw asUnchecked(e); | ||
1521 | } | ||
1522 | }; | ||
1523 | } | ||
1524 | |||
1057 | /* | 1525 | /* |
1058 | * ================== BiFunctions ================== | 1526 | * ================== BiFunctions ================== |
1059 | */ | 1527 | */ |
@@ -1115,6 +1583,32 @@ public class EHandle { | |||
1115 | } | 1583 | } |
1116 | 1584 | ||
1117 | /** | 1585 | /** |
1586 | * Handles a generic exception type that may occur in the handled function by | ||
1587 | * throwing it explicitly. | ||
1588 | * | ||
1589 | * @param <E> | ||
1590 | * The handled function's exception type | ||
1591 | * @param handled | ||
1592 | * The function that may throw an exception | ||
1593 | * | ||
1594 | * @return An exception-proofed function | ||
1595 | * | ||
1596 | * @throws E | ||
1597 | * The checked exception | ||
1598 | */ | ||
1599 | @Nonnull | ||
1600 | @SuppressWarnings("unused") | ||
1601 | public static <T, U, R, E extends Throwable> BiFunction<T, U, R> handleThrowing(@Nonnull EBiFunction<T, U, R, E> handled) throws E { | ||
1602 | return (t, u) -> { | ||
1603 | try { | ||
1604 | return handled.applyChecked(t, u); | ||
1605 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
1606 | throw asUnchecked(e); | ||
1607 | } | ||
1608 | }; | ||
1609 | } | ||
1610 | |||
1611 | /** | ||
1118 | * Handles a generic exception type that may occur in the handled function with a | 1612 | * Handles a generic exception type that may occur in the handled function with a |
1119 | * provided handler. | 1613 | * provided handler. |
1120 | * | 1614 | * |
@@ -1171,6 +1665,32 @@ public class EHandle { | |||
1171 | } | 1665 | } |
1172 | 1666 | ||
1173 | /** | 1667 | /** |
1668 | * Handles a generic exception type that may occur in the handled function by | ||
1669 | * throwing it explicitly. | ||
1670 | * | ||
1671 | * @param <E> | ||
1672 | * The handled function's exception type | ||
1673 | * @param handled | ||
1674 | * The function that may throw an exception | ||
1675 | * | ||
1676 | * @return An exception-proofed function | ||
1677 | * | ||
1678 | * @throws E | ||
1679 | * The checked exception | ||
1680 | */ | ||
1681 | @Nonnull | ||
1682 | @SuppressWarnings("unused") | ||
1683 | public static <T, R, E extends Throwable> ObjBooleanFunction<T, R> handleThrowing(@Nonnull EObjBooleanFunction<T, R, E> handled) throws E { | ||
1684 | return (t, p) -> { | ||
1685 | try { | ||
1686 | return handled.applyChecked(t, p); | ||
1687 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
1688 | throw asUnchecked(e); | ||
1689 | } | ||
1690 | }; | ||
1691 | } | ||
1692 | |||
1693 | /** | ||
1174 | * Handles a generic exception type that may occur in the handled function with a | 1694 | * Handles a generic exception type that may occur in the handled function with a |
1175 | * provided handler. | 1695 | * provided handler. |
1176 | * | 1696 | * |
@@ -1227,6 +1747,32 @@ public class EHandle { | |||
1227 | } | 1747 | } |
1228 | 1748 | ||
1229 | /** | 1749 | /** |
1750 | * Handles a generic exception type that may occur in the handled function by | ||
1751 | * throwing it explicitly. | ||
1752 | * | ||
1753 | * @param <E> | ||
1754 | * The handled function's exception type | ||
1755 | * @param handled | ||
1756 | * The function that may throw an exception | ||
1757 | * | ||
1758 | * @return An exception-proofed function | ||
1759 | * | ||
1760 | * @throws E | ||
1761 | * The checked exception | ||
1762 | */ | ||
1763 | @Nonnull | ||
1764 | @SuppressWarnings("unused") | ||
1765 | public static <T, R, E extends Throwable> ObjByteFunction<T, R> handleThrowing(@Nonnull EObjByteFunction<T, R, E> handled) throws E { | ||
1766 | return (t, p) -> { | ||
1767 | try { | ||
1768 | return handled.applyChecked(t, p); | ||
1769 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
1770 | throw asUnchecked(e); | ||
1771 | } | ||
1772 | }; | ||
1773 | } | ||
1774 | |||
1775 | /** | ||
1230 | * Handles a generic exception type that may occur in the handled function with a | 1776 | * Handles a generic exception type that may occur in the handled function with a |
1231 | * provided handler. | 1777 | * provided handler. |
1232 | * | 1778 | * |
@@ -1283,6 +1829,32 @@ public class EHandle { | |||
1283 | } | 1829 | } |
1284 | 1830 | ||
1285 | /** | 1831 | /** |
1832 | * Handles a generic exception type that may occur in the handled function by | ||
1833 | * throwing it explicitly. | ||
1834 | * | ||
1835 | * @param <E> | ||
1836 | * The handled function's exception type | ||
1837 | * @param handled | ||
1838 | * The function that may throw an exception | ||
1839 | * | ||
1840 | * @return An exception-proofed function | ||
1841 | * | ||
1842 | * @throws E | ||
1843 | * The checked exception | ||
1844 | */ | ||
1845 | @Nonnull | ||
1846 | @SuppressWarnings("unused") | ||
1847 | public static <T, R, E extends Throwable> ObjIntFunction<T, R> handleThrowing(@Nonnull EObjIntFunction<T, R, E> handled) throws E { | ||
1848 | return (t, p) -> { | ||
1849 | try { | ||
1850 | return handled.applyChecked(t, p); | ||
1851 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
1852 | throw asUnchecked(e); | ||
1853 | } | ||
1854 | }; | ||
1855 | } | ||
1856 | |||
1857 | /** | ||
1286 | * Handles a generic exception type that may occur in the handled function with a | 1858 | * Handles a generic exception type that may occur in the handled function with a |
1287 | * provided handler. | 1859 | * provided handler. |
1288 | * | 1860 | * |
@@ -1339,6 +1911,32 @@ public class EHandle { | |||
1339 | } | 1911 | } |
1340 | 1912 | ||
1341 | /** | 1913 | /** |
1914 | * Handles a generic exception type that may occur in the handled function by | ||
1915 | * throwing it explicitly. | ||
1916 | * | ||
1917 | * @param <E> | ||
1918 | * The handled function's exception type | ||
1919 | * @param handled | ||
1920 | * The function that may throw an exception | ||
1921 | * | ||
1922 | * @return An exception-proofed function | ||
1923 | * | ||
1924 | * @throws E | ||
1925 | * The checked exception | ||
1926 | */ | ||
1927 | @Nonnull | ||
1928 | @SuppressWarnings("unused") | ||
1929 | public static <T, R, E extends Throwable> ObjLongFunction<T, R> handleThrowing(@Nonnull EObjLongFunction<T, R, E> handled) throws E { | ||
1930 | return (t, p) -> { | ||
1931 | try { | ||
1932 | return handled.applyChecked(t, p); | ||
1933 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
1934 | throw asUnchecked(e); | ||
1935 | } | ||
1936 | }; | ||
1937 | } | ||
1938 | |||
1939 | /** | ||
1342 | * Handles a generic exception type that may occur in the handled function with a | 1940 | * Handles a generic exception type that may occur in the handled function with a |
1343 | * provided handler. | 1941 | * provided handler. |
1344 | * | 1942 | * |
@@ -1394,6 +1992,32 @@ public class EHandle { | |||
1394 | }; | 1992 | }; |
1395 | } | 1993 | } |
1396 | 1994 | ||
1995 | /** | ||
1996 | * Handles a generic exception type that may occur in the handled function by | ||
1997 | * throwing it explicitly. | ||
1998 | * | ||
1999 | * @param <E> | ||
2000 | * The handled function's exception type | ||
2001 | * @param handled | ||
2002 | * The function that may throw an exception | ||
2003 | * | ||
2004 | * @return An exception-proofed function | ||
2005 | * | ||
2006 | * @throws E | ||
2007 | * The checked exception | ||
2008 | */ | ||
2009 | @Nonnull | ||
2010 | @SuppressWarnings("unused") | ||
2011 | public static <T, R, E extends Throwable> ObjShortFunction<T, R> handleThrowing(@Nonnull EObjShortFunction<T, R, E> handled) throws E { | ||
2012 | return (t, p) -> { | ||
2013 | try { | ||
2014 | return handled.applyChecked(t, p); | ||
2015 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
2016 | throw asUnchecked(e); | ||
2017 | } | ||
2018 | }; | ||
2019 | } | ||
2020 | |||
1397 | /* | 2021 | /* |
1398 | * ================== Predicates ================== | 2022 | * ================== Predicates ================== |
1399 | */ | 2023 | */ |
@@ -1455,6 +2079,32 @@ public class EHandle { | |||
1455 | } | 2079 | } |
1456 | 2080 | ||
1457 | /** | 2081 | /** |
2082 | * Handles a generic exception type that may occur in the handled predicate by | ||
2083 | * throwing it explicitly. | ||
2084 | * | ||
2085 | * @param <E> | ||
2086 | * The handled function's exception type | ||
2087 | * @param handled | ||
2088 | * The function that may throw an exception | ||
2089 | * | ||
2090 | * @return An exception-proofed predicate | ||
2091 | * | ||
2092 | * @throws E | ||
2093 | * The checked exception | ||
2094 | */ | ||
2095 | @Nonnull | ||
2096 | @SuppressWarnings("unused") | ||
2097 | public static <T, E extends Throwable> Predicate<T> handleThrowing(@Nonnull EPredicate<T, E> handled) throws E { | ||
2098 | return t -> { | ||
2099 | try { | ||
2100 | return handled.testChecked(t); | ||
2101 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
2102 | throw asUnchecked(e); | ||
2103 | } | ||
2104 | }; | ||
2105 | } | ||
2106 | |||
2107 | /** | ||
1458 | * Handles a generic exception type that may occur in the handled predicate with a | 2108 | * Handles a generic exception type that may occur in the handled predicate with a |
1459 | * provided handler. | 2109 | * provided handler. |
1460 | * | 2110 | * |
@@ -1511,6 +2161,32 @@ public class EHandle { | |||
1511 | } | 2161 | } |
1512 | 2162 | ||
1513 | /** | 2163 | /** |
2164 | * Handles a generic exception type that may occur in the handled predicate by | ||
2165 | * throwing it explicitly. | ||
2166 | * | ||
2167 | * @param <E> | ||
2168 | * The handled function's exception type | ||
2169 | * @param handled | ||
2170 | * The function that may throw an exception | ||
2171 | * | ||
2172 | * @return An exception-proofed predicate | ||
2173 | * | ||
2174 | * @throws E | ||
2175 | * The checked exception | ||
2176 | */ | ||
2177 | @Nonnull | ||
2178 | @SuppressWarnings("unused") | ||
2179 | public static <E extends Throwable> BooleanPredicate handleThrowing(@Nonnull EBooleanPredicate<E> handled) throws E { | ||
2180 | return p -> { | ||
2181 | try { | ||
2182 | return handled.testChecked(p); | ||
2183 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
2184 | throw asUnchecked(e); | ||
2185 | } | ||
2186 | }; | ||
2187 | } | ||
2188 | |||
2189 | /** | ||
1514 | * Handles a generic exception type that may occur in the handled predicate with a | 2190 | * Handles a generic exception type that may occur in the handled predicate with a |
1515 | * provided handler. | 2191 | * provided handler. |
1516 | * | 2192 | * |
@@ -1567,6 +2243,32 @@ public class EHandle { | |||
1567 | } | 2243 | } |
1568 | 2244 | ||
1569 | /** | 2245 | /** |
2246 | * Handles a generic exception type that may occur in the handled predicate by | ||
2247 | * throwing it explicitly. | ||
2248 | * | ||
2249 | * @param <E> | ||
2250 | * The handled function's exception type | ||
2251 | * @param handled | ||
2252 | * The function that may throw an exception | ||
2253 | * | ||
2254 | * @return An exception-proofed predicate | ||
2255 | * | ||
2256 | * @throws E | ||
2257 | * The checked exception | ||
2258 | */ | ||
2259 | @Nonnull | ||
2260 | @SuppressWarnings("unused") | ||
2261 | public static <E extends Throwable> BytePredicate handleThrowing(@Nonnull EBytePredicate<E> handled) throws E { | ||
2262 | return p -> { | ||
2263 | try { | ||
2264 | return handled.testChecked(p); | ||
2265 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
2266 | throw asUnchecked(e); | ||
2267 | } | ||
2268 | }; | ||
2269 | } | ||
2270 | |||
2271 | /** | ||
1570 | * Handles a generic exception type that may occur in the handled predicate with a | 2272 | * Handles a generic exception type that may occur in the handled predicate with a |
1571 | * provided handler. | 2273 | * provided handler. |
1572 | * | 2274 | * |
@@ -1623,6 +2325,32 @@ public class EHandle { | |||
1623 | } | 2325 | } |
1624 | 2326 | ||
1625 | /** | 2327 | /** |
2328 | * Handles a generic exception type that may occur in the handled predicate by | ||
2329 | * throwing it explicitly. | ||
2330 | * | ||
2331 | * @param <E> | ||
2332 | * The handled function's exception type | ||
2333 | * @param handled | ||
2334 | * The function that may throw an exception | ||
2335 | * | ||
2336 | * @return An exception-proofed predicate | ||
2337 | * | ||
2338 | * @throws E | ||
2339 | * The checked exception | ||
2340 | */ | ||
2341 | @Nonnull | ||
2342 | @SuppressWarnings("unused") | ||
2343 | public static <E extends Throwable> IntPredicate handleThrowing(@Nonnull EIntPredicate<E> handled) throws E { | ||
2344 | return p -> { | ||
2345 | try { | ||
2346 | return handled.testChecked(p); | ||
2347 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
2348 | throw asUnchecked(e); | ||
2349 | } | ||
2350 | }; | ||
2351 | } | ||
2352 | |||
2353 | /** | ||
1626 | * Handles a generic exception type that may occur in the handled predicate with a | 2354 | * Handles a generic exception type that may occur in the handled predicate with a |
1627 | * provided handler. | 2355 | * provided handler. |
1628 | * | 2356 | * |
@@ -1679,6 +2407,32 @@ public class EHandle { | |||
1679 | } | 2407 | } |
1680 | 2408 | ||
1681 | /** | 2409 | /** |
2410 | * Handles a generic exception type that may occur in the handled predicate by | ||
2411 | * throwing it explicitly. | ||
2412 | * | ||
2413 | * @param <E> | ||
2414 | * The handled function's exception type | ||
2415 | * @param handled | ||
2416 | * The function that may throw an exception | ||
2417 | * | ||
2418 | * @return An exception-proofed predicate | ||
2419 | * | ||
2420 | * @throws E | ||
2421 | * The checked exception | ||
2422 | */ | ||
2423 | @Nonnull | ||
2424 | @SuppressWarnings("unused") | ||
2425 | public static <E extends Throwable> LongPredicate handleThrowing(@Nonnull ELongPredicate<E> handled) throws E { | ||
2426 | return p -> { | ||
2427 | try { | ||
2428 | return handled.testChecked(p); | ||
2429 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
2430 | throw asUnchecked(e); | ||
2431 | } | ||
2432 | }; | ||
2433 | } | ||
2434 | |||
2435 | /** | ||
1682 | * Handles a generic exception type that may occur in the handled predicate with a | 2436 | * Handles a generic exception type that may occur in the handled predicate with a |
1683 | * provided handler. | 2437 | * provided handler. |
1684 | * | 2438 | * |
@@ -1734,6 +2488,32 @@ public class EHandle { | |||
1734 | }; | 2488 | }; |
1735 | } | 2489 | } |
1736 | 2490 | ||
2491 | /** | ||
2492 | * Handles a generic exception type that may occur in the handled predicate by | ||
2493 | * throwing it explicitly. | ||
2494 | * | ||
2495 | * @param <E> | ||
2496 | * The handled function's exception type | ||
2497 | * @param handled | ||
2498 | * The function that may throw an exception | ||
2499 | * | ||
2500 | * @return An exception-proofed predicate | ||
2501 | * | ||
2502 | * @throws E | ||
2503 | * The checked exception | ||
2504 | */ | ||
2505 | @Nonnull | ||
2506 | @SuppressWarnings("unused") | ||
2507 | public static <E extends Throwable> ShortPredicate handleThrowing(@Nonnull EShortPredicate<E> handled) throws E { | ||
2508 | return p -> { | ||
2509 | try { | ||
2510 | return handled.testChecked(p); | ||
2511 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
2512 | throw asUnchecked(e); | ||
2513 | } | ||
2514 | }; | ||
2515 | } | ||
2516 | |||
1737 | /* | 2517 | /* |
1738 | * ================== BiPredicates ================== | 2518 | * ================== BiPredicates ================== |
1739 | */ | 2519 | */ |
@@ -1795,6 +2575,32 @@ public class EHandle { | |||
1795 | } | 2575 | } |
1796 | 2576 | ||
1797 | /** | 2577 | /** |
2578 | * Handles a generic exception type that may occur in the handled predicate by | ||
2579 | * throwing it explicitly. | ||
2580 | * | ||
2581 | * @param <E> | ||
2582 | * The handled function's exception type | ||
2583 | * @param handled | ||
2584 | * The function that may throw an exception | ||
2585 | * | ||
2586 | * @return An exception-proofed predicate | ||
2587 | * | ||
2588 | * @throws E | ||
2589 | * The checked exception | ||
2590 | */ | ||
2591 | @Nonnull | ||
2592 | @SuppressWarnings("unused") | ||
2593 | public static <T, U, E extends Throwable> BiPredicate<T, U> handleThrowing(@Nonnull EBiPredicate<T, U, E> handled) throws E { | ||
2594 | return (t, u) -> { | ||
2595 | try { | ||
2596 | return handled.testChecked(t, u); | ||
2597 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
2598 | throw asUnchecked(e); | ||
2599 | } | ||
2600 | }; | ||
2601 | } | ||
2602 | |||
2603 | /** | ||
1798 | * Handles a generic exception type that may occur in the handled predicate with a | 2604 | * Handles a generic exception type that may occur in the handled predicate with a |
1799 | * provided handler. | 2605 | * provided handler. |
1800 | * | 2606 | * |
@@ -1851,6 +2657,32 @@ public class EHandle { | |||
1851 | } | 2657 | } |
1852 | 2658 | ||
1853 | /** | 2659 | /** |
2660 | * Handles a generic exception type that may occur in the handled predicate by | ||
2661 | * throwing it explicitly. | ||
2662 | * | ||
2663 | * @param <E> | ||
2664 | * The handled function's exception type | ||
2665 | * @param handled | ||
2666 | * The function that may throw an exception | ||
2667 | * | ||
2668 | * @return An exception-proofed predicate | ||
2669 | * | ||
2670 | * @throws E | ||
2671 | * The checked exception | ||
2672 | */ | ||
2673 | @Nonnull | ||
2674 | @SuppressWarnings("unused") | ||
2675 | public static <T, E extends Throwable> ObjBooleanPredicate<T> handleThrowing(@Nonnull EObjBooleanPredicate<T, E> handled) throws E { | ||
2676 | return (t, p) -> { | ||
2677 | try { | ||
2678 | return handled.testChecked(t, p); | ||
2679 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
2680 | throw asUnchecked(e); | ||
2681 | } | ||
2682 | }; | ||
2683 | } | ||
2684 | |||
2685 | /** | ||
1854 | * Handles a generic exception type that may occur in the handled predicate with a | 2686 | * Handles a generic exception type that may occur in the handled predicate with a |
1855 | * provided handler. | 2687 | * provided handler. |
1856 | * | 2688 | * |
@@ -1907,6 +2739,32 @@ public class EHandle { | |||
1907 | } | 2739 | } |
1908 | 2740 | ||
1909 | /** | 2741 | /** |
2742 | * Handles a generic exception type that may occur in the handled predicate by | ||
2743 | * throwing it explicitly. | ||
2744 | * | ||
2745 | * @param <E> | ||
2746 | * The handled function's exception type | ||
2747 | * @param handled | ||
2748 | * The function that may throw an exception | ||
2749 | * | ||
2750 | * @return An exception-proofed predicate | ||
2751 | * | ||
2752 | * @throws E | ||
2753 | * The checked exception | ||
2754 | */ | ||
2755 | @Nonnull | ||
2756 | @SuppressWarnings("unused") | ||
2757 | public static <T, E extends Throwable> ObjBytePredicate<T> handleThrowing(@Nonnull EObjBytePredicate<T, E> handled) throws E { | ||
2758 | return (t, p) -> { | ||
2759 | try { | ||
2760 | return handled.testChecked(t, p); | ||
2761 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
2762 | throw asUnchecked(e); | ||
2763 | } | ||
2764 | }; | ||
2765 | } | ||
2766 | |||
2767 | /** | ||
1910 | * Handles a generic exception type that may occur in the handled predicate with a | 2768 | * Handles a generic exception type that may occur in the handled predicate with a |
1911 | * provided handler. | 2769 | * provided handler. |
1912 | * | 2770 | * |
@@ -1963,6 +2821,32 @@ public class EHandle { | |||
1963 | } | 2821 | } |
1964 | 2822 | ||
1965 | /** | 2823 | /** |
2824 | * Handles a generic exception type that may occur in the handled predicate by | ||
2825 | * throwing it explicitly. | ||
2826 | * | ||
2827 | * @param <E> | ||
2828 | * The handled function's exception type | ||
2829 | * @param handled | ||
2830 | * The function that may throw an exception | ||
2831 | * | ||
2832 | * @return An exception-proofed predicate | ||
2833 | * | ||
2834 | * @throws E | ||
2835 | * The checked exception | ||
2836 | */ | ||
2837 | @Nonnull | ||
2838 | @SuppressWarnings("unused") | ||
2839 | public static <T, E extends Throwable> ObjIntPredicate<T> handleThrowing(@Nonnull EObjIntPredicate<T, E> handled) throws E { | ||
2840 | return (t, p) -> { | ||
2841 | try { | ||
2842 | return handled.testChecked(t, p); | ||
2843 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
2844 | throw asUnchecked(e); | ||
2845 | } | ||
2846 | }; | ||
2847 | } | ||
2848 | |||
2849 | /** | ||
1966 | * Handles a generic exception type that may occur in the handled predicate with a | 2850 | * Handles a generic exception type that may occur in the handled predicate with a |
1967 | * provided handler. | 2851 | * provided handler. |
1968 | * | 2852 | * |
@@ -2019,6 +2903,32 @@ public class EHandle { | |||
2019 | } | 2903 | } |
2020 | 2904 | ||
2021 | /** | 2905 | /** |
2906 | * Handles a generic exception type that may occur in the handled predicate by | ||
2907 | * throwing it explicitly. | ||
2908 | * | ||
2909 | * @param <E> | ||
2910 | * The handled function's exception type | ||
2911 | * @param handled | ||
2912 | * The function that may throw an exception | ||
2913 | * | ||
2914 | * @return An exception-proofed predicate | ||
2915 | * | ||
2916 | * @throws E | ||
2917 | * The checked exception | ||
2918 | */ | ||
2919 | @Nonnull | ||
2920 | @SuppressWarnings("unused") | ||
2921 | public static <T, E extends Throwable> ObjLongPredicate<T> handleThrowing(@Nonnull EObjLongPredicate<T, E> handled) throws E { | ||
2922 | return (t, p) -> { | ||
2923 | try { | ||
2924 | return handled.testChecked(t, p); | ||
2925 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
2926 | throw asUnchecked(e); | ||
2927 | } | ||
2928 | }; | ||
2929 | } | ||
2930 | |||
2931 | /** | ||
2022 | * Handles a generic exception type that may occur in the handled predicate with a | 2932 | * Handles a generic exception type that may occur in the handled predicate with a |
2023 | * provided handler. | 2933 | * provided handler. |
2024 | * | 2934 | * |
@@ -2074,6 +2984,32 @@ public class EHandle { | |||
2074 | }; | 2984 | }; |
2075 | } | 2985 | } |
2076 | 2986 | ||
2987 | /** | ||
2988 | * Handles a generic exception type that may occur in the handled predicate by | ||
2989 | * throwing it explicitly. | ||
2990 | * | ||
2991 | * @param <E> | ||
2992 | * The handled function's exception type | ||
2993 | * @param handled | ||
2994 | * The function that may throw an exception | ||
2995 | * | ||
2996 | * @return An exception-proofed predicate | ||
2997 | * | ||
2998 | * @throws E | ||
2999 | * The checked exception | ||
3000 | */ | ||
3001 | @Nonnull | ||
3002 | @SuppressWarnings("unused") | ||
3003 | public static <T, E extends Throwable> ObjShortPredicate<T> handleThrowing(@Nonnull EObjShortPredicate<T, E> handled) throws E { | ||
3004 | return (t, p) -> { | ||
3005 | try { | ||
3006 | return handled.testChecked(t, p); | ||
3007 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
3008 | throw asUnchecked(e); | ||
3009 | } | ||
3010 | }; | ||
3011 | } | ||
3012 | |||
2077 | /* | 3013 | /* |
2078 | * ================== Runnables ================== | 3014 | * ================== Runnables ================== |
2079 | */ | 3015 | */ |
@@ -2134,6 +3070,32 @@ public class EHandle { | |||
2134 | }; | 3070 | }; |
2135 | } | 3071 | } |
2136 | 3072 | ||
3073 | /** | ||
3074 | * Handles a generic exception type that may occur in the handled runnable by | ||
3075 | * throwing it explicitly. | ||
3076 | * | ||
3077 | * @param <E> | ||
3078 | * The handled function's exception type | ||
3079 | * @param handled | ||
3080 | * The function that may throw an exception | ||
3081 | * | ||
3082 | * @return An exception-proofed runnable | ||
3083 | * | ||
3084 | * @throws E | ||
3085 | * The checked exception | ||
3086 | */ | ||
3087 | @Nonnull | ||
3088 | @SuppressWarnings("unused") | ||
3089 | public static <E extends Throwable> Runnable handleThrowing(@Nonnull ERunnable<E> handled) throws E { | ||
3090 | return () -> { | ||
3091 | try { | ||
3092 | handled.runChecked(); | ||
3093 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
3094 | throw asUnchecked(e); | ||
3095 | } | ||
3096 | }; | ||
3097 | } | ||
3098 | |||
2137 | /* | 3099 | /* |
2138 | * ================== Suppliers & Callable ================== | 3100 | * ================== Suppliers & Callable ================== |
2139 | */ | 3101 | */ |
@@ -2190,6 +3152,29 @@ public class EHandle { | |||
2190 | } | 3152 | } |
2191 | 3153 | ||
2192 | /** | 3154 | /** |
3155 | * Handles any exception type that may occur in the handled callable by throwing it | ||
3156 | * explicitly. | ||
3157 | * | ||
3158 | * @param handled | ||
3159 | * The function that may throw an exception | ||
3160 | * | ||
3161 | * @return An exception-proofed callable | ||
3162 | * | ||
3163 | * @throws Exception | ||
3164 | * The checked exception | ||
3165 | */ | ||
3166 | @Nonnull | ||
3167 | public static <T> Supplier<T> handleThrowing(@Nonnull Callable<T> handled) throws Exception { // NOSONAR | ||
3168 | return () -> { | ||
3169 | try { | ||
3170 | return handled.call(); | ||
3171 | } catch (Exception e) { | ||
3172 | throw asUnchecked(e); | ||
3173 | } | ||
3174 | }; | ||
3175 | } | ||
3176 | |||
3177 | /** | ||
2193 | * Handles a generic exception type that may occur in the handled function with a | 3178 | * Handles a generic exception type that may occur in the handled function with a |
2194 | * provided handler. | 3179 | * provided handler. |
2195 | * | 3180 | * |
@@ -2246,6 +3231,32 @@ public class EHandle { | |||
2246 | } | 3231 | } |
2247 | 3232 | ||
2248 | /** | 3233 | /** |
3234 | * Handles any exception types that may occur in the handled supplier by throwing it | ||
3235 | * explicitly. | ||
3236 | * | ||
3237 | * @param <E> | ||
3238 | * The handled function's exception type | ||
3239 | * @param handled | ||
3240 | * The function that may throw an exception | ||
3241 | * | ||
3242 | * @return An exception-proofed supplier | ||
3243 | * | ||
3244 | * @throws E | ||
3245 | * The checked exception | ||
3246 | */ | ||
3247 | @Nonnull | ||
3248 | @SuppressWarnings("unused") | ||
3249 | public static <T, E extends Throwable> Supplier<T> handleThrowing(@Nonnull ESupplier<T, E> handled) throws E { | ||
3250 | return () -> { | ||
3251 | try { | ||
3252 | return handled.getChecked(); | ||
3253 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
3254 | throw asUnchecked(e); | ||
3255 | } | ||
3256 | }; | ||
3257 | } | ||
3258 | |||
3259 | /** | ||
2249 | * Handles a generic exception type that may occur in the handled function with a | 3260 | * Handles a generic exception type that may occur in the handled function with a |
2250 | * provided handler. | 3261 | * provided handler. |
2251 | * | 3262 | * |
@@ -2301,6 +3312,32 @@ public class EHandle { | |||
2301 | }; | 3312 | }; |
2302 | } | 3313 | } |
2303 | 3314 | ||
3315 | /** | ||
3316 | * Handles any exception types that may occur in the handled supplier by throwing it | ||
3317 | * explicitly. | ||
3318 | * | ||
3319 | * @param <E> | ||
3320 | * The handled function's exception type | ||
3321 | * @param handled | ||
3322 | * The function that may throw an exception | ||
3323 | * | ||
3324 | * @return An exception-proofed supplier | ||
3325 | * | ||
3326 | * @throws E | ||
3327 | * The checked exception | ||
3328 | */ | ||
3329 | @Nonnull | ||
3330 | @SuppressWarnings("unused") | ||
3331 | public static <T, E extends Throwable> BooleanSupplier handleThrowing(@Nonnull EBooleanSupplier<E> handled) throws E { | ||
3332 | return () -> { | ||
3333 | try { | ||
3334 | return handled.getAsBoolean(); | ||
3335 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
3336 | throw asUnchecked(e); | ||
3337 | } | ||
3338 | }; | ||
3339 | } | ||
3340 | |||
2304 | // missing: handle EByteSupplier, blocked by: missing ToByteFunction | 3341 | // missing: handle EByteSupplier, blocked by: missing ToByteFunction |
2305 | 3342 | ||
2306 | /** | 3343 | /** |
@@ -2335,6 +3372,32 @@ public class EHandle { | |||
2335 | } | 3372 | } |
2336 | 3373 | ||
2337 | /** | 3374 | /** |
3375 | * Handles any exception types that may occur in the handled supplier by throwing it | ||
3376 | * explicitly. | ||
3377 | * | ||
3378 | * @param <E> | ||
3379 | * The handled function's exception type | ||
3380 | * @param handled | ||
3381 | * The function that may throw an exception | ||
3382 | * | ||
3383 | * @return An exception-proofed supplier | ||
3384 | * | ||
3385 | * @throws E | ||
3386 | * The checked exception | ||
3387 | */ | ||
3388 | @Nonnull | ||
3389 | @SuppressWarnings("unused") | ||
3390 | public static <T, E extends Throwable> ByteSupplier handleThrowing(@Nonnull EByteSupplier<E> handled) throws E { | ||
3391 | return () -> { | ||
3392 | try { | ||
3393 | return handled.getAsByte(); | ||
3394 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
3395 | throw asUnchecked(e); | ||
3396 | } | ||
3397 | }; | ||
3398 | } | ||
3399 | |||
3400 | /** | ||
2338 | * Handles a generic exception type that may occur in the handled function with a | 3401 | * Handles a generic exception type that may occur in the handled function with a |
2339 | * provided handler. | 3402 | * provided handler. |
2340 | * | 3403 | * |
@@ -2390,6 +3453,32 @@ public class EHandle { | |||
2390 | }; | 3453 | }; |
2391 | } | 3454 | } |
2392 | 3455 | ||
3456 | /** | ||
3457 | * Handles any exception types that may occur in the handled supplier by throwing it | ||
3458 | * explicitly. | ||
3459 | * | ||
3460 | * @param <E> | ||
3461 | * The handled function's exception type | ||
3462 | * @param handled | ||
3463 | * The function that may throw an exception | ||
3464 | * | ||
3465 | * @return An exception-proofed supplier | ||
3466 | * | ||
3467 | * @throws E | ||
3468 | * The checked exception | ||
3469 | */ | ||
3470 | @Nonnull | ||
3471 | @SuppressWarnings("unused") | ||
3472 | public static <T, E extends Throwable> IntSupplier handleThrowing(@Nonnull EIntSupplier<E> handled) throws E { | ||
3473 | return () -> { | ||
3474 | try { | ||
3475 | return handled.getAsInt(); | ||
3476 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
3477 | throw asUnchecked(e); | ||
3478 | } | ||
3479 | }; | ||
3480 | } | ||
3481 | |||
2393 | // missing: handle EShortSupplier, blocked by: missing ToShortFunction | 3482 | // missing: handle EShortSupplier, blocked by: missing ToShortFunction |
2394 | 3483 | ||
2395 | /** | 3484 | /** |
@@ -2424,6 +3513,32 @@ public class EHandle { | |||
2424 | } | 3513 | } |
2425 | 3514 | ||
2426 | /** | 3515 | /** |
3516 | * Handles any exception types that may occur in the handled supplier by throwing it | ||
3517 | * explicitly. | ||
3518 | * | ||
3519 | * @param <E> | ||
3520 | * The handled function's exception type | ||
3521 | * @param handled | ||
3522 | * The function that may throw an exception | ||
3523 | * | ||
3524 | * @return An exception-proofed supplier | ||
3525 | * | ||
3526 | * @throws E | ||
3527 | * The checked exception | ||
3528 | */ | ||
3529 | @Nonnull | ||
3530 | @SuppressWarnings("unused") | ||
3531 | public static <T, E extends Throwable> ShortSupplier handleThrowing(@Nonnull EShortSupplier<E> handled) throws E { | ||
3532 | return () -> { | ||
3533 | try { | ||
3534 | return handled.getAsShort(); | ||
3535 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
3536 | throw asUnchecked(e); | ||
3537 | } | ||
3538 | }; | ||
3539 | } | ||
3540 | |||
3541 | /** | ||
2427 | * Handles a generic exception type that may occur in the handled function with a | 3542 | * Handles a generic exception type that may occur in the handled function with a |
2428 | * provided handler. | 3543 | * provided handler. |
2429 | * | 3544 | * |
@@ -2479,6 +3594,32 @@ public class EHandle { | |||
2479 | }; | 3594 | }; |
2480 | } | 3595 | } |
2481 | 3596 | ||
3597 | /** | ||
3598 | * Handles any exception types that may occur in the handled supplier by throwing it | ||
3599 | * explicitly. | ||
3600 | * | ||
3601 | * @param <E> | ||
3602 | * The handled function's exception type | ||
3603 | * @param handled | ||
3604 | * The function that may throw an exception | ||
3605 | * | ||
3606 | * @return An exception-proofed supplier | ||
3607 | * | ||
3608 | * @throws E | ||
3609 | * The checked exception | ||
3610 | */ | ||
3611 | @Nonnull | ||
3612 | @SuppressWarnings("unused") | ||
3613 | public static <T, E extends Throwable> LongSupplier handleThrowing(@Nonnull ELongSupplier<E> handled) throws E { | ||
3614 | return () -> { | ||
3615 | try { | ||
3616 | return handled.getAsLong(); | ||
3617 | } catch (Throwable e) { // NOSONAR can't catch generic exceptions | ||
3618 | throw asUnchecked(e); | ||
3619 | } | ||
3620 | }; | ||
3621 | } | ||
3622 | |||
2482 | private EHandle() {} | 3623 | private EHandle() {} |
2483 | 3624 | ||
2484 | } | 3625 | } |