Fix minor bug in FRM proactive flow code path
[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 final class EnumerationType implements EnumTypeDefinition {
25     private final QName name = BaseTypes.constructQName("enumeration");
26     private final SchemaPath path;
27     private final String description = "The enumeration built-in type represents values from a set of assigned names.";
28     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.6";
29
30     private final EnumPair defaultEnum;
31     private final List<EnumPair> enums;
32     private final String units = "";
33     private final EnumTypeDefinition baseType;
34
35     public EnumerationType(final SchemaPath path, final List<EnumPair> enums) {
36         super();
37         this.path = path;
38         this.enums = Collections.unmodifiableList(enums);
39         this.defaultEnum = null;
40         this.baseType = this;
41     }
42
43     public EnumerationType(final SchemaPath path, final EnumPair defaultEnum,
44             final List<EnumPair> enums) {
45         super();
46         this.path = path;
47         this.baseType = this;
48         this.defaultEnum = defaultEnum;
49         this.enums = Collections.unmodifiableList(enums);
50     }
51
52     /*
53      * (non-Javadoc)
54      *
55      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
56      */
57     @Override
58     public EnumTypeDefinition getBaseType() {
59         return baseType;
60     }
61
62     /*
63      * (non-Javadoc)
64      *
65      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
66      */
67     @Override
68     public String getUnits() {
69         return units;
70     }
71
72     /*
73      * (non-Javadoc)
74      *
75      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
76      */
77     @Override
78     public Object getDefaultValue() {
79         return defaultEnum;
80     }
81
82     /*
83      * (non-Javadoc)
84      *
85      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
86      */
87     @Override
88     public QName getQName() {
89         return name;
90     }
91
92     /*
93      * (non-Javadoc)
94      *
95      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
96      */
97     @Override
98     public SchemaPath getPath() {
99         return path;
100     }
101
102     /*
103      * (non-Javadoc)
104      *
105      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
106      */
107     @Override
108     public String getDescription() {
109         return description;
110     }
111
112     /*
113      * (non-Javadoc)
114      *
115      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
116      */
117     @Override
118     public String getReference() {
119         return reference;
120     }
121
122     /*
123      * (non-Javadoc)
124      *
125      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
126      */
127     @Override
128     public Status getStatus() {
129         return Status.CURRENT;
130     }
131
132     /*
133      * (non-Javadoc)
134      *
135      * @see org.opendaylight.controller.yang.model.base.type.api.EnumTypeDefinition#getValues()
136      */
137     @Override
138     public List<EnumPair> getValues() {
139         return enums;
140     }
141
142     @Override
143     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
144         return Collections.emptyList();
145     }
146
147     @Override
148     public int hashCode() {
149         final int prime = 31;
150         int result = 1;
151         result = prime * result
152                 + ((defaultEnum == null) ? 0 : defaultEnum.hashCode());
153         result = prime * result
154                 + ((description == null) ? 0 : description.hashCode());
155         result = prime * result + ((enums == null) ? 0 : enums.hashCode());
156         result = prime * result + ((name == null) ? 0 : name.hashCode());
157         result = prime * result + ((path == null) ? 0 : path.hashCode());
158         result = prime * result
159                 + ((reference == null) ? 0 : reference.hashCode());
160         result = prime * result + ((units == null) ? 0 : units.hashCode());
161         return result;
162     }
163
164     @Override
165     public boolean equals(Object obj) {
166         if (this == obj) {
167             return true;
168         }
169         if (obj == null) {
170             return false;
171         }
172         if (getClass() != obj.getClass()) {
173             return false;
174         }
175         EnumerationType other = (EnumerationType) obj;
176         if (defaultEnum == null) {
177             if (other.defaultEnum != null) {
178                 return false;
179             }
180         } else if (!defaultEnum.equals(other.defaultEnum)) {
181             return false;
182         }
183         if (description == null) {
184             if (other.description != null) {
185                 return false;
186             }
187         } else if (!description.equals(other.description)) {
188             return false;
189         }
190         if (enums == null) {
191             if (other.enums != null) {
192                 return false;
193             }
194         } else if (!enums.equals(other.enums)) {
195             return false;
196         }
197         if (name == null) {
198             if (other.name != null) {
199                 return false;
200             }
201         } else if (!name.equals(other.name)) {
202             return false;
203         }
204         if (path == null) {
205             if (other.path != null) {
206                 return false;
207             }
208         } else if (!path.equals(other.path)) {
209             return false;
210         }
211         if (reference == null) {
212             if (other.reference != null) {
213                 return false;
214             }
215         } else if (!reference.equals(other.reference)) {
216             return false;
217         }
218         if (units == null) {
219             if (other.units != null) {
220                 return false;
221             }
222         } else if (!units.equals(other.units)) {
223             return false;
224         }
225         return true;
226     }
227
228     @Override
229     public String toString() {
230         StringBuilder builder = new StringBuilder();
231         builder.append("EnumerationType [name=");
232         builder.append(name);
233         builder.append(", path=");
234         builder.append(path);
235         builder.append(", description=");
236         builder.append(description);
237         builder.append(", reference=");
238         builder.append(reference);
239         builder.append(", defaultEnum=");
240         builder.append(defaultEnum);
241         builder.append(", enums=");
242         builder.append(enums);
243         builder.append(", units=");
244         builder.append(units);
245         builder.append("]");
246         return builder.toString();
247     }
248 }