2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\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
8 package org.opendaylight.controller.model.util;
\r
10 import java.util.Collections;
\r
11 import java.util.List;
\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
20 * The <code>default</code> implementation of Enumertaion Type Definition interface.
\r
22 * @see EnumTypeDefinition
\r
24 public class EnumerationType implements EnumTypeDefinition {
\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
31 private final List<EnumPair> defaultEnum;
\r
32 private final List<EnumPair> enums;
\r
33 private String units = "";
\r
35 public EnumerationType(final List<EnumPair> enums) {
\r
37 this.enums = Collections.unmodifiableList(enums);
\r
38 defaultEnum = Collections.emptyList();
\r
41 public EnumerationType(final List<EnumPair> defaultEnum,
\r
42 final List<EnumPair> enums, final String units) {
\r
44 this.defaultEnum = Collections.unmodifiableList(defaultEnum);
\r
45 this.enums = Collections.unmodifiableList(enums);
\r
52 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
\r
55 public EnumTypeDefinition getBaseType() {
\r
62 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
\r
65 public String getUnits() {
\r
72 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
\r
75 public Object getDefaultValue() {
\r
82 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
\r
85 public QName getQName() {
\r
92 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
\r
95 public SchemaPath getPath() {
\r
102 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
\r
105 public String getDescription() {
\r
106 return description;
\r
112 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
\r
115 public String getReference() {
\r
122 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
\r
125 public Status getStatus() {
\r
126 return Status.CURRENT;
\r
132 * @see org.opendaylight.controller.yang.model.base.type.api.EnumTypeDefinition#getValues()
\r
135 public List<EnumPair> getValues() {
\r
140 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
\r
141 return Collections.emptyList();
\r
145 public int hashCode() {
\r
146 final int prime = 31;
\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
162 public boolean equals(Object obj) {
\r
169 if (getClass() != obj.getClass()) {
\r
172 EnumerationType other = (EnumerationType) obj;
\r
173 if (defaultEnum == null) {
\r
174 if (other.defaultEnum != null) {
\r
177 } else if (!defaultEnum.equals(other.defaultEnum)) {
\r
180 if (description == null) {
\r
181 if (other.description != null) {
\r
184 } else if (!description.equals(other.description)) {
\r
187 if (enums == null) {
\r
188 if (other.enums != null) {
\r
191 } else if (!enums.equals(other.enums)) {
\r
194 if (name == null) {
\r
195 if (other.name != null) {
\r
198 } else if (!name.equals(other.name)) {
\r
201 if (path == null) {
\r
202 if (other.path != null) {
\r
205 } else if (!path.equals(other.path)) {
\r
208 if (reference == null) {
\r
209 if (other.reference != null) {
\r
212 } else if (!reference.equals(other.reference)) {
\r
215 if (units == null) {
\r
216 if (other.units != null) {
\r
219 } else if (!units.equals(other.units)) {
\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