All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.simonharmonicminor.juu.measure.ExecutionResult Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy