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