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