AtomicCounter.java
package ch.hslu.exercises.sw08.ex2;
import java.util.concurrent.atomic.AtomicInteger;
public final class AtomicCounter implements Counter {
private final AtomicInteger count;
/**
* Erzeugt einen Zähler mit Zählerstand 0.
*/
public AtomicCounter() {
this.count = new AtomicInteger(0);
}
/**
* see ch.hslu.ad.exercise.sw07.count.Counter#increment()
*/
@Override
public int increment() {
return count.incrementAndGet();
}
/**
* see ch.hslu.ad.exercise.sw07.count.Counter#decrement()
*/
@Override
public int decrement() {
return count.decrementAndGet();
}
/**
* see ch.hslu.ad.exercise.sw07.count.Counter#get()
*/
@Override
public int get() {
return count.get();
}
}