Package org.swisspush.gateleen.core.util
Class Result<TOk,TErr>
- java.lang.Object
-
- org.swisspush.gateleen.core.util.Result<TOk,TErr>
-
public final class Result<TOk,TErr> extends Object
A result inspired by rust. See https://doc.rust-lang.org/stable/std/result/enum.Result.htmlA result is either successful (ok) or unsuccessful (error). All values should be immutable. Does NOT support null values. Implements equals / hashcode / toString and is immutable.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceResult.Handler<TOk,TErr>static interfaceResult.RetHandler<TOk,TErr,R>
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)TErrerr()static <TOk,TErr>
Result<TOk,TErr>err(TErr value)voidhandle(Result.Handler<TOk,TErr> handler)<R> Rhandle(Result.RetHandler<TOk,TErr,R> handler)inthashCode()voidifOk(Consumer<TOk> okHandler)booleanisErr()booleanisOk()<T> Result<T,TErr>mapOk(Function<TOk,T> mapFunction)If this is in error state, just returns a result with the same error.TOkok()See https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.unwrap Returns the ok result or throws if this result is in error state.static <TOk,TErr>
Result<TOk,TErr>ok(TOk value)Optional<TOk>okOptional()Returns present if ok or absent if error.StringtoString()
-
-
-
Method Detail
-
ok
public static <TOk,TErr> Result<TOk,TErr> ok(TOk value)
-
err
public static <TOk,TErr> Result<TOk,TErr> err(TErr value)
-
isOk
public boolean isOk()
-
ok
public TOk ok() throws IllegalStateException
See https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.unwrap Returns the ok result or throws if this result is in error state.- Throws:
IllegalStateException
-
isErr
public boolean isErr()
-
err
public TErr err() throws IllegalStateException
- Throws:
IllegalStateException
-
handle
public <R> R handle(Result.RetHandler<TOk,TErr,R> handler)
-
handle
public void handle(Result.Handler<TOk,TErr> handler)
-
mapOk
public <T> Result<T,TErr> mapOk(Function<TOk,T> mapFunction)
If this is in error state, just returns a result with the same error. If it's in OK state, maps the OK value using the map function.
-
-