Skip to content

Instantly share code, notes, and snippets.

@forax
Created May 11, 2014 15:28
Show Gist options
  • Save forax/48b51fb2924c7773e159 to your computer and use it in GitHub Desktop.
Save forax/48b51fb2924c7773e159 to your computer and use it in GitHub Desktop.
import java.util.OptionalLong;
public class TimeStat {
private long totalTime;
private long recordCount;
private long minimumTime;
public void record(long elapsedTime) {
totalTime += elapsedTime;
minimumTime = (recordCount == 0)? elapsedTime: Math.min(minimumTime, elapsedTime);
recordCount++;
}
public double getAverageTime() {
return ((double)totalTime) / recordCount;
}
public OptionalLong getMinimumTime() {
if (recordCount == 0) {
return OptionalLong.empty();
}
return OptionalLong.of(minimumTime);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment