View Javadoc
1   package ch.hslu.exercises.sw08.ex2;
2   
3   
4   import java.util.concurrent.atomic.AtomicInteger;
5   
6   public final class AtomicCounter implements Counter {
7   
8       private final AtomicInteger count;
9   
10      /**
11       * Erzeugt einen Zähler mit Zählerstand 0.
12       */
13      public AtomicCounter() {
14          this.count = new AtomicInteger(0);
15      }
16  
17      /**
18       * see ch.hslu.ad.exercise.sw07.count.Counter#increment()
19       */
20      @Override
21      public int increment() {
22          return count.incrementAndGet();
23      }
24  
25      /**
26       * see ch.hslu.ad.exercise.sw07.count.Counter#decrement()
27       */
28      @Override
29      public int decrement() {
30          return count.decrementAndGet();
31      }
32  
33      /**
34       * see ch.hslu.ad.exercise.sw07.count.Counter#get()
35       */
36      @Override
37      public int get() {
38          return count.get();
39      }
40  }