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 final String description = "The union built-in type represents a value that corresponds to one of its member types.";
24 private 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 NullPointerException(
30 "When the type is 'union', the 'type' statement MUST be present.");
36 public UnionTypeDefinition getBaseType() {
41 public String getUnits() {
46 public Object getDefaultValue() {
51 public QName getQName() {
56 public SchemaPath getPath() {
61 public String getDescription() {
66 public String getReference() {
71 public Status getStatus() {
72 return Status.CURRENT;
76 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
77 return Collections.emptyList();
81 public List<TypeDefinition<?>> getTypes() {
86 public int hashCode() {
89 result = prime * result + ((types == null) ? 0 : types.hashCode());
94 public boolean equals(Object obj) {
101 if (getClass() != obj.getClass()) {
104 UnionType other = (UnionType) obj;
105 if (!types.equals(other.types)) {
112 public String toString() {
113 StringBuilder builder = new StringBuilder();
114 builder.append("type ");
115 builder.append(name);
116 builder.append(" (types=[");
117 for (TypeDefinition<?> td : types) {
118 builder.append(", " + td.getQName().getLocalName());
121 return builder.toString();