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 {
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";
30 private final EnumPair defaultEnum;
31 private final List<EnumPair> enums;
32 private final String units = "";
33 private final EnumTypeDefinition baseType;
35 public EnumerationType(final SchemaPath path, final List<EnumPair> enums) {
38 this.enums = Collections.unmodifiableList(enums);
39 this.defaultEnum = null;
43 public EnumerationType(final SchemaPath path, final EnumPair defaultEnum,
44 final List<EnumPair> enums) {
48 this.defaultEnum = defaultEnum;
49 this.enums = Collections.unmodifiableList(enums);
55 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
58 public EnumTypeDefinition getBaseType() {
65 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
68 public String getUnits() {
75 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
78 public Object getDefaultValue() {
85 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
88 public QName getQName() {
95 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
98 public SchemaPath getPath() {
105 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
108 public String getDescription() {
115 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
118 public String getReference() {
125 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
128 public Status getStatus() {
129 return Status.CURRENT;
135 * @see org.opendaylight.controller.yang.model.base.type.api.EnumTypeDefinition#getValues()
138 public List<EnumPair> getValues() {
143 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
144 return Collections.emptyList();
148 public int hashCode() {
149 final int prime = 31;
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());
165 public boolean equals(Object obj) {
172 if (getClass() != obj.getClass()) {
175 EnumerationType other = (EnumerationType) obj;
176 if (defaultEnum == null) {
177 if (other.defaultEnum != null) {
180 } else if (!defaultEnum.equals(other.defaultEnum)) {
183 if (description == null) {
184 if (other.description != null) {
187 } else if (!description.equals(other.description)) {
191 if (other.enums != null) {
194 } else if (!enums.equals(other.enums)) {
198 if (other.name != null) {
201 } else if (!name.equals(other.name)) {
205 if (other.path != null) {
208 } else if (!path.equals(other.path)) {
211 if (reference == null) {
212 if (other.reference != null) {
215 } else if (!reference.equals(other.reference)) {
219 if (other.units != null) {
222 } else if (!units.equals(other.units)) {
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);
246 return builder.toString();