2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.yang.model.util;
10 import java.util.Collections;
11 import java.util.List;
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;
20 * The <code>default</code> implementation of Enumertaion Type Definition interface.
22 * @see EnumTypeDefinition
24 public final class EnumerationType implements EnumTypeDefinition {
26 private final QName name = BaseTypes.constructQName("enumeration");
27 private final SchemaPath path;
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";
31 private final EnumPair defaultEnum;
32 private final List<EnumPair> enums;
33 private String units = "";
34 private final EnumTypeDefinition baseType;
36 private EnumerationType(final List<EnumPair> enums) {
37 this.path = BaseTypes.schemaPath(name);
38 this.enums = Collections.unmodifiableList(enums);
39 this.defaultEnum = null;
43 public EnumerationType(final SchemaPath path, final List<EnumPair> enums) {
46 this.enums = Collections.unmodifiableList(enums);
47 this.defaultEnum = null;
48 baseType = new EnumerationType(enums);
51 public EnumerationType(final SchemaPath path, final EnumPair defaultEnum,
52 final List<EnumPair> enums, final String units) {
55 baseType = new EnumerationType(enums);
56 this.defaultEnum = defaultEnum;
57 this.enums = Collections.unmodifiableList(enums);
64 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
67 public EnumTypeDefinition getBaseType() {
74 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
77 public String getUnits() {
84 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
87 public Object getDefaultValue() {
94 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
97 public QName getQName() {
104 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
107 public SchemaPath getPath() {
114 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
117 public String getDescription() {
124 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
127 public String getReference() {
134 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
137 public Status getStatus() {
138 return Status.CURRENT;
144 * @see org.opendaylight.controller.yang.model.base.type.api.EnumTypeDefinition#getValues()
147 public List<EnumPair> getValues() {
152 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
153 return Collections.emptyList();
157 public int hashCode() {
158 final int prime = 31;
160 result = prime * result
161 + ((defaultEnum == null) ? 0 : defaultEnum.hashCode());
162 result = prime * result
163 + ((description == null) ? 0 : description.hashCode());
164 result = prime * result + ((enums == null) ? 0 : enums.hashCode());
165 result = prime * result + ((name == null) ? 0 : name.hashCode());
166 result = prime * result + ((path == null) ? 0 : path.hashCode());
167 result = prime * result
168 + ((reference == null) ? 0 : reference.hashCode());
169 result = prime * result + ((units == null) ? 0 : units.hashCode());
174 public boolean equals(Object obj) {
181 if (getClass() != obj.getClass()) {
184 EnumerationType other = (EnumerationType) obj;
185 if (defaultEnum == null) {
186 if (other.defaultEnum != null) {
189 } else if (!defaultEnum.equals(other.defaultEnum)) {
192 if (description == null) {
193 if (other.description != null) {
196 } else if (!description.equals(other.description)) {
200 if (other.enums != null) {
203 } else if (!enums.equals(other.enums)) {
207 if (other.name != null) {
210 } else if (!name.equals(other.name)) {
214 if (other.path != null) {
217 } else if (!path.equals(other.path)) {
220 if (reference == null) {
221 if (other.reference != null) {
224 } else if (!reference.equals(other.reference)) {
228 if (other.units != null) {
231 } else if (!units.equals(other.units)) {
238 public String toString() {
239 StringBuilder builder = new StringBuilder();
240 builder.append("EnumerationType [name=");
241 builder.append(name);
242 builder.append(", path=");
243 builder.append(path);
244 builder.append(", description=");
245 builder.append(description);
246 builder.append(", reference=");
247 builder.append(reference);
248 builder.append(", defaultEnum=");
249 builder.append(defaultEnum);
250 builder.append(", enums=");
251 builder.append(enums);
252 builder.append(", units=");
253 builder.append(units);
255 return builder.toString();