Skip to content

Package: Semaphor

Semaphor

nameinstructionbranchcomplexitylinemethod
Semaphor(Integer)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
down()
M: 3 C: 22
88%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 3
75%
M: 0 C: 1
100%
up()
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: package basic;
2:
3: /**
4: * The Semaphore to lock or unlock a attribute.
5: *
6: * @author HFW410
7: *
8: */
9: public class Semaphor {
10:         /**
11:          * The counter for the semaphore.
12:          */
13:         private Integer count;
14:
15:         /**
16:          * The constructor for the semaphore.
17:          *
18:          * @param count
19:          * the counter for the semaphore.
20:          */
21:         public Semaphor(final Integer count) {
22:                 super();
23:                 this.count = count;
24:         }
25:
26:         /**
27:          * unlock the attribute.
28:          */
29:         public synchronized void up() {
30:                 this.count++;
31:                 this.notifyAll();
32:         }
33:
34:         /**
35:          * lock the attribute.
36:          *
37:          * @throws InterruptedException
38:          * if it failed.
39:          */
40:         public synchronized void down() throws InterruptedException {
41:•                while (this.count == 0) {
42:                         wait();
43:                 }
44:                 this.count--;
45:         }
46:
47: }