Class TryWithResult<O>
- java.lang.Object
-
- dev.pcvolkmer.mv64e.datamapper.mapper.exceptionhandler.AbstractLoggable
-
- dev.pcvolkmer.mv64e.datamapper.mapper.exceptionhandler.TryWithResult<O>
-
- All Implemented Interfaces:
Catchable
@NullMarked public class TryWithResult<O> extends AbstractLoggable implements Catchable
A try/catch chain with an expected result- Since:
- 0.2
-
-
Field Summary
-
Fields inherited from class dev.pcvolkmer.mv64e.datamapper.mapper.exceptionhandler.AbstractLoggable
logger
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TryandTry(java.util.function.Consumer<O> consumer)Try to consume last result or resend exception.<T> TryWithResult<T>andTryWithResult(java.util.function.Function<O,T> function)Try another function and update result or resend exception.TryWithResult<O>elseCatch(java.util.function.Consumer<IgnorableMappingException> exceptionConsumer)Consume exception if present.TryWithResult<O>elseThrow()Throws exception if present.@Nullable IgnorableMappingExceptiongetException()Get the exception if any.java.util.Optional<@Nullable O>ok()Get the result as optional.@Nullable OokOrNull()Get the result or null.
-
-
-
Method Detail
-
andTryWithResult
public <T> TryWithResult<T> andTryWithResult(java.util.function.Function<O,T> function)
Try another function and update result or resend exception.- Type Parameters:
T- The expected return type- Parameters:
function- The function to be executed- Returns:
- TryWithResult for further processing
-
andTry
public Try andTry(java.util.function.Consumer<O> consumer)
Try to consume last result or resend exception.- Parameters:
consumer- The consumer to be executed- Returns:
- Try for further processing
-
elseThrow
public TryWithResult<O> elseThrow()
Throws exception if present.- Returns:
- TryWithResult for further processing
-
elseCatch
public TryWithResult<O> elseCatch(java.util.function.Consumer<IgnorableMappingException> exceptionConsumer)
Consume exception if present.- Parameters:
exceptionConsumer- The consumer to be executed with the exception- Returns:
- TryWithResult for further processing
-
ok
public java.util.Optional<@Nullable O> ok()
Get the result as optional.- Returns:
- The result as optional
-
okOrNull
public @Nullable O okOrNull()
Get the result or null.- Returns:
- The result as optional
-
getException
public @Nullable IgnorableMappingException getException()
Get the exception if any.- Specified by:
getExceptionin interfaceCatchable- Returns:
- The exception if any
-
-