com.github.simonharmonicminor.juu.measure.ExecutionResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-useful-utils Show documentation
Show all versions of java-useful-utils Show documentation
Just some useful utils for everyday coding
package com.github.simonharmonicminor.juu.measure;
/**
* A class which contains the result of function execution and time spent for it
*
* @param function result type
* @see Measure
* @see MeasureUnit
* @since 0.1
*/
public class ExecutionResult {
private static final ExecutionResult> FAILED = new ExecutionResult<>(null, -1, null);
private final T result;
private final long time;
private final MeasureUnit measureUnit;
/**
* Returns an immutable instance which defines that measurement has failed
* @param function return type
* @return a failed result instance
*/
public static ExecutionResult failed() {
return (ExecutionResult) FAILED;
}
public ExecutionResult(T result, long time, MeasureUnit measureUnit) {
this.result = result;
this.time = time;
this.measureUnit = measureUnit;
}
/**
* Check whether execution result was failed or not
* @return true if measurement has failed
*/
public boolean isFailed() {
return this == FAILED;
}
/**
* @return function result
*/
public T getResult() {
return result;
}
/**
* @return time spent
*/
public long getTime() {
return time;
}
/**
* @return measure unit
*/
public MeasureUnit getMeasureUnit() {
return measureUnit;
}
}