EpicHeads/main/java/com/songoda/epicheads/util/Clock.java
Brianna O'Keefe 83a77b3578 Replaced existing commandManager with my CommandManager v2
Replaced localization system with mine.
2018-09-20 21:42:20 -04:00

43 lines
877 B
Java

package com.songoda.epicheads.util;
import java.text.DecimalFormat;
public class Clock {
private static final DecimalFormat millisecondsFormat = new DecimalFormat("#.##");
private final long start;
private long end;
public Clock() {
this.start = System.nanoTime();
this.end = -1;
}
public boolean hasEnded() {
return end >= 0;
}
public String stop() {
Checks.ensureTrue(!hasEnded(), "Timer has already been stopped.");
this.end = System.nanoTime();
return toString();
}
public double getDuration() {
return (hasEnded() ? end - start : System.nanoTime() - start) / 1e6;
}
@Override
public String toString() {
return "(" + millisecondsFormat.format(getDuration()) + " ms)";
}
public static Clock start() {
return new Clock();
}
}