View Javadoc
1   /**
2    * This file is part of Indicators.
3    *
4    * Indicators is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * Indicators is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with Indicators. If not, see <https://www.gnu.org/licenses/>.
16   */
17  package fr.inrae.agroclim.indicators.model.indicator;
18  
19  import lombok.Getter;
20  
21  /**
22   * All categories of indicator.
23   *
24   * Last changed : $Date$
25   *
26   * @author $Author$
27   * @version $Revision$
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       * @param tag
45       *            category tag
46       * @return category for the tag.
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       * @param category
59       *            tag of parent category
60       * @return tag of child category
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       * Order.
76       *
77       * Exists only to prevent side effects of member sorting during auto-format.
78       */
79      private final int order;
80  
81      /**
82       * Tag.
83       */
84      @Getter
85      private final String tag;
86  
87      /**
88       * @param categoryOrder
89       *            Order
90       * @param categoryTag
91       *            Tag
92       */
93      IndicatorCategory(final int categoryOrder, final String categoryTag) {
94          this.order = categoryOrder;
95          this.tag = categoryTag;
96      }
97  
98      /**
99       * @return next category by its order.
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 }