Created
May 11, 2014 15:28
-
-
Save forax/48b51fb2924c7773e159 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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