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 class EnumerationType implements EnumTypeDefinition {
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";
31 private final List<EnumPair> defaultEnum;
32 private final List<EnumPair> enums;
33 private String units = "";
35 public EnumerationType(final List<EnumPair> enums) {
37 this.enums = Collections.unmodifiableList(enums);
38 defaultEnum = Collections.emptyList();
41 public EnumerationType(final List<EnumPair> defaultEnum,
42 final List<EnumPair> enums, final String units) {
44 this.defaultEnum = Collections.unmodifiableList(defaultEnum);
45 this.enums = Collections.unmodifiableList(enums);
52 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
55 public EnumTypeDefinition getBaseType() {
62 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
65 public String getUnits() {
72 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
75 public Object getDefaultValue() {
82 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
85 public QName getQName() {
92 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
95 public SchemaPath getPath() {
102 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
105 public String getDescription() {
112 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
115 public String getReference() {
122 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
125 public Status getStatus() {
126 return Status.CURRENT;
132 * @see org.opendaylight.controller.yang.model.base.type.api.EnumTypeDefinition#getValues()
135 public List<EnumPair> getValues() {
140 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
141 return Collections.emptyList();
145 public int hashCode() {
146 final int prime = 31;
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());
162 public boolean equals(Object obj) {
169 if (getClass() != obj.getClass()) {
172 EnumerationType other = (EnumerationType) obj;
173 if (defaultEnum == null) {
174 if (other.defaultEnum != null) {
177 } else if (!defaultEnum.equals(other.defaultEnum)) {
180 if (description == null) {
181 if (other.description != null) {
184 } else if (!description.equals(other.description)) {
188 if (other.enums != null) {
191 } else if (!enums.equals(other.enums)) {
195 if (other.name != null) {
198 } else if (!name.equals(other.name)) {
202 if (other.path != null) {
205 } else if (!path.equals(other.path)) {
208 if (reference == null) {
209 if (other.reference != null) {
212 } else if (!reference.equals(other.reference)) {
216 if (other.units != null) {
219 } else if (!units.equals(other.units)) {
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);
243 return builder.toString();