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