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;
11 import java.util.Collections;
12 import java.util.Date;
13 import java.util.List;
15 import org.opendaylight.controller.yang.common.QName;
16 import org.opendaylight.controller.yang.model.api.SchemaPath;
17 import org.opendaylight.controller.yang.model.api.Status;
18 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
19 import org.opendaylight.controller.yang.model.api.type.EnumTypeDefinition;
22 * The <code>default</code> implementation of Enumertaion Type Definition interface.
24 * @see EnumTypeDefinition
26 public class EnumerationType implements EnumTypeDefinition {
28 private final QName name = BaseTypes.constructQName("enumeration");
29 private final SchemaPath path;
30 private final String description = "The enumeration built-in type represents values from a set of assigned names.";
31 private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.6";
33 private final EnumPair defaultEnum;
34 private final List<EnumPair> enums;
35 private String units = "";
36 private final EnumTypeDefinition baseType;
38 private EnumerationType(final List<EnumPair> enums) {
39 this.path = BaseTypes.schemaPath(name);
40 this.enums = Collections.unmodifiableList(enums);
41 this.defaultEnum = null;
45 public EnumerationType(final List<String> actualPath, final URI namespace,
46 final Date revision, final List<EnumPair> enums) {
48 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
49 this.enums = Collections.unmodifiableList(enums);
50 this.defaultEnum = null;
51 baseType = new EnumerationType(enums);
54 public EnumerationType(final List<String> actualPath, final URI namespace,
55 final Date revision, final EnumTypeDefinition baseType, final EnumPair defaultEnum,
56 final List<EnumPair> enums, final String units) {
58 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
59 this.baseType = baseType;
60 this.defaultEnum = defaultEnum;
61 this.enums = Collections.unmodifiableList(enums);
68 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
71 public EnumTypeDefinition getBaseType() {
78 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
81 public String getUnits() {
88 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
91 public Object getDefaultValue() {
98 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
101 public QName getQName() {
108 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
111 public SchemaPath getPath() {
118 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
121 public String getDescription() {
128 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
131 public String getReference() {
138 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
141 public Status getStatus() {
142 return Status.CURRENT;
148 * @see org.opendaylight.controller.yang.model.base.type.api.EnumTypeDefinition#getValues()
151 public List<EnumPair> getValues() {
156 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
157 return Collections.emptyList();
161 public int hashCode() {
162 final int prime = 31;
164 result = prime * result
165 + ((defaultEnum == null) ? 0 : defaultEnum.hashCode());
166 result = prime * result
167 + ((description == null) ? 0 : description.hashCode());
168 result = prime * result + ((enums == null) ? 0 : enums.hashCode());
169 result = prime * result + ((name == null) ? 0 : name.hashCode());
170 result = prime * result + ((path == null) ? 0 : path.hashCode());
171 result = prime * result
172 + ((reference == null) ? 0 : reference.hashCode());
173 result = prime * result + ((units == null) ? 0 : units.hashCode());
178 public boolean equals(Object obj) {
185 if (getClass() != obj.getClass()) {
188 EnumerationType other = (EnumerationType) obj;
189 if (defaultEnum == null) {
190 if (other.defaultEnum != null) {
193 } else if (!defaultEnum.equals(other.defaultEnum)) {
196 if (description == null) {
197 if (other.description != null) {
200 } else if (!description.equals(other.description)) {
204 if (other.enums != null) {
207 } else if (!enums.equals(other.enums)) {
211 if (other.name != null) {
214 } else if (!name.equals(other.name)) {
218 if (other.path != null) {
221 } else if (!path.equals(other.path)) {
224 if (reference == null) {
225 if (other.reference != null) {
228 } else if (!reference.equals(other.reference)) {
232 if (other.units != null) {
235 } else if (!units.equals(other.units)) {
242 public String toString() {
243 StringBuilder builder = new StringBuilder();
244 builder.append("EnumerationType [name=");
245 builder.append(name);
246 builder.append(", path=");
247 builder.append(path);
248 builder.append(", description=");
249 builder.append(description);
250 builder.append(", reference=");
251 builder.append(reference);
252 builder.append(", defaultEnum=");
253 builder.append(defaultEnum);
254 builder.append(", enums=");
255 builder.append(enums);
256 builder.append(", units=");
257 builder.append(units);
259 return builder.toString();