Class Timing.TimedWithErrorOrResult<R>

java.lang.Object
org.kiwiproject.beta.time.Timing.TimedWithErrorOrResult<R>
Type Parameters:
R - the result type
All Implemented Interfaces:
Timing.TimedWithError
Enclosing class:
Timing

public static final class Timing.TimedWithErrorOrResult<R> extends Object implements Timing.TimedWithError
Represents an operation that is timed and returns a (possibly null) result, but may throw an exception.
  • Method Details

    • ofResult

      public static <R> Timing.TimedWithErrorOrResult<R> ofResult(long elapsedNanos, R result)
      Create a new instance containing a result.
      Type Parameters:
      R - the result type
      Parameters:
      elapsedNanos - the number of nanoseconds that elapsed during the operation
      result - the result of the operation; may be null
      Returns:
      a new instance representing a successful operation
    • ofException

      public static <R> Timing.TimedWithErrorOrResult<R> ofException(long elapsedNanos, RuntimeException exception)
      Create a new instance containing an exception.
      Type Parameters:
      R - the result type
      Parameters:
      elapsedNanos - the number of nanoseconds that elapsed during the operation
      exception - the exception thrown by the operation
      Returns:
      a new instance representing a failed operation
    • hasResult

      public boolean hasResult()
      Returns:
      true if the operation succeeded and contains a (possibly null) result
    • getResult

      public Optional<R> getResult()
      Returns:
      an Optional that will contain a (possibly null) result when the operation succeeds. If called when the operation failed, an empty Optional is always returned.
    • isNullResult

      public boolean isNullResult()
      Returns:
      true if the operation completed without exception and the actual result is null.
    • getException

      public Optional<RuntimeException> getException()
      Specified by:
      getException in interface Timing.TimedWithError
      Returns:
      an Optional that will contain a RuntimeException if the operation failed. If called when the operation succeeded, an empty Optional is always returned.
    • getElapsedNanos

      public long getElapsedNanos()
      Specified by:
      getElapsedNanos in interface Timing.TimedWithError
      Returns:
      the number of nanoseconds that elapsed during the operation
    • 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