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