2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.yang.model.util;
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.Date;
14 import java.util.List;
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;
25 * The <code>default</code> implementation of String Type Definition interface.
27 * @see StringTypeDefinition
29 public class StringType implements StringTypeDefinition {
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 = "";
41 * Default Constructor.
43 public StringType(final List<String> actualPath,
44 final URI namespace, final Date revision) {
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);
51 this.patterns = Collections.emptyList();
57 * @param lengthStatements
60 public StringType(final List<String> actualPath,
61 final URI namespace, final Date revision, final List<LengthConstraint> lengthStatements,
62 final List<PatternConstraint> patterns) {
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);
70 this.lengthStatements = Collections.unmodifiableList(lengthStatements);
72 this.patterns = Collections.unmodifiableList(patterns);
79 * @param lengthStatements
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) {
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);
95 this.lengthStatements = Collections.unmodifiableList(lengthStatements);
97 this.patterns = patterns;
104 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
107 public StringTypeDefinition getBaseType() {
114 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
117 public String getUnits() {
124 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
127 public Object getDefaultValue() {
134 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
137 public QName getQName() {
144 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
147 public SchemaPath getPath() {
154 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
157 public String getDescription() {
164 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
167 public String getReference() {
174 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
177 public Status getStatus() {
178 return Status.CURRENT;
185 * com.csico.yang.model.base.type.api.StringTypeDefinition#getLengthStatements
189 public List<LengthConstraint> getLengthStatements() {
190 return lengthStatements;
197 * com.csico.yang.model.base.type.api.StringTypeDefinition#getPatterns()
200 public List<PatternConstraint> getPatterns() {
205 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
206 return Collections.emptyList();
210 public int hashCode() {
211 final int prime = 31;
213 result = prime * result
214 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
215 result = prime * result
216 + ((description == null) ? 0 : description.hashCode());
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());
231 public boolean equals(Object obj) {
238 if (getClass() != obj.getClass()) {
241 StringType other = (StringType) obj;
242 if (defaultValue == null) {
243 if (other.defaultValue != null) {
246 } else if (!defaultValue.equals(other.defaultValue)) {
249 if (description == null) {
250 if (other.description != null) {
253 } else if (!description.equals(other.description)) {
256 if (lengthStatements == null) {
257 if (other.lengthStatements != null) {
260 } else if (!lengthStatements.equals(other.lengthStatements)) {
264 if (other.name != null) {
267 } else if (!name.equals(other.name)) {
271 if (other.path != null) {
274 } else if ((path != null) && (other.path != null)) {
275 if (!path.getPath().equals(other.path.getPath())) {
279 if (patterns == null) {
280 if (other.patterns != null) {
283 } else if (!patterns.equals(other.patterns)) {
286 if (reference == null) {
287 if (other.reference != null) {
290 } else if (!reference.equals(other.reference)) {
294 if (other.units != null) {
297 } else if (!units.equals(other.units)) {
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);
323 return builder.toString();