Package org.kiwiproject.beta.time
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 Summary
Modifier and TypeMethodDescriptionbooleanlonginthashCode()booleanbooleanstatic <R> Timing.TimedWithErrorOrResult<R>ofException(long elapsedNanos, RuntimeException exception) Create a new instance containing an exception.static <R> Timing.TimedWithErrorOrResult<R>ofResult(long elapsedNanos, R result) Create a new instance containing a result.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.kiwiproject.beta.time.Timing.TimedWithError
getElapsedMillis, hasException, operationSucceeded
-
Method Details
-
ofResult
Create a new instance containing a result.- Type Parameters:
R- the result type- Parameters:
elapsedNanos- the number of nanoseconds that elapsed during the operationresult- 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 operationexception- 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
- 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
- Specified by:
getExceptionin interfaceTiming.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:
getElapsedNanosin interfaceTiming.TimedWithError- Returns:
- the number of nanoseconds that elapsed during the operation
-
equals
-
hashCode
public int hashCode() -
toString
-