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