View Javadoc
1   package fr.ifremer.tutti.persistence.dao.referential.pmfm;
2   
3   /*
4    * #%L
5    * Tutti :: Persistence
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2012 - 2016 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU General Public License as
13   * published by the Free Software Foundation, either version 3 of the
14   * License, or (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU General Public
22   * License along with this program.  If not, see
23   * <http://www.gnu.org/licenses/gpl-3.0.html>.
24   * #L%
25   */
26  
27  import com.google.common.collect.ImmutableList;
28  import com.google.common.collect.ImmutableMap;
29  import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId;
30  import fr.ifremer.adagio.core.dao.technical.AdagioEnumerationDef;
31  
32  import java.io.Serializable;
33  import java.util.List;
34  import java.util.Map;
35  
36  import static org.nuiton.i18n.I18n.n;
37  
38  /**
39   * L'extension de {@link PmfmId} pour les pmfm non encore géré dans adagio.
40   *
41   * Created on 25/04/16.
42   *
43   * @author Tony Chemit - chemit@codelutin.com
44   * @since 4.5
45   */
46  public enum PmfmId2 implements Serializable, AdagioEnumerationDef<Integer> {
47  
48      /** TODO: Model Documentation for Enumeration Literal SAMPLE_ID value 1435 */
49      SAMPLE_ID(
50              "adagio.enumeration.PmfmId.SAMPLE_ID",
51              n("adagio.enumeration.PmfmId.SAMPLE_ID.description"),
52              1435),
53      /** TODO: Model Documentation for Enumeration Literal COPY_METHOD value 1762 */
54      COPY_METHOD(
55              "adagio.enumeration.PmfmId.COPY_METHOD",
56              n("adagio.enumeration.PmfmId.COPY_METHOD.description"),
57              1762),
58  
59      /** TODO: Model Documentation for Enumeration Literal CALCIFIED_STRUCTURE value 1807 */
60      CALCIFIED_STRUCTURE(
61              "adagio.enumeration.PmfmId.CALCIFIED_STRUCTURE",
62              n("adagio.enumeration.PmfmId.CALCIFIED_STRUCTURE.description"),
63              1807);
64  
65      private static final long serialVersionUID = 1L;
66  
67      private String key;
68      private String description;
69      private Integer enumValue;
70  
71      private PmfmId2(String key, String description, Integer value) {
72          this.key = key;
73          this.description = description;
74          this.enumValue = value;
75      }
76  
77      @Override
78      public void setValue(Integer newValue) {
79          if (newValue != null && !this.enumValue.equals(newValue)) {
80              // Update static lists
81              values.remove(this.enumValue);
82              literals.remove(this.enumValue);
83              this.enumValue = newValue;
84              values.put(this.enumValue, this);
85              literals.add(this.enumValue);
86          }
87      }
88  
89  
90      @Override
91      public String getValueAsString() {
92          return String.valueOf(this.enumValue);
93      }
94  
95      /**
96       * Retrieves an instance of PmfmId2 from <code>its name</code>.
97       *
98       * @param name the name to create the PmfmId2 from.
99       * @return The enumeration literal named after the 'name' argument
100      */
101     public static PmfmId2 fromString(String name) {
102         return PmfmId2.valueOf(name);
103     }
104 
105     /**
106      * Returns an enumeration literal Integer <code>value</code>.
107      * Required by JAXB2 enumeration implementation
108      *
109      * @return Integer with corresponding value
110      */
111     public Integer value() {
112         return this.enumValue;
113     }
114 
115     /**
116      * Returns an instance of PmfmId2 from Integer <code>value</code>.
117      * Required by JAXB2 enumeration implementation
118      *
119      * @param value the value to create the PmfmId2 from.
120      * @return static Enumeration with corresponding value
121      */
122     public static PmfmId2 fromValue(Integer value) {
123         for (PmfmId2 enumName : PmfmId2.values()) {
124             if (enumName.getValue().equals(value)) {
125                 return enumName;
126             }
127         }
128         throw new IllegalArgumentException("PmfmId2.fromValue(" + value.toString() + ')');
129     }
130 
131     /**
132      * Gets the underlying value of this type safe enumeration.
133      * This method is necessary to comply with DaoBase implementation.
134      *
135      * @return The name of this literal.
136      */
137     public Integer getValue() {
138         return this.enumValue;
139     }
140 
141     @Override
142     public String getDescription() {
143         return description;
144     }
145 
146     @Override
147     public String getKey() {
148         return key;
149     }
150 
151     @Override
152     public Class<?> getType() {
153         return Integer.class;
154     }
155 
156     /**
157      * Returns an unmodifiable list containing the literals that are known by this enumeration.
158      *
159      * @return A List containing the actual literals defined by this enumeration, this list
160      * can not be modified.
161      */
162     public static List<Integer> literals() {
163         return PmfmId2.literals;
164     }
165 
166     /**
167      * Returns an unmodifiable list containing the names of the literals that are known
168      * by this enumeration.
169      *
170      * @return A List containing the actual names of the literals defined by this
171      * enumeration, this list can not be modified.
172      */
173     public static List<String> names() {
174         return PmfmId2.names;
175     }
176 
177     private static final Map<Integer, PmfmId2> values = ImmutableMap
178             .<Integer, PmfmId2>builder()
179             .put(SAMPLE_ID.enumValue, SAMPLE_ID)
180             .put(COPY_METHOD.enumValue, COPY_METHOD)
181             .put(CALCIFIED_STRUCTURE.enumValue, CALCIFIED_STRUCTURE)
182             .build();
183 
184     private static final List<Integer> literals = ImmutableList.of(SAMPLE_ID.enumValue,
185                                                                    COPY_METHOD.enumValue,
186                                                                    CALCIFIED_STRUCTURE.enumValue);
187 
188     private static final List<String> names = ImmutableList.of("SAMPLE_ID",
189                                                                "COPY_METHOD",
190                                                                "CALCIFIED_STRUCTURE");
191 
192 }