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

fr.jcgay.maven.profiler.KnownElapsedTimeTicker Maven / Gradle / Ivy

There is a newer version: 3.2
Show newest version
package fr.jcgay.maven.profiler;

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

public class KnownElapsedTimeTicker extends Ticker {

    private final long expectedElapsedTime;
    private boolean firstRead;

    public KnownElapsedTimeTicker(long expectedElapsedTime) {
        this.expectedElapsedTime = expectedElapsedTime;
    }

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy