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.TypeDefinition;
19 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
20 import org.opendaylight.controller.yang.model.api.type.UnionTypeDefinition;
22 public class UnionType implements UnionTypeDefinition {
24 private final QName name = BaseTypes.constructQName("union");
25 private final SchemaPath path;
26 private final String description = "The union built-in type represents a value that corresponds to one of its member types.";
27 private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.12";
28 private final UnionTypeDefinition baseType;
29 private final List<TypeDefinition<?>> types;
31 private UnionType(List<TypeDefinition<?>> types) {
33 throw new NullPointerException("When the type is 'union', the 'type' statement MUST be present.");
35 path = BaseTypes.schemaPath(name);
40 public UnionType(final List<String> actualPath, final URI namespace,
41 final Date revision, List<TypeDefinition<?>> types) {
43 throw new NullPointerException("When the type is 'union', the 'type' statement MUST be present.");
45 path = BaseTypes.schemaPath(actualPath, namespace, revision);
47 this.baseType = new UnionType(types);
51 public UnionTypeDefinition getBaseType() {
56 public String getUnits() {
61 public Object getDefaultValue() {
66 public QName getQName() {
71 public SchemaPath getPath() {
76 public String getDescription() {
81 public String getReference() {
86 public Status getStatus() {
87 return Status.CURRENT;
91 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
92 return Collections.emptyList();
96 public List<TypeDefinition<?>> getTypes() {
101 public int hashCode() {
102 final int prime = 31;
104 result = prime * result + ((name == null) ? 0 : name.hashCode());
105 result = prime * result + ((path == null) ? 0 : path.hashCode());
106 result = prime * result + ((types == null) ? 0 : types.hashCode());
111 public boolean equals(Object obj) {
118 if (getClass() != obj.getClass()) {
121 UnionType other = (UnionType) obj;
123 if (other.types != null) {
126 } else if (!types.equals(other.types)) {
133 public String toString() {
134 StringBuilder builder = new StringBuilder();
135 builder.append("UnionType [name=");
136 builder.append(name);
137 builder.append(", types=[");
138 for(TypeDefinition<?> td : types) {
139 builder.append(", "+ td.getQName().getLocalName());
143 return builder.toString();