Created
September 18, 2016 12:48
-
-
Save julianthome/41473cf2e2ad3bfa0eff7e0dd628bd8e to your computer and use it in GitHub Desktop.
A simple stop watch implemented in Java
This file contains 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
public class StopWatch { | |
long start; | |
long end; | |
long time; | |
long overallTime = 0; | |
public static StopWatch get() { | |
return new StopWatch(); | |
} | |
private StopWatch() { start = 0; end = 0; time = 0; overallTime = 0;} | |
public void start() { | |
this.start = System.currentTimeMillis(); | |
} | |
public long stop() { | |
this.end = System.currentTimeMillis(); | |
if(this.end > this.start) { | |
this.time = this.end - this.start; | |
} else { | |
this.time = 0L; | |
} | |
this.end = 0; this.start = 0; | |
this.overallTime += time; | |
return time; | |
} | |
public long getTime() { | |
return this.time; | |
} | |
public long getOverallTime() { | |
return this.overallTime; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment