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