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 = "";
39 private final StringTypeDefinition baseType;
41 private StringType() {
43 path = BaseTypes.schemaPath(name);
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();
52 * Default Constructor.
54 public StringType(final List<String> actualPath,
55 final URI namespace, final Date revision) {
57 path = BaseTypes.schemaPath(actualPath, namespace, revision);
58 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
59 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
60 lengthStatements = Collections.unmodifiableList(constraints);
61 patterns = Collections.emptyList();
62 baseType = new StringType();
70 * @param lengthStatements
73 public StringType(final List<String> actualPath,
74 final URI namespace, final Date revision, final List<LengthConstraint> lengthStatements,
75 final List<PatternConstraint> patterns) {
77 path = BaseTypes.schemaPath(actualPath, namespace, revision);
78 if(lengthStatements == null || lengthStatements.size() == 0) {
79 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
80 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
81 this.lengthStatements = Collections.unmodifiableList(constraints);
83 this.lengthStatements = Collections.unmodifiableList(lengthStatements);
85 this.patterns = Collections.unmodifiableList(patterns);
86 baseType = new StringType();
93 * @param lengthStatements
97 public StringType(final List<String> actualPath,
98 final URI namespace, final Date revision, final String defaultValue,
99 final List<LengthConstraint> lengthStatements,
100 final List<PatternConstraint> patterns, final String units) {
102 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
103 this.defaultValue = defaultValue;
104 if(lengthStatements == null || lengthStatements.size() == 0) {
105 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
106 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
107 this.lengthStatements = Collections.unmodifiableList(constraints);
109 this.lengthStatements = Collections.unmodifiableList(lengthStatements);
111 this.patterns = Collections.unmodifiableList(patterns);
113 this.baseType = new StringType();
119 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
122 public StringTypeDefinition getBaseType() {
129 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
132 public String getUnits() {
139 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
142 public Object getDefaultValue() {
149 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
152 public QName getQName() {
159 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
162 public SchemaPath getPath() {
169 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
172 public String getDescription() {
179 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
182 public String getReference() {
189 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
192 public Status getStatus() {
193 return Status.CURRENT;
200 * com.csico.yang.model.base.type.api.StringTypeDefinition#getLengthStatements
204 public List<LengthConstraint> getLengthStatements() {
205 return lengthStatements;
212 * com.csico.yang.model.base.type.api.StringTypeDefinition#getPatterns()
215 public List<PatternConstraint> getPatterns() {
220 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
221 return Collections.emptyList();
225 public int hashCode() {
226 final int prime = 31;
228 result = prime * result
229 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
230 result = prime * result
231 + ((description == null) ? 0 : description.hashCode());
234 + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
235 result = prime * result + ((name == null) ? 0 : name.hashCode());
236 result = prime * result + ((path == null) ? 0 : path.hashCode());
237 result = prime * result
238 + ((patterns == null) ? 0 : patterns.hashCode());
239 result = prime * result
240 + ((reference == null) ? 0 : reference.hashCode());
241 result = prime * result + ((units == null) ? 0 : units.hashCode());
246 public boolean equals(Object obj) {
253 if (getClass() != obj.getClass()) {
256 StringType other = (StringType) obj;
257 if (defaultValue == null) {
258 if (other.defaultValue != null) {
261 } else if (!defaultValue.equals(other.defaultValue)) {
264 if (description == null) {
265 if (other.description != null) {
268 } else if (!description.equals(other.description)) {
271 if (lengthStatements == null) {
272 if (other.lengthStatements != null) {
275 } else if (!lengthStatements.equals(other.lengthStatements)) {
279 if (other.name != null) {
282 } else if (!name.equals(other.name)) {
286 if (other.path != null) {
289 } else if ((path != null) && (other.path != null)) {
290 if (!path.getPath().equals(other.path.getPath())) {
294 if (patterns == null) {
295 if (other.patterns != null) {
298 } else if (!patterns.equals(other.patterns)) {
301 if (reference == null) {
302 if (other.reference != null) {
305 } else if (!reference.equals(other.reference)) {
309 if (other.units != null) {
312 } else if (!units.equals(other.units)) {
319 public String toString() {
320 StringBuilder builder = new StringBuilder();
321 builder.append("StringType [name=");
322 builder.append(name);
323 builder.append(", path=");
324 builder.append(path);
325 builder.append(", defaultValue=");
326 builder.append(defaultValue);
327 builder.append(", description=");
328 builder.append(description);
329 builder.append(", reference=");
330 builder.append(reference);
331 builder.append(", lengthStatements=");
332 builder.append(lengthStatements);
333 builder.append(", patterns=");
334 builder.append(patterns);
335 builder.append(", units=");
336 builder.append(units);
338 return builder.toString();