Class Try.Failure<V>

java.lang.Object
org.junit.platform.commons.function.Try<V>
org.junit.platform.commons.function.Try.Failure<V>
Enclosing class:
Try<V>

private static class Try.Failure<V> extends Try<V>
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.junit.platform.commons.function.Try

    Try.Transformer<S,T>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Exception
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <U> Try<U>
    andThen(Function<V,Try<U>> function)
    If this Try is a success, apply the supplied function to its value and return the resulting Try; if this Try is a failure, do nothing.
    <U> Try<U>
    andThenTry(Try.Transformer<V,U> transformer)
    If this Try is a success, apply the supplied transformer to its value and return a new successful or failed Try depending on the transformer's outcome; if this Try is a failure, do nothing.
    boolean
    equals(Object that)
     
    get()
    If this Try is a success, get the contained value; if this Try is a failure, throw the contained exception.
    <E extends Exception>
    V
    getOrThrow(Function<? super Exception,E> exceptionTransformer)
    If this Try is a success, get the contained value; if this Try is a failure, call the supplied Function with the contained exception and throw the resulting Exception.
    int
     
    ifFailure(Consumer<Exception> causeConsumer)
    If this Try is a failure, call the supplied Consumer with the contained exception; otherwise, do nothing.
    ifSuccess(Consumer<V> valueConsumer)
    If this Try is a success, call the supplied Consumer with the contained value; otherwise, do nothing.
    orElse(Supplier<Try<V>> supplier)
    If this Try is a failure, call the supplied supplier and return the resulting Try; if this Try is a success, do nothing.
    orElseTry(Callable<V> action)
    If this Try is a failure, call the supplied action and return a new successful or failed Try depending on the action's outcome; if this Try is a success, do nothing.
    If this Try is a failure, return an empty Optional; if this Try is a success, wrap the contained value using Optional.ofNullable(Object).
    private <U> Try<U>
     

    Methods inherited from class org.junit.platform.commons.function.Try

    call, failure, success

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • andThenTry

      public <U> Try<U> andThenTry(Try.Transformer<V,U> transformer)
      Description copied from class: Try
      If this Try is a success, apply the supplied transformer to its value and return a new successful or failed Try depending on the transformer's outcome; if this Try is a failure, do nothing.
      Specified by:
      andThenTry in class Try<V>
      Parameters:
      transformer - the transformer to try; must not be null
      Returns:
      a succeeded or failed Try; never null
    • andThen

      public <U> Try<U> andThen(Function<V,Try<U>> function)
      Description copied from class: Try
      If this Try is a success, apply the supplied function to its value and return the resulting Try; if this Try is a failure, do nothing.
      Specified by:
      andThen in class Try<V>
      Parameters:
      function - the function to apply; must not be null
      Returns:
      a succeeded or failed Try; never null
    • uncheckedCast

      private <U> Try<U> uncheckedCast()
    • orElseTry

      public Try<V> orElseTry(Callable<V> action)
      Description copied from class: Try
      If this Try is a failure, call the supplied action and return a new successful or failed Try depending on the action's outcome; if this Try is a success, do nothing.
      Specified by:
      orElseTry in class Try<V>
      Parameters:
      action - the action to try; must not be null
      Returns:
      a succeeded or failed Try; never null
    • orElse

      public Try<V> orElse(Supplier<Try<V>> supplier)
      Description copied from class: Try
      If this Try is a failure, call the supplied supplier and return the resulting Try; if this Try is a success, do nothing.
      Specified by:
      orElse in class Try<V>
      Parameters:
      supplier - the supplier to call; must not be null
      Returns:
      a succeeded or failed Try; never null
    • get

      public V get() throws Exception
      Description copied from class: Try
      If this Try is a success, get the contained value; if this Try is a failure, throw the contained exception.
      Specified by:
      get in class Try<V>
      Returns:
      the contained value, if available; potentially null
      Throws:
      Exception - if this Try is a failure
    • getOrThrow

      public <E extends Exception> V getOrThrow(Function<? super Exception,E> exceptionTransformer) throws E
      Description copied from class: Try
      If this Try is a success, get the contained value; if this Try is a failure, call the supplied Function with the contained exception and throw the resulting Exception.
      Specified by:
      getOrThrow in class Try<V>
      Parameters:
      exceptionTransformer - the transformer to be called with the contained exception, if available; must not be null
      Returns:
      the contained value, if available
      Throws:
      E - if this Try is a failure
    • ifSuccess

      public Try<V> ifSuccess(Consumer<V> valueConsumer)
      Description copied from class: Try
      If this Try is a success, call the supplied Consumer with the contained value; otherwise, do nothing.
      Specified by:
      ifSuccess in class Try<V>
      Parameters:
      valueConsumer - the consumer to be called with the contained value, if available; must not be null
      Returns:
      the same Try for method chaining
    • ifFailure

      public Try<V> ifFailure(Consumer<Exception> causeConsumer)
      Description copied from class: Try
      If this Try is a failure, call the supplied Consumer with the contained exception; otherwise, do nothing.
      Specified by:
      ifFailure in class Try<V>
      Parameters:
      causeConsumer - the consumer to be called with the contained exception, if available; must not be null
      Returns:
      the same Try for method chaining
    • toOptional

      public Optional<V> toOptional()
      Description copied from class: Try
      If this Try is a failure, return an empty Optional; if this Try is a success, wrap the contained value using Optional.ofNullable(Object).
      Specified by:
      toOptional in class Try<V>
      Returns:
      an Optional; never null but potentially empty
    • equals

      public boolean equals(Object that)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object