BUG-865: deprecate pre-Beryllium parser elements
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / 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.yangtools.yang.parser.builder.impl;
9
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.ImmutableList;
12 import java.util.Objects;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.Status;
17 import org.opendaylight.yangtools.yang.parser.builder.api.ConstraintsBuilder;
18 import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
19 import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
20 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
21 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractTypeAwareBuilder;
22
23 /**
24  * @deprecated Pre-Beryllium implementation, scheduled for removal.
25  */
26 @Deprecated
27 public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder {
28     private LeafListSchemaNodeImpl instance;
29     private boolean userOrdered;
30     // SchemaNode args
31     private SchemaPath schemaPath;
32     private String description;
33     private String reference;
34     private Status status = Status.CURRENT;
35     // DataSchemaNode args
36     private boolean augmenting;
37     private boolean addedByUses;
38     private LeafListSchemaNode originalNode;
39     private LeafListSchemaNodeBuilder originalBuilder;
40     private boolean configuration;
41     private final ConstraintsBuilder constraints;
42
43     public LeafListSchemaNodeBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path) {
44         super(moduleName, line, qname);
45         this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
46         constraints = new ConstraintsBuilderImpl(moduleName, line);
47     }
48
49     public LeafListSchemaNodeBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path,
50             final LeafListSchemaNode base) {
51         super(moduleName, line, qname);
52         this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
53         constraints = new ConstraintsBuilderImpl(moduleName, line, base.getConstraints());
54
55         description = base.getDescription();
56         reference = base.getReference();
57         status = base.getStatus();
58         augmenting = base.isAugmenting();
59         addedByUses = base.isAddedByUses();
60         originalNode = base;
61         configuration = base.isConfiguration();
62         this.type = base.getType();
63         userOrdered = base.isUserOrdered();
64         unknownNodes.addAll(base.getUnknownSchemaNodes());
65     }
66
67     @Override
68     public LeafListSchemaNode build() {
69         if (instance != null) {
70             return instance;
71         }
72
73         instance = new LeafListSchemaNodeImpl(qname, schemaPath);
74
75         instance.description = description;
76         instance.reference = reference;
77         instance.status = status;
78         instance.augmenting = augmenting;
79         instance.addedByUses = addedByUses;
80         instance.configuration = configuration;
81         instance.constraintsDef = constraints.build();
82         instance.userOrdered = userOrdered;
83
84         if (type == null) {
85             instance.type = typedef.build();
86         } else {
87             instance.type = type;
88         }
89
90         // ORIGINAL NODE
91         if (originalNode == null && originalBuilder != null) {
92             originalNode = originalBuilder.build();
93         }
94         instance.original = originalNode;
95
96         // UNKNOWN NODES
97         for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
98             unknownNodes.add(b.build());
99         }
100         instance.unknownNodes = ImmutableList.copyOf(unknownNodes);
101
102         return instance;
103     }
104
105     @Override
106     public SchemaPath getPath() {
107         return schemaPath;
108     }
109
110     @Override
111     public void setPath(final SchemaPath path) {
112         this.schemaPath = path;
113     }
114
115     @Override
116     public String getDescription() {
117         return description;
118     }
119
120     @Override
121     public void setDescription(final String description) {
122         this.description = description;
123     }
124
125     @Override
126     public String getReference() {
127         return reference;
128     }
129
130     @Override
131     public void setReference(final String reference) {
132         this.reference = reference;
133     }
134
135     @Override
136     public Status getStatus() {
137         return status;
138     }
139
140     @Override
141     public void setStatus(final Status status) {
142         this.status = Preconditions.checkNotNull(status, "status cannot be null");
143     }
144
145     @Override
146     public boolean isAugmenting() {
147         return augmenting;
148     }
149
150     @Override
151     public void setAugmenting(final boolean augmenting) {
152         this.augmenting = augmenting;
153     }
154
155     @Override
156     public boolean isAddedByUses() {
157         return addedByUses;
158     }
159
160     @Override
161     public void setAddedByUses(final boolean addedByUses) {
162         this.addedByUses = addedByUses;
163     }
164
165     @Override
166     public LeafListSchemaNodeBuilder getOriginal() {
167         return originalBuilder;
168     }
169
170     @Override
171     public void setOriginal(final SchemaNodeBuilder builder) {
172         Preconditions.checkArgument(builder instanceof LeafListSchemaNodeBuilder, "Original of leaf-list cannot be "
173                 + builder);
174         this.originalBuilder = (LeafListSchemaNodeBuilder) builder;
175     }
176
177     @Override
178     public boolean isConfiguration() {
179         return configuration;
180     }
181
182     @Override
183     public void setConfiguration(final boolean configuration) {
184         this.configuration = configuration;
185     }
186
187     @Override
188     public ConstraintsBuilder getConstraints() {
189         return constraints;
190     }
191
192     public boolean isUserOrdered() {
193         return userOrdered;
194     }
195
196     public void setUserOrdered(final boolean userOrdered) {
197         this.userOrdered = userOrdered;
198     }
199
200     @Override
201     public int hashCode() {
202         final int prime = 31;
203         int result = 1;
204         result = prime * result + Objects.hashCode(schemaPath);
205         return result;
206     }
207
208     @Override
209     public boolean equals(final Object obj) {
210         if (this == obj) {
211             return true;
212         }
213         if (obj == null) {
214             return false;
215         }
216         if (getClass() != obj.getClass()) {
217             return false;
218         }
219         LeafListSchemaNodeBuilder other = (LeafListSchemaNodeBuilder) obj;
220         if (schemaPath == null) {
221             if (other.schemaPath != null) {
222                 return false;
223             }
224         } else if (!schemaPath.equals(other.schemaPath)) {
225             return false;
226         }
227         if (getParent() == null) {
228             if (other.getParent() != null) {
229                 return false;
230             }
231         } else if (!getParent().equals(other.getParent())) {
232             return false;
233         }
234         return true;
235     }
236
237     @Override
238     public String toString() {
239         return "leaf-list " + qname.getLocalName();
240     }
241
242 }