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