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;
19 import com.google.common.collect.ImmutableList;
22 * The <code>default</code> implementation of Enumeration Type Definition
25 * @see EnumTypeDefinition
27 public final class EnumerationType implements EnumTypeDefinition {
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";
30 private static final String UNITS = "";
32 private final SchemaPath path;
33 private final EnumPair defaultEnum;
34 private final List<EnumPair> enums;
36 public EnumerationType(final SchemaPath path, final List<EnumPair> enums) {
39 this.enums = ImmutableList.copyOf(enums);
40 this.defaultEnum = null;
43 public EnumerationType(final SchemaPath path, final EnumPair defaultEnum, final List<EnumPair> enums) {
46 this.defaultEnum = defaultEnum;
47 this.enums = ImmutableList.copyOf(enums);
54 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
57 public EnumTypeDefinition getBaseType() {
64 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
67 public String getUnits() {
75 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
79 public Object getDefaultValue() {
86 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
89 public QName getQName() {
90 return BaseTypes.ENUMERATION_QNAME;
96 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
99 public SchemaPath getPath() {
107 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
110 public String getDescription() {
117 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
120 public String getReference() {
127 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
130 public Status getStatus() {
131 return Status.CURRENT;
138 * org.opendaylight.yangtools.yang.model.base.type.api.EnumTypeDefinition
142 public List<EnumPair> getValues() {
147 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
148 return Collections.emptyList();
152 public int hashCode() {
153 final int prime = 31;
155 result = prime * result + ((defaultEnum == null) ? 0 : defaultEnum.hashCode());
156 result = prime * result + ((enums == null) ? 0 : enums.hashCode());
157 result = prime * result + BaseTypes.ENUMERATION_QNAME.hashCode();
158 result = prime * result + ((path == null) ? 0 : path.hashCode());
163 public boolean equals(final Object obj) {
170 if (getClass() != obj.getClass()) {
173 EnumerationType other = (EnumerationType) obj;
174 if (defaultEnum == null) {
175 if (other.defaultEnum != null) {
178 } else if (!defaultEnum.equals(other.defaultEnum)) {
182 if (other.enums != null) {
185 } else if (!enums.equals(other.enums)) {
189 if (other.path != null) {
192 } else if (!path.equals(other.path)) {
199 public String toString() {
200 StringBuilder builder = new StringBuilder();
201 builder.append("EnumerationType [name=");
202 builder.append(BaseTypes.ENUMERATION_QNAME);
203 builder.append(", path=");
204 builder.append(path);
205 builder.append(", description=");
206 builder.append(DESCRIPTION);
207 builder.append(", reference=");
208 builder.append(REFERENCE);
209 builder.append(", defaultEnum=");
210 builder.append(defaultEnum);
211 builder.append(", enums=");
212 builder.append(enums);
213 builder.append(", units=");
214 builder.append(UNITS);
216 return builder.toString();