1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package fr.inrae.agroclim.indicators.model.indicator.listener;
18
19 import java.util.Objects;
20
21 import fr.inrae.agroclim.indicators.model.Evaluation;
22 import fr.inrae.agroclim.indicators.model.indicator.CompositeIndicator;
23 import fr.inrae.agroclim.indicators.model.indicator.Indicator;
24 import lombok.Getter;
25
26
27
28
29
30
31
32
33
34 public final class IndicatorEvent {
35
36
37
38 public enum Type {
39
40
41
42 ADD(Indicator.class),
43
44
45
46 AGGREGATION_MISSING(CompositeIndicator.class),
47
48
49
50 CHANGE(Indicator.class),
51
52
53
54 CLIMATIC_MISSING(CompositeIndicator.class),
55
56
57
58 COMPUTE_FAILURE(Evaluation.class),
59
60
61
62 COMPUTE_START(Evaluation.class),
63
64
65
66 COMPUTE_SUCCESS(Evaluation.class),
67
68
69
70 NOT_COMPUTABLE(Indicator.class),
71
72
73
74 PHASE_MISSING(Evaluation.class),
75
76
77
78 REMOVE(Indicator.class),
79
80
81
82 UPDATED_VALUE(Indicator.class);
83
84
85
86
87 @Getter
88 private final Class<? extends Indicator> clazz;
89
90
91
92
93
94
95 Type(final Class<? extends Indicator> value) {
96 clazz = value;
97 }
98
99
100
101
102
103
104
105 public IndicatorEvent event(final Indicator ind) {
106 return new IndicatorEvent(this, ind);
107 }
108
109 }
110
111
112
113
114 @Getter
115 private final Type associatedType;
116
117
118
119
120 @Getter
121 private final Indicator source;
122
123
124
125
126
127
128
129 private IndicatorEvent(final Type type, final Indicator indicator) {
130 Objects.requireNonNull(type,
131 "IndicatorEvent.Type must not be null!");
132 Objects.requireNonNull(indicator,
133 "Indicator indicator must not be null!");
134 if (!type.getClazz().isAssignableFrom(indicator.getClass())) {
135 throw new IllegalArgumentException("Associated class for "
136 + type.name() + " is " + type.getClazz().getCanonicalName()
137 + ", but provided = "
138 + indicator.getClass().getCanonicalName());
139 }
140 associatedType = type;
141 source = indicator;
142 }
143
144 }