Created
August 11, 2014 18:43
-
-
Save adamv/5a7c4d9ceb456c76da6c 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
| /** | |
| * A Counter can issue sequential ids, and return the largest id issued so far. | |
| */ | |
| public class Counter { | |
| private long nextValue = 0; | |
| /** | |
| * @return the next value from this counter. | |
| */ | |
| public long nextValue() { | |
| final long thisValue = nextValue; | |
| nextValue++; | |
| return thisValue; | |
| } | |
| /** | |
| * @return the highest value returned so far by this counter. | |
| */ | |
| public long maxValueAssigned() { | |
| return nextValue - 1; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment