Refactor frontend JS
[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.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.ConstraintDefinition;
16 import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
17 import org.opendaylight.controller.yang.model.api.SchemaPath;
18 import org.opendaylight.controller.yang.model.api.Status;
19 import org.opendaylight.controller.yang.model.api.TypeDefinition;
20 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
21 import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder;
22 import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder;
23 import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder;
24
25 public class LeafListSchemaNodeBuilder implements SchemaNodeBuilder,
26         TypeAwareBuilder, DataSchemaNodeBuilder {
27
28     private final LeafListSchemaNodeImpl instance;
29     private final QName qname;
30     private final ConstraintsBuilder constraintsBuilder = new ConstraintsBuilder();
31     private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
32     private TypeDefinition<?> type;
33
34     LeafListSchemaNodeBuilder(QName qname) {
35         this.qname = qname;
36         instance = new LeafListSchemaNodeImpl(qname);
37     }
38
39     @Override
40     public LeafListSchemaNode build() {
41         instance.setConstraints(constraintsBuilder.build());
42         return instance;
43     }
44
45     @Override
46     public QName getQName() {
47         return qname;
48     }
49
50     @Override
51     public void setPath(SchemaPath path) {
52         instance.setPath(path);
53     }
54
55     @Override
56     public void setDescription(String description) {
57         instance.setDescription(description);
58     }
59
60     @Override
61     public void setReference(String reference) {
62         instance.setReference(reference);
63     }
64
65     @Override
66     public void setStatus(Status status) {
67         if(status != null) {
68             instance.setStatus(status);
69         }
70     }
71
72     @Override
73     public TypeDefinition<?> getType() {
74         return type;
75     }
76
77     @Override
78     public void setType(TypeDefinition<?> type) {
79         this.type = type;
80         instance.setType(type);
81     }
82
83     @Override
84     public void setAugmenting(boolean augmenting) {
85         instance.setAugmenting(augmenting);
86     }
87
88     @Override
89     public void setConfiguration(boolean configuration) {
90         instance.setConfiguration(configuration);
91     }
92
93     @Override
94     public ConstraintsBuilder getConstraintsBuilder() {
95         return constraintsBuilder;
96     }
97
98     public void setUserOrdered(boolean userOrdered) {
99         instance.setUserOrdered(userOrdered);
100     }
101
102     @Override
103     public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
104         addedUnknownNodes.add(unknownSchemaNodeBuilder);
105     }
106
107     private class LeafListSchemaNodeImpl implements LeafListSchemaNode {
108         private final QName qname;
109         private SchemaPath path;
110         private String description;
111         private String reference;
112         private Status status = Status.CURRENT;
113         private boolean augmenting;
114         private boolean configuration;
115         private ConstraintDefinition constraints;
116         private TypeDefinition<?> type;
117         private boolean userOrdered;
118         private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();
119
120         private LeafListSchemaNodeImpl(QName qname) {
121             this.qname = qname;
122         }
123
124         @Override
125         public QName getQName() {
126             return qname;
127         }
128
129         @Override
130         public SchemaPath getPath() {
131             return path;
132         }
133
134         private void setPath(SchemaPath path) {
135             this.path = path;
136         }
137
138         @Override
139         public String getDescription() {
140             return description;
141         }
142
143         private void setDescription(String description) {
144             this.description = description;
145         }
146
147         @Override
148         public String getReference() {
149             return reference;
150         }
151
152         private void setReference(String reference) {
153             this.reference = reference;
154         }
155
156         @Override
157         public Status getStatus() {
158             return status;
159         }
160
161         private void setStatus(Status status) {
162             this.status = status;
163         }
164
165         @Override
166         public boolean isAugmenting() {
167             return augmenting;
168         }
169
170         private void setAugmenting(boolean augmenting) {
171             this.augmenting = augmenting;
172         }
173
174         @Override
175         public boolean isConfiguration() {
176             return configuration;
177         }
178
179         private void setConfiguration(boolean configuration) {
180             this.configuration = configuration;
181         }
182
183         @Override
184         public ConstraintDefinition getConstraints() {
185             return constraints;
186         }
187
188         private void setConstraints(ConstraintDefinition constraints) {
189             this.constraints = constraints;
190         }
191
192         @Override
193         public TypeDefinition<?> getType() {
194             return type;
195         }
196
197         public void setType(TypeDefinition<? extends TypeDefinition<?>> type) {
198             this.type = type;
199         }
200
201         @Override
202         public boolean isUserOrdered() {
203             return userOrdered;
204         }
205
206         private void setUserOrdered(boolean userOrdered) {
207             this.userOrdered = userOrdered;
208         }
209
210         @Override
211         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
212             return unknownSchemaNodes;
213         }
214
215         private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
216             if(unknownSchemaNodes != null) {
217                 this.unknownSchemaNodes = unknownSchemaNodes;
218             }
219         }
220
221         @Override
222         public int hashCode() {
223             final int prime = 31;
224             int result = 1;
225             result = prime * result + ((qname == null) ? 0 : qname.hashCode());
226             result = prime * result + ((path == null) ? 0 : path.hashCode());
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             return true;
257         }
258
259         @Override
260         public String toString() {
261             StringBuilder sb = new StringBuilder(
262                     LeafListSchemaNodeImpl.class.getSimpleName());
263             sb.append("[");
264             sb.append("qname=" + qname);
265             sb.append(", path=" + path);
266             sb.append(", description=" + description);
267             sb.append(", reference=" + reference);
268             sb.append(", status=" + status);
269             sb.append(", augmenting=" + augmenting);
270             sb.append(", configuration=" + configuration);
271             sb.append(", constraints=" + constraints);
272             sb.append(", type=" + type);
273             sb.append(", userOrdered=" + userOrdered);
274             sb.append("]");
275             return sb.toString();
276         }
277     }
278
279 }