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.yangtools.yang.model.util;
10 import java.util.Collections;
11 import java.util.List;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
15 import org.opendaylight.yangtools.yang.model.api.Status;
16 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
20 * The <code>default</code> implementation of Enumertaion Type Definition
23 * @see EnumTypeDefinition
25 public final class EnumerationType implements EnumTypeDefinition {
26 private final QName name = BaseTypes.constructQName("enumeration");
27 private final SchemaPath path;
28 private static final String DESCRIPTION = "The enumeration built-in type represents values from a set of assigned names.";
29 private static 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 static final String UNITS = "";
35 public EnumerationType(final SchemaPath path, final List<EnumPair> enums) {
38 this.enums = Collections.unmodifiableList(enums);
39 this.defaultEnum = null;
42 public EnumerationType(final SchemaPath path, final EnumPair defaultEnum, final List<EnumPair> enums) {
45 this.defaultEnum = defaultEnum;
46 this.enums = Collections.unmodifiableList(enums);
53 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
56 public EnumTypeDefinition getBaseType() {
63 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
66 public String getUnits() {
74 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
78 public Object getDefaultValue() {
85 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
88 public QName getQName() {
95 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
98 public SchemaPath getPath() {
106 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
109 public String getDescription() {
116 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
119 public String getReference() {
126 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
129 public Status getStatus() {
130 return Status.CURRENT;
137 * org.opendaylight.yangtools.yang.model.base.type.api.EnumTypeDefinition
141 public List<EnumPair> getValues() {
146 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
147 return Collections.emptyList();
151 public int hashCode() {
152 final int prime = 31;
154 result = prime * result + ((defaultEnum == null) ? 0 : defaultEnum.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());
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)) {
181 if (other.enums != null) {
184 } else if (!enums.equals(other.enums)) {
188 if (other.name != null) {
191 } else if (!name.equals(other.name)) {
195 if (other.path != null) {
198 } else if (!path.equals(other.path)) {
205 public String toString() {
206 StringBuilder builder = new StringBuilder();
207 builder.append("EnumerationType [name=");
208 builder.append(name);
209 builder.append(", path=");
210 builder.append(path);
211 builder.append(", description=");
212 builder.append(DESCRIPTION);
213 builder.append(", reference=");
214 builder.append(REFERENCE);
215 builder.append(", defaultEnum=");
216 builder.append(defaultEnum);
217 builder.append(", enums=");
218 builder.append(enums);
219 builder.append(", units=");
220 builder.append(UNITS);
222 return builder.toString();