Updated YANG Type definitions and documentation in YANG Model Utils.
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / model / util / EnumerationType.java
1 /*\r
2   * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3   *\r
4   * This program and the accompanying materials are made available under the\r
5   * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6   * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7   */\r
8 package org.opendaylight.controller.model.util;\r
9 \r
10 import java.util.Collections;\r
11 import java.util.List;\r
12 \r
13 import org.opendaylight.controller.model.api.type.EnumTypeDefinition;\r
14 import org.opendaylight.controller.yang.common.QName;\r
15 import org.opendaylight.controller.yang.model.api.SchemaPath;\r
16 import org.opendaylight.controller.yang.model.api.Status;\r
17 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;\r
18 \r
19 /**\r
20  * The <code>default</code> implementation of Enumertaion Type Definition interface.\r
21  * \r
22  * @see EnumTypeDefinition\r
23  */\r
24 public class EnumerationType implements EnumTypeDefinition {\r
25 \r
26     private final QName name = BaseTypes.constructQName("enumeration");\r
27     private final SchemaPath path = BaseTypes.schemaPath(name);\r
28     private final String description = "The enumeration built-in type represents values from a set of assigned names.";\r
29     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.6";\r
30 \r
31     private final List<EnumPair> defaultEnum;\r
32     private final List<EnumPair> enums;\r
33     private String units = "";\r
34 \r
35     public EnumerationType(final List<EnumPair> enums) {\r
36         super();\r
37         this.enums = Collections.unmodifiableList(enums);\r
38         defaultEnum = Collections.emptyList();\r
39     }\r
40 \r
41     public EnumerationType(final List<EnumPair> defaultEnum,\r
42             final List<EnumPair> enums, final String units) {\r
43         super();\r
44         this.defaultEnum = Collections.unmodifiableList(defaultEnum);\r
45         this.enums = Collections.unmodifiableList(enums);\r
46         this.units = units;\r
47     }\r
48 \r
49     /*\r
50      * (non-Javadoc)\r
51      * \r
52      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()\r
53      */\r
54     @Override\r
55     public EnumTypeDefinition getBaseType() {\r
56         return this;\r
57     }\r
58 \r
59     /*\r
60      * (non-Javadoc)\r
61      * \r
62      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()\r
63      */\r
64     @Override\r
65     public String getUnits() {\r
66         return units;\r
67     }\r
68 \r
69     /*\r
70      * (non-Javadoc)\r
71      * \r
72      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()\r
73      */\r
74     @Override\r
75     public Object getDefaultValue() {\r
76         return defaultEnum;\r
77     }\r
78 \r
79     /*\r
80      * (non-Javadoc)\r
81      * \r
82      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()\r
83      */\r
84     @Override\r
85     public QName getQName() {\r
86         return name;\r
87     }\r
88 \r
89     /*\r
90      * (non-Javadoc)\r
91      * \r
92      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()\r
93      */\r
94     @Override\r
95     public SchemaPath getPath() {\r
96         return path;\r
97     }\r
98 \r
99     /*\r
100      * (non-Javadoc)\r
101      * \r
102      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()\r
103      */\r
104     @Override\r
105     public String getDescription() {\r
106         return description;\r
107     }\r
108 \r
109     /*\r
110      * (non-Javadoc)\r
111      * \r
112      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()\r
113      */\r
114     @Override\r
115     public String getReference() {\r
116         return reference;\r
117     }\r
118 \r
119     /*\r
120      * (non-Javadoc)\r
121      * \r
122      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()\r
123      */\r
124     @Override\r
125     public Status getStatus() {\r
126         return Status.CURRENT;\r
127     }\r
128 \r
129     /*\r
130      * (non-Javadoc)\r
131      * \r
132      * @see org.opendaylight.controller.yang.model.base.type.api.EnumTypeDefinition#getValues()\r
133      */\r
134     @Override\r
135     public List<EnumPair> getValues() {\r
136         return enums;\r
137     }\r
138 \r
139     @Override\r
140     public List<UnknownSchemaNode> getUnknownSchemaNodes() {\r
141         return Collections.emptyList();\r
142     }\r
143 \r
144     @Override\r
145     public int hashCode() {\r
146         final int prime = 31;\r
147         int result = 1;\r
148         result = prime * result\r
149                 + ((defaultEnum == null) ? 0 : defaultEnum.hashCode());\r
150         result = prime * result\r
151                 + ((description == null) ? 0 : description.hashCode());\r
152         result = prime * result + ((enums == null) ? 0 : enums.hashCode());\r
153         result = prime * result + ((name == null) ? 0 : name.hashCode());\r
154         result = prime * result + ((path == null) ? 0 : path.hashCode());\r
155         result = prime * result\r
156                 + ((reference == null) ? 0 : reference.hashCode());\r
157         result = prime * result + ((units == null) ? 0 : units.hashCode());\r
158         return result;\r
159     }\r
160 \r
161     @Override\r
162     public boolean equals(Object obj) {\r
163         if (this == obj) {\r
164             return true;\r
165         }\r
166         if (obj == null) {\r
167             return false;\r
168         }\r
169         if (getClass() != obj.getClass()) {\r
170             return false;\r
171         }\r
172         EnumerationType other = (EnumerationType) obj;\r
173         if (defaultEnum == null) {\r
174             if (other.defaultEnum != null) {\r
175                 return false;\r
176             }\r
177         } else if (!defaultEnum.equals(other.defaultEnum)) {\r
178             return false;\r
179         }\r
180         if (description == null) {\r
181             if (other.description != null) {\r
182                 return false;\r
183             }\r
184         } else if (!description.equals(other.description)) {\r
185             return false;\r
186         }\r
187         if (enums == null) {\r
188             if (other.enums != null) {\r
189                 return false;\r
190             }\r
191         } else if (!enums.equals(other.enums)) {\r
192             return false;\r
193         }\r
194         if (name == null) {\r
195             if (other.name != null) {\r
196                 return false;\r
197             }\r
198         } else if (!name.equals(other.name)) {\r
199             return false;\r
200         }\r
201         if (path == null) {\r
202             if (other.path != null) {\r
203                 return false;\r
204             }\r
205         } else if (!path.equals(other.path)) {\r
206             return false;\r
207         }\r
208         if (reference == null) {\r
209             if (other.reference != null) {\r
210                 return false;\r
211             }\r
212         } else if (!reference.equals(other.reference)) {\r
213             return false;\r
214         }\r
215         if (units == null) {\r
216             if (other.units != null) {\r
217                 return false;\r
218             }\r
219         } else if (!units.equals(other.units)) {\r
220             return false;\r
221         }\r
222         return true;\r
223     }\r
224 \r
225     @Override\r
226     public String toString() {\r
227         StringBuilder builder = new StringBuilder();\r
228         builder.append("EnumerationType [name=");\r
229         builder.append(name);\r
230         builder.append(", path=");\r
231         builder.append(path);\r
232         builder.append(", description=");\r
233         builder.append(description);\r
234         builder.append(", reference=");\r
235         builder.append(reference);\r
236         builder.append(", defaultEnum=");\r
237         builder.append(defaultEnum);\r
238         builder.append(", enums=");\r
239         builder.append(enums);\r
240         builder.append(", units=");\r
241         builder.append(units);\r
242         builder.append("]");\r
243         return builder.toString();\r
244     }\r
245 }\r