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 class UnionType implements UnionTypeDefinition {
22 private final QName name = BaseTypes.constructQName("union");
23 private final SchemaPath path = BaseTypes.schemaPath(name);
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";
27 private final List<TypeDefinition<?>> types;
30 public UnionType(List<TypeDefinition<?>> types) {
32 throw new NullPointerException("When the type is 'union', the 'type' statement MUST be present.");
38 public UnionTypeDefinition getBaseType() {
43 public String getUnits() {
48 public Object getDefaultValue() {
53 public QName getQName() {
58 public SchemaPath getPath() {
63 public String getDescription() {
68 public String getReference() {
73 public Status getStatus() {
74 return Status.CURRENT;
78 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
79 return Collections.emptyList();
83 public List<TypeDefinition<?>> getTypes() {
88 public int hashCode() {
89 // TODO: implement hashcode
94 public boolean equals(Object obj) {
101 if (getClass() != obj.getClass()) {
104 UnionType other = (UnionType) obj;
106 if (other.types != null) {
109 } else if (!types.equals(other.types)) {
116 public String toString() {
117 StringBuilder builder = new StringBuilder();
118 builder.append("UnionType [name=");
119 builder.append(name);
120 builder.append(", types=[");
121 for(TypeDefinition<?> td : types) {
122 builder.append(", "+ td.getQName().getLocalName());
126 return builder.toString();