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.TypeDefinition;
17 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
20 public final class UnionType implements UnionTypeDefinition {
21 private final QName name = BaseTypes.constructQName("union");
22 private final SchemaPath path = BaseTypes.schemaPath(name);
23 private static final String DESCRIPTION = "The union built-in type represents a value that corresponds to one of its member types.";
24 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.12";
25 private final List<TypeDefinition<?>> types;
27 public UnionType(List<TypeDefinition<?>> types) {
29 throw new IllegalArgumentException("When the type is 'union', the 'type' statement MUST be present.");
35 public UnionTypeDefinition getBaseType() {
40 public String getUnits() {
45 public Object getDefaultValue() {
50 public QName getQName() {
55 public SchemaPath getPath() {
60 public String getDescription() {
65 public String getReference() {
70 public Status getStatus() {
71 return Status.CURRENT;
75 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
76 return Collections.emptyList();
80 public List<TypeDefinition<?>> getTypes() {
85 public int hashCode() {
88 result = prime * result + ((types == null) ? 0 : types.hashCode());
93 public boolean equals(Object obj) {
100 if (getClass() != obj.getClass()) {
103 UnionType other = (UnionType) obj;
104 if (!types.equals(other.types)) {
111 public String toString() {
112 StringBuilder builder = new StringBuilder();
113 builder.append("type ");
114 builder.append(name);
115 builder.append(" (types=[");
116 for (TypeDefinition<?> td : types) {
117 builder.append(", " + td.getQName().getLocalName());
120 return builder.toString();