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;
12 import java.util.Collections;
13 import java.util.List;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.Status;
17 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
18 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
22 * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#unionTypeBuilder(SchemaPath)} instead
25 public final class UnionType implements UnionTypeDefinition {
26 private static final SchemaPath PATH = SchemaPath.create(true, BaseTypes.UNION_QNAME);
27 private static final String DESCRIPTION = "The union built-in type represents a value that corresponds to one of its member types.";
28 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.12";
29 private final List<TypeDefinition<?>> types;
31 private UnionType(final List<TypeDefinition<?>> types) {
32 Preconditions.checkNotNull(types,"When the type is 'union', the 'type' statement MUST be present.");
33 this.types = ImmutableList.copyOf(types);
36 public static UnionType create(final List<TypeDefinition<?>> types) {
37 return new UnionType(types);
41 public UnionTypeDefinition getBaseType() {
46 public String getUnits() {
51 public Object getDefaultValue() {
56 public QName getQName() {
57 return BaseTypes.UNION_QNAME;
61 public SchemaPath getPath() {
66 public String getDescription() {
71 public String getReference() {
76 public Status getStatus() {
77 return Status.CURRENT;
81 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
82 return Collections.emptyList();
86 public List<TypeDefinition<?>> getTypes() {
91 public int hashCode() {
94 result = prime * result + types.hashCode();
99 public boolean equals(final Object obj) {
106 if (getClass() != obj.getClass()) {
109 UnionType other = (UnionType) obj;
110 if (!types.equals(other.types)) {
117 public String toString() {
118 StringBuilder builder = new StringBuilder();
119 builder.append("type ");
120 builder.append(BaseTypes.UNION_QNAME);
121 builder.append(" (types=[");
122 for (TypeDefinition<?> td : types) {
123 builder.append(", " ).append(td.getQName().getLocalName());
126 return builder.toString();