Class CallResult.Failure<L,​R>

java.lang.Object
com.github.badpop.jcoinbase.control.CallResult<L,​R>
com.github.badpop.jcoinbase.control.CallResult.Failure<L,​R>
Type Parameters:
L - failure component type
R - success component type
All Implemented Interfaces:
FunctionalValue<R>, java.io.Serializable, java.lang.Iterable<R>
Enclosing class:
CallResult<L,​R>

public static final class CallResult.Failure<L,​R>
extends CallResult<L,​R>
implements java.io.Serializable
The Failure version of a CallResult.
See Also:
Serialized Form
  • Method Details

    • get

      public R get()
      Description copied from interface: FunctionalValue
      Gets the underlying functionalValue or throws if no functionalValue is present.

      IMPORTANT! This method will throw an undeclared Throwable if isEmpty() == true is true.

      Because the 'empty' state indicates that there is no functionalValue present that can be returned, get() has to throw in such a case. Generally, implementing classes should throw a NoSuchElementException if isEmpty() returns true.

      However, there exist use-cases, where implementations may throw other exceptions. See Try.get().

      Additional note: Dynamic proxies will wrap an undeclared exception in a UndeclaredThrowableException.

      Specified by:
      get in interface FunctionalValue<L>
      Returns:
      the underlying functionalValue if this is not empty, otherwise get() throws a Throwable
    • isSuccess

      public boolean isSuccess()
      Description copied from class: CallResult
      Returns whether this CallResult is a Success.
      
       // prints "true"
       System.out.println(CallResult.success(42).isSuccess());
      
       // prints "false"
       System.out.println(CallResult.failure("error").isSuccess());
       
      Specified by:
      isSuccess in class CallResult<L,​R>
      Returns:
      true, if this is a Success, false otherwise
    • isFailure

      public boolean isFailure()
      Description copied from class: CallResult
      Returns whether this CallResult is a Failure.
      
       // prints "true"
       System.out.println(CallResult.failure("error").isFailure());
      
       // prints "false"
       System.out.println(CallResult.success(42).isFailure());
       
      Specified by:
      isFailure in class CallResult<L,​R>
      Returns:
      true, if this is a Failure, false otherwise
    • getFailure

      public L getFailure()
      Description copied from class: CallResult
      Returns the failure value.
      
       // prints "error"
       System.out.println(CallResult.failure("error").getFailure());
      
       // throws NoSuchElementException
       System.out.println(CallResult.success(42).getFailure());
       
      Specified by:
      getFailure in class CallResult<L,​R>
      Returns:
      The failure value.
    • equals

      public boolean equals​(java.lang.Object obj)
      Description copied from interface: FunctionalValue
      Clarifies that functionalValues have a proper equals() method implemented.

      See Object.equals(Object).

      Specified by:
      equals in interface FunctionalValue<L>
      Overrides:
      equals in class java.lang.Object
      Parameters:
      obj - An object
      Returns:
      true, if this equals o, false otherwise
    • hashCode

      public int hashCode()
      Description copied from interface: FunctionalValue
      Clarifies that functionalValues have a proper hashCode() method implemented.

      See Object.hashCode().

      Specified by:
      hashCode in interface FunctionalValue<L>
      Overrides:
      hashCode in class java.lang.Object
      Returns:
      The hashcode of this object