Record Class FetchResult<T>

java.lang.Object
java.lang.Record
org.cy3sbml.util.FetchResult<T>

public record FetchResult<T>(FetchStatus status, Optional<T> value) extends Record
The result of a fetch: its FetchStatus and the value, if found.

The value is present if, and only if, the status is FetchStatus.FOUND. A fetch that got no value (e.g. an empty or missing response body) is an error, not a found null: callers map it to error() before creating a result.

  • Constructor Summary

    Constructors
    Constructor
    Description
    FetchResult(FetchStatus status, Optional<T> value)
    Creates an instance of a FetchResult record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    static <T> FetchResult<T>
    A transient error, e.g. a timeout, which is not cached.
    static <T> FetchResult<T>
    found(T value)
    A found value.
    final int
    Returns a hash code value for this object.
    static <T> FetchResult<T>
    A deterministic "not found", e.g. an HTTP 404, which may be cached for a short time.
    Returns the value of the status record component.
    final String
    Returns a string representation of this record class.
    Returns the value of the value record component.

    Methods inherited from class java.lang.Object

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

    • FetchResult

      public FetchResult(FetchStatus status, Optional<T> value)
      Creates an instance of a FetchResult record class.
      Parameters:
      status - the value for the status record component
      value - the value for the value record component
  • Method Details

    • found

      public static <T> FetchResult<T> found(T value)
      A found value.
      Throws:
      IllegalArgumentException - if value is null: a fetch without a value is an error()
    • notFound

      public static <T> FetchResult<T> notFound()
      A deterministic "not found", e.g. an HTTP 404, which may be cached for a short time.
      Type Parameters:
      T - the value type
      Returns:
      the result
    • error

      public static <T> FetchResult<T> error()
      A transient error, e.g. a timeout, which is not cached.
      Type Parameters:
      T - the value type
      Returns:
      the result
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • status

      public FetchStatus status()
      Returns the value of the status record component.
      Returns:
      the value of the status record component
    • value

      public Optional<T> value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component