1 package cz.cuni.amis.pogamut.defcon.utils;
2
3 import java.util.LinkedList;
4
5
6
7
8
9
10
11
12 public class SimpleFlag<T> {
13 private LinkedList<AdvancedFlagListener<T>> listeners = new LinkedList<AdvancedFlagListener<T>>();
14
15 private T value;
16
17 public void addStrongListener(AdvancedFlagListener<T> listener) {
18 listeners.addLast(listener);
19 }
20
21 public void clearListeners() {
22 listeners.clear();
23 }
24
25 public T getFlag() {
26 return value;
27 }
28
29 public void removeListener(AdvancedFlagListener<T> listener) {
30 listeners.remove(listener);
31 }
32
33 public void setFlag(T newValue) {
34 if (newValue == value)
35 return;
36
37 T oldValue = value;
38 value = newValue;
39
40 for (AdvancedFlagListener<T> listener : listeners) {
41 listener.flagChanged(oldValue, newValue);
42 }
43 }
44
45 public SimpleFlag(T value) {
46 this.value = value;
47 }
48 }