Skip to content

Instantly share code, notes, and snippets.

@adamv
Created August 11, 2014 18:43
Show Gist options
  • Select an option

  • Save adamv/5a7c4d9ceb456c76da6c to your computer and use it in GitHub Desktop.

Select an option

Save adamv/5a7c4d9ceb456c76da6c to your computer and use it in GitHub Desktop.
/**
* 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