Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Counter implements Comparable<Counter> {
- private volatile long value;
- public long getValue() {
- return value;
- }
- public synchronized void reset() {
- value = 0;
- notifyAll();
- }
- public synchronized void incr() {
- value++;
- notifyAll();
- }
- public synchronized void decr() {
- value--;
- notifyAll();
- }
- @Override
- public int hashCode() {
- return 17 + (int) (this.value ^ (this.value >>> 32));
- }
- @Override
- public boolean equals(Object o) {
- return o instanceof Counter && ((Counter)o).value == value;
- }
- @Override
- public int compareTo(Counter o) {
- if( o.value > value )
- return -1;
- else if( o.value < value )
- return 1;
- else
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement