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;
21 public final class UnionType implements UnionTypeDefinition {
22 private static final SchemaPath PATH = SchemaPath.create(true, BaseTypes.UNION_QNAME);
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 private UnionType(final List<TypeDefinition<?>> types) {
28 Preconditions.checkNotNull(types,"When the type is 'union', the 'type' statement MUST be present.");
29 this.types = ImmutableList.copyOf(types);
32 public static UnionType create(final List<TypeDefinition<?>> types) {
33 return new UnionType(types);
37 public UnionTypeDefinition getBaseType() {
42 public String getUnits() {
47 public Object getDefaultValue() {
52 public QName getQName() {
53 return BaseTypes.UNION_QNAME;
57 public SchemaPath getPath() {
62 public String getDescription() {
67 public String getReference() {
72 public Status getStatus() {
73 return Status.CURRENT;
77 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
78 return Collections.emptyList();
82 public List<TypeDefinition<?>> getTypes() {
87 public int hashCode() {
90 result = prime * result + types.hashCode();
95 public boolean equals(final Object obj) {
102 if (getClass() != obj.getClass()) {
105 UnionType other = (UnionType) obj;
106 if (!types.equals(other.types)) {
113 public String toString() {
114 StringBuilder builder = new StringBuilder();
115 builder.append("type ");
116 builder.append(BaseTypes.UNION_QNAME);
117 builder.append(" (types=[");
118 for (TypeDefinition<?> td : types) {
119 builder.append(", " ).append(td.getQName().getLocalName());
122 return builder.toString();