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.TypeDefinition;
17 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.controller.yang.model.api.type.UnionTypeDefinition;
20 public final class UnionType implements UnionTypeDefinition {
22 private final QName name = BaseTypes.constructQName("union");
23 private final SchemaPath path;
24 private final String description = "The union built-in type represents a value that corresponds to one of its member types.";
25 private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.12";
26 private final UnionTypeDefinition baseType;
27 private final List<TypeDefinition<?>> types;
29 private UnionType(List<TypeDefinition<?>> types) {
31 throw new NullPointerException(
32 "When the type is 'union', the 'type' statement MUST be present.");
34 path = BaseTypes.schemaPath(name);
39 public UnionType(final SchemaPath path, List<TypeDefinition<?>> types) {
41 throw new NullPointerException(
42 "When the type is 'union', the 'type' statement MUST be present.");
46 this.baseType = new UnionType(types);
50 public UnionTypeDefinition getBaseType() {
55 public String getUnits() {
60 public Object getDefaultValue() {
65 public QName getQName() {
70 public SchemaPath getPath() {
75 public String getDescription() {
80 public String getReference() {
85 public Status getStatus() {
86 return Status.CURRENT;
90 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
91 return Collections.emptyList();
95 public List<TypeDefinition<?>> getTypes() {
100 public int hashCode() {
101 final int prime = 31;
103 result = prime * result + ((name == null) ? 0 : name.hashCode());
104 result = prime * result + ((path == null) ? 0 : path.hashCode());
105 result = prime * result + ((types == null) ? 0 : types.hashCode());
110 public boolean equals(Object obj) {
117 if (getClass() != obj.getClass()) {
120 UnionType other = (UnionType) obj;
122 if (other.types != null) {
125 } else if (!types.equals(other.types)) {
132 public String toString() {
133 StringBuilder builder = new StringBuilder();
134 builder.append("UnionType [name=");
135 builder.append(name);
136 builder.append(", types=[");
137 for (TypeDefinition<?> td : types) {
138 builder.append(", " + td.getQName().getLocalName());
142 return builder.toString();