BUG-865: mark yang-model-util types as deprecated
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / UnionType.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.util;
9
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;
20
21 /**
22  * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#unionTypeBuilder(SchemaPath)} instead
23  */
24 @Deprecated
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;
30
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);
34     }
35
36     public static UnionType create(final List<TypeDefinition<?>> types) {
37         return new UnionType(types);
38     }
39
40     @Override
41     public UnionTypeDefinition getBaseType() {
42         return null;
43     }
44
45     @Override
46     public String getUnits() {
47         return null;
48     }
49
50     @Override
51     public Object getDefaultValue() {
52         return null;
53     }
54
55     @Override
56     public QName getQName() {
57         return BaseTypes.UNION_QNAME;
58     }
59
60     @Override
61     public SchemaPath getPath() {
62         return PATH;
63     }
64
65     @Override
66     public String getDescription() {
67         return DESCRIPTION;
68     }
69
70     @Override
71     public String getReference() {
72         return REFERENCE;
73     }
74
75     @Override
76     public Status getStatus() {
77         return Status.CURRENT;
78     }
79
80     @Override
81     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
82         return Collections.emptyList();
83     }
84
85     @Override
86     public List<TypeDefinition<?>> getTypes() {
87         return types;
88     }
89
90     @Override
91     public int hashCode() {
92         final int prime = 31;
93         int result = 1;
94         result = prime * result + types.hashCode();
95         return result;
96     }
97
98     @Override
99     public boolean equals(final Object obj) {
100         if (this == obj) {
101             return true;
102         }
103         if (obj == null) {
104             return false;
105         }
106         if (getClass() != obj.getClass()) {
107             return false;
108         }
109         UnionType other = (UnionType) obj;
110         if (!types.equals(other.types)) {
111             return false;
112         }
113         return true;
114     }
115
116     @Override
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());
124         }
125         builder.append(']');
126         return builder.toString();
127     }
128
129 }