Class LambdaExceptionUtil
- java.lang.Object
-
- org.openmetadata.service.util.LambdaExceptionUtil
-
public final class LambdaExceptionUtil extends Object
Utility class for the streams API.Wraps consumers and functions into interfaces that can throw Checked Exceptions
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceLambdaExceptionUtil.ComparatorWithExceptions<T,E extends Exception>static interfaceLambdaExceptionUtil.ConsumerWithExceptions<T,E extends Exception>static interfaceLambdaExceptionUtil.FunctionWithExceptions<T,R,E extends Exception>
-
Constructor Summary
Constructors Constructor Description LambdaExceptionUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,E extends Exception>
Comparator<T>ignoringComparator(LambdaExceptionUtil.ComparatorWithExceptions<T,E> comparator)Wrap a standardComparator, swallowing allException.static <T,E extends Exception>
Comparator<T>rethrowComparator(LambdaExceptionUtil.ComparatorWithExceptions<T,E> comparator)Wrap a standardComparatorin aLambdaExceptionUtil.ComparatorWithExceptions.static <T,E extends Exception>
Consumer<T>rethrowConsumer(LambdaExceptionUtil.ConsumerWithExceptions<T,E> consumer)Wrap a standardConsumerin aLambdaExceptionUtil.ConsumerWithExceptions.static <T,R,E extends Exception>
Function<T,R>rethrowFunction(LambdaExceptionUtil.FunctionWithExceptions<T,R,E> function)Wrap a standardFunctionin aLambdaExceptionUtil.FunctionWithExceptions.
-
-
-
Method Detail
-
rethrowConsumer
public static <T,E extends Exception> Consumer<T> rethrowConsumer(LambdaExceptionUtil.ConsumerWithExceptions<T,E> consumer)
Wrap a standardConsumerin aLambdaExceptionUtil.ConsumerWithExceptions.This allows a consumer to throw Checked Exception that will be propagated to the context of the statement calling it
Example:
Stream.of("java.lang.String", "java.bad.Class").forEach(rethrowConsumer(name -> System.out.println(Class.forName(name))));throws checkedClassNotFoundException
-
rethrowFunction
public static <T,R,E extends Exception> Function<T,R> rethrowFunction(LambdaExceptionUtil.FunctionWithExceptions<T,R,E> function)
Wrap a standardFunctionin aLambdaExceptionUtil.FunctionWithExceptions.This allows a lambda function to throw Checked Exception that will be propagated to the context of the statement calling it
Example:
Stream.of("java.lang.String", "java.bad.Class").map(rethrowFunction(Class::forName)));throws checkedClassNotFoundException
-
rethrowComparator
public static <T,E extends Exception> Comparator<T> rethrowComparator(LambdaExceptionUtil.ComparatorWithExceptions<T,E> comparator)
Wrap a standardComparatorin aLambdaExceptionUtil.ComparatorWithExceptions.This allows a comparator to propagate a Checked Exception
Example:
List.of("java.lang.String", "java.lang.Integer", "java.bad.Class").sorted((c1, c2) -> Class.forName(c1).getFields().length - Class.forName(c2).getFields().lengththrows checkedClassNotFoundException
-
ignoringComparator
public static <T,E extends Exception> Comparator<T> ignoringComparator(LambdaExceptionUtil.ComparatorWithExceptions<T,E> comparator)
Wrap a standardComparator, swallowing allException.WARNING! WhenComparator.compare(T, T)throws an exception the elements are treated as equal. This should only be used for ignoring checked exceptions that can never be throws.
-
-