99d3e647940c06ceebb0debf22c40426540941a9
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / model / parser / builder / impl / LeafListSchemaNodeBuilder.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.model.parser.builder.impl;
9
10 import java.util.Collections;
11 import java.util.List;
12
13 import org.opendaylight.controller.yang.common.QName;
14 import org.opendaylight.controller.yang.model.api.ConstraintDefinition;
15 import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
16 import org.opendaylight.controller.yang.model.api.SchemaPath;
17 import org.opendaylight.controller.yang.model.api.Status;
18 import org.opendaylight.controller.yang.model.api.TypeDefinition;
19 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
20 import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder;
21 import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder;
22 import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder;
23
24 public class LeafListSchemaNodeBuilder implements SchemaNodeBuilder,
25         TypeAwareBuilder, DataSchemaNodeBuilder {
26
27     private final LeafListSchemaNodeImpl instance;
28     private final QName qname;
29     private final ConstraintsBuilder constraintsBuilder;
30     private TypeDefinition<?> type;
31
32     LeafListSchemaNodeBuilder(QName qname) {
33         this.qname = qname;
34         instance = new LeafListSchemaNodeImpl(qname);
35         constraintsBuilder = new ConstraintsBuilder();
36     }
37
38     @Override
39     public LeafListSchemaNode build() {
40         instance.setConstraints(constraintsBuilder.build());
41         return instance;
42     }
43
44     @Override
45     public QName getQName() {
46         return qname;
47     }
48
49     @Override
50     public void setPath(SchemaPath path) {
51         instance.setPath(path);
52     }
53
54     @Override
55     public void setDescription(String description) {
56         instance.setDescription(description);
57     }
58
59     @Override
60     public void setReference(String reference) {
61         instance.setReference(reference);
62     }
63
64     @Override
65     public void setStatus(Status status) {
66         if(status != null) {
67             instance.setStatus(status);
68         }
69     }
70
71     @Override
72     public TypeDefinition<?> getType() {
73         return type;
74     }
75
76     @Override
77     public void setType(TypeDefinition<?> type) {
78         this.type = type;
79         instance.setType(type);
80     }
81
82     @Override
83     public void setAugmenting(boolean augmenting) {
84         instance.setAugmenting(augmenting);
85     }
86
87     @Override
88     public void setConfiguration(boolean configuration) {
89         instance.setConfiguration(configuration);
90     }
91
92     @Override
93     public ConstraintsBuilder getConstraintsBuilder() {
94         return constraintsBuilder;
95     }
96
97     public void setUserOrdered(boolean userOrdered) {
98         instance.setUserOrdered(userOrdered);
99     }
100
101     private class LeafListSchemaNodeImpl implements LeafListSchemaNode {
102         private final QName qname;
103         private SchemaPath path;
104         private String description;
105         private String reference;
106         private Status status = Status.CURRENT;
107         private boolean augmenting;
108         private boolean configuration;
109         private ConstraintDefinition constraints;
110         private TypeDefinition<?> type;
111         private boolean userOrdered;
112         private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();
113
114         private LeafListSchemaNodeImpl(QName qname) {
115             this.qname = qname;
116         }
117
118         @Override
119         public QName getQName() {
120             return qname;
121         }
122
123         @Override
124         public SchemaPath getPath() {
125             return path;
126         }
127
128         private void setPath(SchemaPath path) {
129             this.path = path;
130         }
131
132         @Override
133         public String getDescription() {
134             return description;
135         }
136
137         private void setDescription(String description) {
138             this.description = description;
139         }
140
141         @Override
142         public String getReference() {
143             return reference;
144         }
145
146         private void setReference(String reference) {
147             this.reference = reference;
148         }
149
150         @Override
151         public Status getStatus() {
152             return status;
153         }
154
155         private void setStatus(Status status) {
156             this.status = status;
157         }
158
159         @Override
160         public boolean isAugmenting() {
161             return augmenting;
162         }
163
164         private void setAugmenting(boolean augmenting) {
165             this.augmenting = augmenting;
166         }
167
168         @Override
169         public boolean isConfiguration() {
170             return configuration;
171         }
172
173         private void setConfiguration(boolean configuration) {
174             this.configuration = configuration;
175         }
176
177         @Override
178         public ConstraintDefinition getConstraints() {
179             return constraints;
180         }
181
182         private void setConstraints(ConstraintDefinition constraints) {
183             this.constraints = constraints;
184         }
185
186         @Override
187         public TypeDefinition<?> getType() {
188             return type;
189         }
190
191         public void setType(TypeDefinition<? extends TypeDefinition<?>> type) {
192             this.type = type;
193         }
194
195         @Override
196         public boolean isUserOrdered() {
197             return userOrdered;
198         }
199
200         private void setUserOrdered(boolean userOrdered) {
201             this.userOrdered = userOrdered;
202         }
203
204         @Override
205         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
206             return unknownSchemaNodes;
207         }
208
209         @Override
210         public int hashCode() {
211             final int prime = 31;
212             int result = 1;
213             result = prime * result + ((qname == null) ? 0 : qname.hashCode());
214             result = prime * result + ((path == null) ? 0 : path.hashCode());
215             result = prime * result
216                     + ((description == null) ? 0 : description.hashCode());
217             result = prime * result
218                     + ((reference == null) ? 0 : reference.hashCode());
219             result = prime * result
220                     + ((status == null) ? 0 : status.hashCode());
221             result = prime * result + (augmenting ? 1231 : 1237);
222             result = prime * result + (configuration ? 1231 : 1237);
223             result = prime * result
224                     + ((constraints == null) ? 0 : constraints.hashCode());
225             result = prime * result + ((type == null) ? 0 : type.hashCode());
226             result = prime * result + (userOrdered ? 1231 : 1237);
227             return result;
228         }
229
230         @Override
231         public boolean equals(Object obj) {
232             if (this == obj) {
233                 return true;
234             }
235             if (obj == null) {
236                 return false;
237             }
238             if (getClass() != obj.getClass()) {
239                 return false;
240             }
241             LeafListSchemaNodeImpl other = (LeafListSchemaNodeImpl) obj;
242             if (qname == null) {
243                 if (other.qname != null) {
244                     return false;
245                 }
246             } else if (!qname.equals(other.qname)) {
247                 return false;
248             }
249             if (path == null) {
250                 if (other.path != null) {
251                     return false;
252                 }
253             } else if (!path.equals(other.path)) {
254                 return false;
255             }
256             if (description == null) {
257                 if (other.description != null) {
258                     return false;
259                 }
260             } else if (!description.equals(other.description)) {
261                 return false;
262             }
263             if (reference == null) {
264                 if (other.reference != null) {
265                     return false;
266                 }
267             } else if (!reference.equals(other.reference)) {
268                 return false;
269             }
270             if (status == null) {
271                 if (other.status != null) {
272                     return false;
273                 }
274             } else if (!status.equals(other.status)) {
275                 return false;
276             }
277             if (augmenting != other.augmenting) {
278                 return false;
279             }
280             if (configuration != other.configuration) {
281                 return false;
282             }
283             if (constraints == null) {
284                 if (other.constraints != null) {
285                     return false;
286                 }
287             } else if (!constraints.equals(other.constraints)) {
288                 return false;
289             }
290             if (type == null) {
291                 if (other.type != null) {
292                     return false;
293                 }
294             } else if (!type.equals(other.type)) {
295                 return false;
296             }
297             if (userOrdered != other.userOrdered) {
298                 return false;
299             }
300             return true;
301         }
302
303         @Override
304         public String toString() {
305             StringBuilder sb = new StringBuilder(
306                     LeafListSchemaNodeImpl.class.getSimpleName());
307             sb.append("[");
308             sb.append("qname=" + qname);
309             sb.append(", path=" + path);
310             sb.append(", description=" + description);
311             sb.append(", reference=" + reference);
312             sb.append(", status=" + status);
313             sb.append(", augmenting=" + augmenting);
314             sb.append(", configuration=" + configuration);
315             sb.append(", constraints=" + constraints);
316             sb.append(", type=" + type);
317             sb.append(", userOrdered=" + userOrdered);
318             sb.append("]");
319             return sb.toString();
320         }
321     }
322
323 }