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