Class Resolved<T>

java.lang.Object
org.springframework.pulsar.core.Resolved<T>
Type Parameters:
T - the resolved type

public final class Resolved<T> extends Object
A resolved value or an exception if it could not be resolved.
Author:
Christophe Bornet, Chris Bono, Jonas Geiregat
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    Gets the exception that may have occurred during resolution.
    static <T> Resolved<T>
    Factory method to create a Resolved when resolution fails.
    static <T> Resolved<T>
    failed(String reason)
    Factory method to create a Resolved when resolution fails.
    get()
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use value() instead
    int
     
    void
    ifResolved(Consumer<? super T> action)
    Performs the given action with the resolved value if a value was resolved and no exception occurred.
    void
    ifResolvedOrElse(Consumer<? super T> action, Consumer<RuntimeException> errorAction)
    Performs the given action with the resolved value if a non-null value was resolved and no exception occurred.
    static <T> Resolved<T>
    of(T value)
    Factory method to create a Resolved when resolution succeeds.
    Returns the resolved value if a value was resolved and no exception occurred, otherwise throws the resolution exception back to the caller.
    orElseThrow(Supplier<String> wrappingErrorMessage)
    Returns the resolved value if a value was resolved and no exception occurred, otherwise wraps the resolution exception with the provided error message and throws back to the caller.
     
    Gets the resolved value.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • of

      public static <T> Resolved<T> of(@Nullable T value)
      Factory method to create a Resolved when resolution succeeds.
      Type Parameters:
      T - the type of the value
      Parameters:
      value - the non-null resolved value
      Returns:
      a Resolved containing the resolved value
    • failed

      public static <T> Resolved<T> failed(String reason)
      Factory method to create a Resolved when resolution fails.
      Type Parameters:
      T - the type of the value
      Parameters:
      reason - the non-null reason the resolution failed
      Returns:
      a Resolved containing an IllegalArgumentException with the reason for the failure
    • failed

      public static <T> Resolved<T> failed(RuntimeException reason)
      Factory method to create a Resolved when resolution fails.
      Type Parameters:
      T - the type of the value
      Parameters:
      reason - the non-null reason the resolution failed
      Returns:
      a Resolved containing the reason for the failure
    • get

      @Deprecated(since="1.1.0", forRemoval=true) public Optional<T> get()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use value() instead
      Gets the optional resolved value.
      Returns:
      an optional with the resolved value or empty if failed to resolve
    • value

      public Optional<T> value()
      Gets the resolved value.
      Returns:
      an optional with the resolved value or empty if failed to resolve
    • exception

      public Optional<RuntimeException> exception()
      Gets the exception that may have occurred during resolution.
      Returns:
      an optional with the resolution exception or empty if no error occurred
    • ifResolved

      public void ifResolved(Consumer<? super T> action)
      Performs the given action with the resolved value if a value was resolved and no exception occurred.
      Parameters:
      action - the action to be performed
    • ifResolvedOrElse

      public void ifResolvedOrElse(Consumer<? super T> action, Consumer<RuntimeException> errorAction)
      Performs the given action with the resolved value if a non-null value was resolved and no exception occurred. Otherwise, if an exception occurred then the provided error action is performed with the exception.
      Parameters:
      action - the action to be performed
      errorAction - the error action to be performed
    • orElseThrow

      public T orElseThrow()
      Returns the resolved value if a value was resolved and no exception occurred, otherwise throws the resolution exception back to the caller.
      Returns:
      the resolved value if a value was resolved and no exception occurred
      Throws:
      RuntimeException - if an exception occurred during resolution
    • orElseThrow

      public T orElseThrow(Supplier<String> wrappingErrorMessage)
      Returns the resolved value if a value was resolved and no exception occurred, otherwise wraps the resolution exception with the provided error message and throws back to the caller.
      Parameters:
      wrappingErrorMessage - additional context to add to the wrapped exception
      Returns:
      the resolved value if a value was resolved and no exception occurred
      Throws:
      RuntimeException - wrapping the resolution exception if an exception occurred during resolution
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object