Removed Equals/HashCodeBuilder for ARP/LLDPTLV
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / parser / builder / impl / UnionTypeBuilder.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.controller.yang.parser.builder.impl;
9
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
13
14 import org.opendaylight.controller.yang.common.QName;
15 import org.opendaylight.controller.yang.model.api.SchemaPath;
16 import org.opendaylight.controller.yang.model.api.Status;
17 import org.opendaylight.controller.yang.model.api.TypeDefinition;
18 import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
19 import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
20 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
21 import org.opendaylight.controller.yang.model.util.UnionType;
22 import org.opendaylight.controller.yang.parser.builder.api.AbstractTypeAwareBuilder;
23 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
24 import org.opendaylight.controller.yang.parser.util.YangParseException;
25
26 /**
27  * Builder for YANG union type. User can add type to this union as
28  * TypeDefinition object (resolved type) or in form of TypeDefinitionBuilder.
29  * When build is called, types in builder form will be built and add to resolved
30  * types.
31  */
32 public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
33         TypeDefinitionBuilder {
34     private final static String NAME = "union";
35
36     private final int line;
37     private final List<TypeDefinition<?>> types;
38     private final List<TypeDefinitionBuilder> typedefs;
39     private UnionType instance;
40     private boolean isBuilt;
41
42     private SchemaPath path;
43
44     public UnionTypeBuilder(final int line) {
45         this.line = line;
46         types = new ArrayList<TypeDefinition<?>>();
47         typedefs = new ArrayList<TypeDefinitionBuilder>();
48     }
49
50     @Override
51     public int getLine() {
52         return line;
53     }
54
55     public List<TypeDefinition<?>> getTypes() {
56         return types;
57     }
58
59     @Override
60     public TypeDefinition<?> getType() {
61         return null;
62     }
63
64     public List<TypeDefinitionBuilder> getTypedefs() {
65         return Collections.unmodifiableList(typedefs);
66     }
67
68     @Override
69     public TypeDefinitionBuilder getTypedef() {
70         return null;
71     }
72
73     @Override
74     public void setType(final TypeDefinition<?> type) {
75         types.add(type);
76     }
77
78     @Override
79     public void setType(final TypeDefinitionBuilder tdb) {
80         typedefs.add(tdb);
81     }
82
83     @Override
84     public UnionType build() {
85         if (!isBuilt) {
86             instance = new UnionType(path, types);
87             for (TypeDefinitionBuilder tdb : typedefs) {
88                 types.add(tdb.build());
89             }
90             isBuilt = true;
91         }
92         return instance;
93     }
94
95     @Override
96     public void setPath(final SchemaPath schemaPath) {
97         this.path = schemaPath;
98     }
99
100     @Override
101     public void setDescription(final String description) {
102         throw new YangParseException(line, "Can not set description to " + NAME);
103     }
104
105     @Override
106     public void setReference(final String reference) {
107         throw new YangParseException(line, "Can not set reference to " + NAME);
108     }
109
110     @Override
111     public void setStatus(final Status status) {
112         throw new YangParseException(line, "Can not set status to " + NAME);
113     }
114
115     @Override
116     public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
117         throw new YangParseException(line, "Can not add unknown node to "
118                 + NAME);
119     }
120
121     @Override
122     public QName getQName() {
123         return null;
124     }
125
126     @Override
127     public SchemaPath getPath() {
128         return null;
129     }
130
131     @Override
132     public String getDescription() {
133         return null;
134     }
135
136     @Override
137     public String getReference() {
138         return null;
139     }
140
141     @Override
142     public Status getStatus() {
143         return null;
144     }
145
146     @Override
147     public List<RangeConstraint> getRanges() {
148         return Collections.emptyList();
149     }
150
151     @Override
152     public void setRanges(List<RangeConstraint> ranges) {
153         throw new YangParseException(line, "Can not set ranges to " + NAME);
154     }
155
156     @Override
157     public List<LengthConstraint> getLengths() {
158         return Collections.emptyList();
159     }
160
161     @Override
162     public void setLengths(List<LengthConstraint> lengths) {
163         throw new YangParseException(line, "Can not set lengths to " + NAME);
164     }
165
166     @Override
167     public List<PatternConstraint> getPatterns() {
168         return Collections.emptyList();
169     }
170
171     @Override
172     public void setPatterns(List<PatternConstraint> patterns) {
173         throw new YangParseException(line, "Can not set patterns to " + NAME);
174     }
175
176     @Override
177     public Integer getFractionDigits() {
178         return null;
179     }
180
181     @Override
182     public void setFractionDigits(Integer fractionDigits) {
183         throw new YangParseException(line, "Can not set fraction digits to "
184                 + NAME);
185     }
186
187     @Override
188     public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
189         return Collections.emptyList();
190     }
191
192     @Override
193     public Object getDefaultValue() {
194         return null;
195     }
196
197     @Override
198     public void setDefaultValue(Object defaultValue) {
199         throw new YangParseException(line, "Can not set default value to "
200                 + NAME);
201     }
202
203     @Override
204     public String getUnits() {
205         return null;
206     }
207
208     @Override
209     public void setUnits(String units) {
210         throw new YangParseException(line, "Can not set units to " + NAME);
211     }
212
213     @Override
214     public String toString() {
215         final StringBuilder result = new StringBuilder(
216                 UnionTypeBuilder.class.getSimpleName() + "[");
217         result.append(", types=" + types);
218         result.append(", typedefs=" + typedefs);
219         result.append("]");
220         return result.toString();
221     }
222
223 }