YANG model parser refactoring
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / yang / model / util / StringType.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.util;
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.UnknownSchemaNode;
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.StringTypeDefinition;
21
22 /**
23  * The <code>default</code> implementation of String Type Definition interface.
24  *
25  * @see StringTypeDefinition
26  */
27 public class StringType implements StringTypeDefinition {
28
29     private final QName name = BaseTypes.constructQName("string");;
30     private final SchemaPath path;
31     private String defaultValue = "";
32     private final String description = "";
33     private final String reference = "";
34     private final List<LengthConstraint> lengthStatements;
35     private final List<PatternConstraint> patterns;
36     private String units = "";
37
38     /**
39      * Default Constructor.
40      */
41     public StringType() {
42         super();
43         path = BaseTypes.schemaPath(name);
44         final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
45         constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
46         lengthStatements = Collections.unmodifiableList(constraints);
47
48         this.patterns = Collections.emptyList();
49     }
50
51     /**
52      *
53      *
54      * @param lengthStatements
55      * @param patterns
56      */
57     public StringType(final List<LengthConstraint> lengthStatements,
58             final List<PatternConstraint> patterns) {
59         super();
60         path = BaseTypes.schemaPath(name);
61         if(lengthStatements == null || lengthStatements.size() == 0) {
62             final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
63             constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
64             this.lengthStatements = Collections.unmodifiableList(constraints);
65         } else {
66             this.lengthStatements = Collections.unmodifiableList(lengthStatements);
67         }
68         this.patterns = Collections.unmodifiableList(patterns);
69     }
70
71     /**
72      *
73      *
74      * @param defaultValue
75      * @param lengthStatements
76      * @param patterns
77      * @param units
78      */
79     public StringType(final String defaultValue,
80             final List<LengthConstraint> lengthStatements,
81             final List<PatternConstraint> patterns, final String units) {
82         super();
83         path = BaseTypes.schemaPath(name);
84         this.defaultValue = defaultValue;
85         if(lengthStatements == null || lengthStatements.size() == 0) {
86             final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
87             constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
88             this.lengthStatements = Collections.unmodifiableList(constraints);
89         } else {
90             this.lengthStatements = Collections.unmodifiableList(lengthStatements);
91         }
92         this.patterns = patterns;
93         this.units = units;
94     }
95
96     /*
97      * (non-Javadoc)
98      *
99      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
100      */
101     @Override
102     public StringTypeDefinition getBaseType() {
103         return this;
104     }
105
106     /*
107      * (non-Javadoc)
108      *
109      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
110      */
111     @Override
112     public String getUnits() {
113         return units;
114     }
115
116     /*
117      * (non-Javadoc)
118      *
119      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
120      */
121     @Override
122     public Object getDefaultValue() {
123         return defaultValue;
124     }
125
126     /*
127      * (non-Javadoc)
128      *
129      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
130      */
131     @Override
132     public QName getQName() {
133         return name;
134     }
135
136     /*
137      * (non-Javadoc)
138      *
139      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
140      */
141     @Override
142     public SchemaPath getPath() {
143         return path;
144     }
145
146     /*
147      * (non-Javadoc)
148      *
149      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
150      */
151     @Override
152     public String getDescription() {
153         return description;
154     }
155
156     /*
157      * (non-Javadoc)
158      *
159      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
160      */
161     @Override
162     public String getReference() {
163         return reference;
164     }
165
166     /*
167      * (non-Javadoc)
168      *
169      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
170      */
171     @Override
172     public Status getStatus() {
173         return Status.CURRENT;
174     }
175
176     /*
177      * (non-Javadoc)
178      *
179      * @see
180      * com.csico.yang.model.base.type.api.StringTypeDefinition#getLengthStatements
181      * ()
182      */
183     @Override
184     public List<LengthConstraint> getLengthStatements() {
185         return lengthStatements;
186     }
187
188     /*
189      * (non-Javadoc)
190      *
191      * @see
192      * com.csico.yang.model.base.type.api.StringTypeDefinition#getPatterns()
193      */
194     @Override
195     public List<PatternConstraint> getPatterns() {
196         return patterns;
197     }
198
199     @Override
200     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
201         return Collections.emptyList();
202     }
203
204     @Override
205     public int hashCode() {
206         final int prime = 31;
207         int result = 1;
208         result = prime * result
209                 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
210         result = prime * result
211                 + ((description == null) ? 0 : description.hashCode());
212         result = prime
213                 * result
214                 + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
215         result = prime * result + ((name == null) ? 0 : name.hashCode());
216         result = prime * result + ((path == null) ? 0 : path.hashCode());
217         result = prime * result
218                 + ((patterns == null) ? 0 : patterns.hashCode());
219         result = prime * result
220                 + ((reference == null) ? 0 : reference.hashCode());
221         result = prime * result + ((units == null) ? 0 : units.hashCode());
222         return result;
223     }
224
225     @Override
226     public boolean equals(Object obj) {
227         if (this == obj) {
228             return true;
229         }
230         if (obj == null) {
231             return false;
232         }
233         if (getClass() != obj.getClass()) {
234             return false;
235         }
236         StringType other = (StringType) obj;
237         if (defaultValue == null) {
238             if (other.defaultValue != null) {
239                 return false;
240             }
241         } else if (!defaultValue.equals(other.defaultValue)) {
242             return false;
243         }
244         if (description == null) {
245             if (other.description != null) {
246                 return false;
247             }
248         } else if (!description.equals(other.description)) {
249             return false;
250         }
251         if (lengthStatements == null) {
252             if (other.lengthStatements != null) {
253                 return false;
254             }
255         } else if (!lengthStatements.equals(other.lengthStatements)) {
256             return false;
257         }
258         if (name == null) {
259             if (other.name != null) {
260                 return false;
261             }
262         } else if (!name.equals(other.name)) {
263             return false;
264         }
265         if (path == null) {
266             if (other.path != null) {
267                 return false;
268             }
269         } else if ((path != null) && (other.path != null)) {
270             if (!path.getPath().equals(other.path.getPath())) {
271                 return false;
272             }
273         }
274         if (patterns == null) {
275             if (other.patterns != null) {
276                 return false;
277             }
278         } else if (!patterns.equals(other.patterns)) {
279             return false;
280         }
281         if (reference == null) {
282             if (other.reference != null) {
283                 return false;
284             }
285         } else if (!reference.equals(other.reference)) {
286             return false;
287         }
288         if (units == null) {
289             if (other.units != null) {
290                 return false;
291             }
292         } else if (!units.equals(other.units)) {
293             return false;
294         }
295         return true;
296     }
297
298     @Override
299     public String toString() {
300         StringBuilder builder = new StringBuilder();
301         builder.append("StringType [name=");
302         builder.append(name);
303         builder.append(", path=");
304         builder.append(path);
305         builder.append(", defaultValue=");
306         builder.append(defaultValue);
307         builder.append(", description=");
308         builder.append(description);
309         builder.append(", reference=");
310         builder.append(reference);
311         builder.append(", lengthStatements=");
312         builder.append(lengthStatements);
313         builder.append(", patterns=");
314         builder.append(patterns);
315         builder.append(", units=");
316         builder.append(units);
317         builder.append("]");
318         return builder.toString();
319     }
320 }