Class Try.Success<V>

  • Enclosing class:
    Try<V>

    private static class Try.Success<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 V value  
    • Constructor Summary

      Constructors 
      Constructor Description
      Success​(V value)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <U> Try<U> andThen​(java.util.function.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​(java.lang.Object that)  
      V get()
      If this Try is a success, get the contained value; if this Try is a failure, throw the contained exception.
      <E extends java.lang.Exception>
      V
      getOrThrow​(java.util.function.Function<? super java.lang.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 hashCode()  
      Try<V> ifFailure​(java.util.function.Consumer<java.lang.Exception> causeConsumer)
      If this Try is a failure, call the supplied Consumer with the contained exception; otherwise, do nothing.
      Try<V> ifSuccess​(java.util.function.Consumer<V> valueConsumer)
      If this Try is a success, call the supplied Consumer with the contained value; otherwise, do nothing.
      Try<V> orElse​(java.util.function.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.
      Try<V> orElseTry​(java.util.concurrent.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.
      java.util.Optional<V> toOptional()
      If this Try is a failure, return an empty Optional; if this Try is a success, wrap the contained value using Optional.ofNullable(Object).
      • Methods inherited from class java.lang.Object

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

      • value

        private final V value
    • Constructor Detail

      • Success

        Success​(V value)
    • Method Detail

      • 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​(java.util.function.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
      • orElseTry

        public Try<V> orElseTry​(java.util.concurrent.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​(java.util.function.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()
        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
      • getOrThrow

        public <E extends java.lang.Exception> V getOrThrow​(java.util.function.Function<? super java.lang.Exception,​E> exceptionTransformer)
        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
      • ifSuccess

        public Try<V> ifSuccess​(java.util.function.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​(java.util.function.Consumer<java.lang.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 java.util.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​(java.lang.Object that)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object