1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package fr.inrae.agroclim.indicators.model.indicator;
18
19 import lombok.Getter;
20
21
22
23
24
25
26
27
28
29 public enum IndicatorCategory {
30
31 EVALUATION(0, "evaluation"),
32
33 PHENO_PHASES(1, "pheno"),
34
35 CULTURAL_PRATICES(2, "practices"),
36
37 ECOPHYSIOLOGICAL_PROCESSES(3, "ecoprocesses"),
38
39 CLIMATIC_EFFECTS(4, "climatic"),
40
41 INDICATORS(5, "indicator");
42
43
44
45
46
47
48 public static IndicatorCategory getByTag(final String tag) {
49 for (IndicatorCategory category : values()) {
50 if (category.tag.equals(tag)) {
51 return category;
52 }
53 }
54 return null;
55 }
56
57
58
59
60
61
62 public static String getChildCategory(final String category) {
63 IndicatorCategory cat = IndicatorCategory.valueOf(category);
64 if (cat == null) {
65 return null;
66 }
67 IndicatorCategory child = cat.getChildCategory();
68 if (child == null) {
69 return null;
70 }
71 return child.getTag();
72 }
73
74
75
76
77
78
79 private final int order;
80
81
82
83
84 @Getter
85 private final String tag;
86
87
88
89
90
91
92
93 IndicatorCategory(final int categoryOrder, final String categoryTag) {
94 this.order = categoryOrder;
95 this.tag = categoryTag;
96 }
97
98
99
100
101 public IndicatorCategory getChildCategory() {
102 final int childOrder = order + 1;
103 for (IndicatorCategory category : values()) {
104 if (category.order == childOrder) {
105 return category;
106 }
107 }
108 return null;
109 }
110 }