Class CallResult.FailureProjection<L,​R>

java.lang.Object
com.github.badpop.jcoinbase.control.CallResult.FailureProjection<L,​R>
Type Parameters:
L - The type of the Failure value of a CallResult.
R - The type of the Success value of a CallResult.
All Implemented Interfaces:
FunctionalValue<L>, java.lang.Iterable<L>
Enclosing class:
CallResult<L,​R>

public static final class CallResult.FailureProjection<L,​R>
extends java.lang.Object
implements FunctionalValue<L>
A failure projection of a CallResult.
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Description copied from interface: FunctionalValue
      Checks, this Value is empty, i.e. if the underlying functionalValue is absent.
      Specified by:
      isEmpty in interface FunctionalValue<L>
      Returns:
      false, if no underlying functionalValue is present, true otherwise.
    • get

      public L get()
      Gets the Failure value or throws.
      Specified by:
      get in interface FunctionalValue<L>
      Returns:
      the failure value, if the underlying CallResult is a Failure
      Throws:
      java.util.NoSuchElementException - if the underlying CallResult of this FailureProjection is a Success
    • orElse

      public CallResult.FailureProjection<L,​R> orElse​(CallResult.FailureProjection<? extends L,​? extends R> other)
    • orElse

      public CallResult.FailureProjection<L,​R> orElse​(java.util.function.Supplier<? extends CallResult.FailureProjection<? extends L,​? extends R>> supplier)
    • getOrElse

      public L getOrElse​(L other)
      Gets the Failure value or an alternate value, if the projected CallResult is a Success.
      Specified by:
      getOrElse in interface FunctionalValue<L>
      Parameters:
      other - an alternative value
      Returns:
      the failure value, if the underlying CallResult is a Failure or else other
      Throws:
      java.util.NoSuchElementException - if the underlying callResult of this FailureProjection is a Success
    • getOrElseGet

      public L getOrElseGet​(java.util.function.Function<? super R,​? extends L> other)
      Gets the Failure value or an alternate value, if the projected CallResult is a Success.
      Parameters:
      other - a function which converts a Success value to an alternative Failure value
      Returns:
      the failure value, if the underlying CallResult is a Failure or else the alternative Failure value provided by other by applying the Success value.
    • orElseRun

      public void orElseRun​(java.util.function.Consumer<? super R> action)
      Runs an action in the case this is a projection on a Success value.
      Parameters:
      action - an action which consumes a Success value
    • getOrElseThrow

      public <X extends java.lang.Throwable> L getOrElseThrow​(java.util.function.Function<? super R,​X> exceptionFunction) throws X extends java.lang.Throwable
      Gets the Failure value or throws, if the projected CallResult is a Success.
      Type Parameters:
      X - a throwable type
      Parameters:
      exceptionFunction - a function which creates an exception based on a Success value
      Returns:
      the failure value, if the underlying CallResult is a Failure or else throws the exception provided by exceptionFunction by applying the Success value.
      Throws:
      X - if the projected CallResult is a Success
    • toCallResult

      public CallResult<L,​R> toCallResult()
      Returns the underlying callResult of this projection.
      Returns:
      the underlying callResult
    • filter

      public io.vavr.control.Option<CallResult.FailureProjection<L,​R>> filter​(java.util.function.Predicate<? super L> predicate)
      Returns Some value of type L if this is a failure projection of a Failure value and the predicate applies to the underlying value.
      Parameters:
      predicate - A predicate
      Returns:
      A new Option
    • flatMap

      public <U> CallResult.FailureProjection<U,​R> flatMap​(java.util.function.Function<? super L,​? extends CallResult.FailureProjection<? extends U,​R>> mapper)
      FlatMaps this FailureProjection.
      Type Parameters:
      U - Component type of the mapped failure value
      Parameters:
      mapper - A mapper
      Returns:
      this as FailureProjection<L, U> if a Success is underlying, otherwise a the mapping result of the failure value.
      Throws:
      java.lang.NullPointerException - if mapper is null
    • map

      public <U> CallResult.FailureProjection<U,​R> map​(java.util.function.Function<? super L,​? extends U> mapper)
      Maps the failure value if the projected CallResult is a Failure.
      Specified by:
      map in interface FunctionalValue<L>
      Type Parameters:
      U - The new type of a Failure value
      Parameters:
      mapper - A mapper which takes a failure value and returns a value of type U
      Returns:
      A new FailureProjection
    • peek

      public CallResult.FailureProjection<L,​R> peek​(java.util.function.Consumer<? super L> action)
      Applies the given action to the value if the projected callResult is a Failure. Otherwise nothing happens.
      Specified by:
      peek in interface FunctionalValue<L>
      Parameters:
      action - An action which takes a failure value
      Returns:
      this FailureProjection
    • transform

      public <U> U transform​(java.util.function.Function<? super CallResult.FailureProjection<L,​R>,​? extends U> f)
      Transforms this FailureProjection.
      Type Parameters:
      U - Type of transformation result
      Parameters:
      f - A transformation
      Returns:
      An instance of type U
      Throws:
      java.lang.NullPointerException - if f is null
    • iterator

      public io.vavr.collection.Iterator<L> iterator()
      Description copied from interface: FunctionalValue
      Returns a rich io.vavr.collection.Iterator.
      Specified by:
      iterator in interface FunctionalValue<L>
      Specified by:
      iterator in interface java.lang.Iterable<L>
      Returns:
      A new Iterator
    • 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