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

com.central1.profiler.KnownElapsedTimeTicker Maven / Gradle / Ivy

The newest version!
package com.central1.profiler;

import com.google.common.base.Stopwatch;
import com.google.common.base.Ticker;

/**
 * Full credit to jcgay on github for the original maven-profiler
 *
 * Licensed under MIT
 *
 * Modifications by Delan Elliot ([email protected])
 */
public class KnownElapsedTimeTicker extends Ticker {

    private final long expectedElapsedTime;
    private boolean firstRead;

    /**
     *
     * @param expectedElapsedTime
     */
    public KnownElapsedTimeTicker(long expectedElapsedTime) {
        this.expectedElapsedTime = expectedElapsedTime;
    }

    /**
     *
     * @param elapsedTime
     * @return
     */
    public static Stopwatch aStopWatchWithElapsedTime(long elapsedTime) {
        return new Stopwatch(new KnownElapsedTimeTicker(elapsedTime)).start().stop();
    }

    /**
     *
     * @return
     */
    @Override
    public long read() {
        firstRead = !firstRead;
        return firstRead ? 0 : expectedElapsedTime;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy