Counter.java
jmud-0.11/src/Counter.java · 647 B
From the archive jmud-0_11.tgz
Download the archive « Back to the archive contents
class Counter {
private int value;
Counter() {
set(0);
}
Counter(int v) {
set(v);
}
void set(int v) {
value = v;
}
synchronized void inc(int increment) {
value += increment;
}
synchronized void inc() {
++value;
}
synchronized void dec(int decrement) {
value -= decrement;
}
synchronized void dec() {
--value;
}
synchronized boolean decIfGreaterThan(int low) {
if (value > low) {
--value;
return true;
}
return false;
}
synchronized boolean incIfLessThan(int high) {
if (value < high) {
++value;
return true;
}
return false;
}
}