View Javadoc
1   /*
2     * #%L
3     * Quadrige3 Core
4     * %%
5     * Copyright (C) 2017 Ifremer
6     * %%
7     * This program is free software: you can redistribute it and/or modify
8     * it under the terms of the GNU Affero General Public License as published by
9     * the Free Software Foundation, either version 3 of the License, or
10    * (at your option) any later version.
11    *
12    * This program is distributed in the hope that it will be useful,
13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    * GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU Affero General Public License
18    * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19    * #L%
20    */
21  //
22  // Attention: Generated code! Do not modify by hand!
23  // Generated by: TypeSafeEnumeration.vsl in andromda-java-cartridge.
24  // Model Class:  Données::fr.ifremer.quadrige3.core::dao::referential::UnitId
25  // Metafacade:   org.andromda.metafacades.uml.Enumeration
26  // Stereotype:  Enumeration
27  //
28  package fr.ifremer.quadrige3.core.dao.referential;
29  
30  import fr.ifremer.quadrige3.core.dao.technical.QuadrigeEnumerationDef;
31  import java.io.Serializable;
32  import java.util.ArrayList;
33  import java.util.Collections;
34  import java.util.LinkedHashMap;
35  import java.util.List;
36  import java.util.Map;
37  import static org.nuiton.i18n.I18n.n;
38  
39  /**
40   * 
41   */
42  public enum UnitId
43      implements Serializable, QuadrigeEnumerationDef<Integer>
44  {
45      NO_UNIT (
46  			"quadrige3.enumeration.UnitId.NO_UNIT",
47  			n("quadrige3.enumeration.UnitId.NO_UNIT.description"),
48  			99),
49      METER (
50  			"quadrige3.enumeration.UnitId.METER",
51  			n("quadrige3.enumeration.UnitId.METER.description"),
52  			6),
53      CENTIMENTER (
54  			"quadrige3.enumeration.UnitId.CENTIMENTER",
55  			n("quadrige3.enumeration.UnitId.CENTIMENTER.description"),
56  			7),
57      MILLIMETER (
58  			"quadrige3.enumeration.UnitId.MILLIMETER",
59  			n("quadrige3.enumeration.UnitId.MILLIMETER.description"),
60  			8),
61      MICROMETER (
62  			"quadrige3.enumeration.UnitId.MICROMETER",
63  			n("quadrige3.enumeration.UnitId.MICROMETER.description"),
64  			9);
65  
66      /**
67       * The serial version UID of this class. Needed for serialization.
68       */
69      private static final long serialVersionUID = 2126945324956511137L;
70  
71      private String key;
72      private String description;
73      private Integer enumValue;
74  
75      /**
76       * The constructor with enumeration literal value allowing
77       * super classes to access it.
78       */
79      private UnitId(String key, String description, Integer value)
80      {
81      	this.key = key;
82      	this.description = description;
83          this.enumValue = value;
84      }
85      
86      @Override
87       /**
88        * Setter for value. Use to override value, from configuration
89        */
90       public void setValue(Integer newValue) {
91  		if (newValue != null && !this.enumValue.equals(newValue)) {
92  			// Update static lists
93  	    	values.remove(this.enumValue);
94  	    	literals.remove(this.enumValue);
95  	    	this.enumValue = newValue;
96  	    	values.put(this.enumValue, this);
97  	    	literals.add(this.enumValue);
98  		}
99      }
100     
101 
102     @Override
103     public String getValueAsString()
104     {
105         return String.valueOf(this.enumValue);
106     }
107 
108     /**
109      * Retrieves an instance of UnitId from <code>its name</code>.
110      *
111      * @param name the name to create the UnitId from.
112      * @return The enumeration literal named after the 'name' argument
113      */
114     public static UnitId fromString(String name)
115     {
116         return UnitId.valueOf(name);
117     }
118 
119     /**
120      * Returns an enumeration literal Integer <code>value</code>.
121      * Required by JAXB2 enumeration implementation
122      *
123      * @return Integer with corresponding value
124      */
125     public Integer value()
126     {
127         return this.enumValue;
128     }
129 
130     /**
131      * Returns an instance of UnitId from Integer <code>value</code>.
132      * Required by JAXB2 enumeration implementation
133      *
134      * @param value the value to create the UnitId from.
135      * @return static Enumeration with corresponding value
136      */
137     public static UnitId fromValue(Integer value)
138     {
139         for (UnitId enumName: UnitId.values())
140         {
141             if (enumName.getValue().equals(value))
142             {
143                 return enumName;
144             }
145         }
146         throw new IllegalArgumentException("UnitId.fromValue(" + value.toString() + ')');
147     }
148 
149     /**
150      * Gets the underlying value of this type safe enumeration.
151      * This method is necessary to comply with DaoBase implementation.
152      * @return The name of this literal.
153      */
154     public Integer getValue()
155     {
156         return this.enumValue;
157     }
158     
159     @Override
160     public String getDescription() {
161     	return description;
162     }
163     
164     @Override
165     public String getKey() {
166     	return key;
167     }
168     
169     @Override
170     public Class<?> getType() {
171     	return Integer.class;
172     }
173     
174     /**
175      * Returns an unmodifiable list containing the literals that are known by this enumeration.
176      *
177      * @return A List containing the actual literals defined by this enumeration, this list
178      *         can not be modified.
179      */
180     public static List<Integer> literals()
181     {
182         return UnitId.literals;
183     }
184 
185     /**
186      * Returns an unmodifiable list containing the names of the literals that are known
187      * by this enumeration.
188      *
189      * @return A List containing the actual names of the literals defined by this
190      *         enumeration, this list can not be modified.
191      */
192     public static List<String> names()
193     {
194         return UnitId.names;
195     }
196 
197     private static Map<Integer, UnitId> values = new LinkedHashMap<Integer, UnitId>(5, 1);
198     private static List<Integer> literals = new ArrayList<Integer>(5);
199     private static List<String> names = new ArrayList<String>(5);
200     private static List<UnitId> valueList = new ArrayList<UnitId>(5);
201 
202     /**
203      * Initializes the values.
204      */
205     static
206     {
207         synchronized (UnitId.values)
208         {
209             UnitId.values.put(NO_UNIT.enumValue, NO_UNIT);
210             UnitId.values.put(METER.enumValue, METER);
211             UnitId.values.put(CENTIMENTER.enumValue, CENTIMENTER);
212             UnitId.values.put(MILLIMETER.enumValue, MILLIMETER);
213             UnitId.values.put(MICROMETER.enumValue, MICROMETER);
214         }
215         synchronized (UnitId.valueList)
216         {
217             UnitId.valueList.add(NO_UNIT);
218             UnitId.valueList.add(METER);
219             UnitId.valueList.add(CENTIMENTER);
220             UnitId.valueList.add(MILLIMETER);
221             UnitId.valueList.add(MICROMETER);
222             // For Quadrige3, lists could be reload from configuration (see method 'setValue')
223             //UnitId.valueList = Collections.unmodifiableList(valueList);
224         }
225         synchronized (UnitId.literals)
226         {
227             UnitId.literals.add(NO_UNIT.enumValue);
228             UnitId.literals.add(METER.enumValue);
229             UnitId.literals.add(CENTIMENTER.enumValue);
230             UnitId.literals.add(MILLIMETER.enumValue);
231             UnitId.literals.add(MICROMETER.enumValue);
232             // For Quadrige3, lists could be reload from configuration (see method 'setValue')
233             //UnitId.literals = Collections.unmodifiableList(literals);
234         }
235         synchronized (UnitId.names)
236         {
237             UnitId.names.add("NO_UNIT");
238             UnitId.names.add("METER");
239             UnitId.names.add("CENTIMENTER");
240             UnitId.names.add("MILLIMETER");
241             UnitId.names.add("MICROMETER");
242             UnitId.names = Collections.unmodifiableList(names);
243         }
244     }
245     // type-safe-enumeration-object java merge-point
246 }