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