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 com.google.common.base.Preconditions;
11 import com.google.common.collect.ImmutableList;
13 import java.util.Collections;
14 import java.util.List;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
18 import org.opendaylight.yangtools.yang.model.api.Status;
19 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
20 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
23 public final class UnionType implements UnionTypeDefinition {
24 private static final SchemaPath PATH = SchemaPath.create(true, BaseTypes.UNION_QNAME);
25 private static final String DESCRIPTION = "The union built-in type represents a value that corresponds to one of its member types.";
26 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.12";
27 private final List<TypeDefinition<?>> types;
30 public UnionType(final List<TypeDefinition<?>> types) {
31 Preconditions.checkNotNull(types,"When the type is 'union', the 'type' statement MUST be present.");
32 this.types = ImmutableList.copyOf(types);
35 public static UnionType create(final List<TypeDefinition<?>> types) {
36 return new UnionType(types);
40 public UnionTypeDefinition getBaseType() {
45 public String getUnits() {
50 public Object getDefaultValue() {
55 public QName getQName() {
56 return BaseTypes.UNION_QNAME;
60 public SchemaPath getPath() {
65 public String getDescription() {
70 public String getReference() {
75 public Status getStatus() {
76 return Status.CURRENT;
80 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
81 return Collections.emptyList();
85 public List<TypeDefinition<?>> getTypes() {
90 public int hashCode() {
93 result = prime * result + ((types == null) ? 0 : types.hashCode());
98 public boolean equals(final Object obj) {
105 if (getClass() != obj.getClass()) {
108 UnionType other = (UnionType) obj;
109 if (!types.equals(other.types)) {
116 public String toString() {
117 StringBuilder builder = new StringBuilder();
118 builder.append("type ");
119 builder.append(BaseTypes.UNION_QNAME);
120 builder.append(" (types=[");
121 for (TypeDefinition<?> td : types) {
122 builder.append(", " + td.getQName().getLocalName());
125 return builder.toString();