Interface SecpResult<T>
- Type Parameters:
T- type of the return value in a successful result
- All Known Implementing Classes:
SecpResult.Err, SecpResult.Ok
public interface SecpResult<T>
Functional-style result for secp256k1 -- either
SecpResult.Ok or SecpResult.Err.
If result is Ok the return value is in SecpResult.Ok.result(), if a failure
occurred the error code is in SecpResult.Err.code().
The error code (or return value
as it is called in the C API) for OK or
success
is 1. For almost all calls the error code for failure
is 0 -- so the behavior is similar to a boolean. However, the C API uses
a (C) `int`, so we return a (Java) `int` for future compatibility.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classAn error result, with aninterror code inSecpResult.Err.code().static final classA successful result containing a value of type<T>inSecpResult.Ok.result(). -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> SecpResult<T> Create a result from an error code and a supplier function.static <T> SecpResult<T> err(int error_code) Static constructor forSecpResult.Errdefault intReturn the error codedefault Tget()Get the result value or throw aRuntimeExceptiondefault TGet the result value or throw aRuntimeExceptiondefault booleanisOk()Is the result successful (SecpResult.Ok)?static <T> SecpResult<T> ok(T result) Static constructor forSecpResult.Ok
-
Field Details
-
OK
static final int OKError return integer value for success- See Also:
-
-
Method Details
-
isOk
default boolean isOk()Is the result successful (SecpResult.Ok)?- Returns:
- true if result is
instanceofSecpResult.Ok
-
errorCode
-
ok
Static constructor forSecpResult.Ok- Type Parameters:
T- result type- Parameters:
result- result value- Returns:
- successful result
-
err
Static constructor forSecpResult.Err- Type Parameters:
T- expected result type- Parameters:
error_code- error code- Returns:
- error result
-
checked
Create a result from an error code and a supplier function. If the error code is1(OK), the supplier function is invoked to produce a successful result. Otherwise, an error result is returned containing the error code.- Type Parameters:
T- result value type- Parameters:
error_code- error codesupplier- value supplier- Returns:
- result
-
get
-
get
Get the result value or throw aRuntimeException- Parameters:
message- error message to include in exception- Returns:
- result value
-