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;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
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;
23 * The <code>default</code> implementation of String Type Definition interface.
25 * @see StringTypeDefinition
27 public class StringType implements StringTypeDefinition {
29 private final QName name = BaseTypes.constructQName("string");;
30 private final SchemaPath path;
31 private 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 String units = "";
39 * Default Constructor.
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);
48 this.patterns = Collections.emptyList();
54 * @param lengthStatements
57 public StringType(final List<LengthConstraint> lengthStatements,
58 final List<PatternConstraint> patterns) {
60 path = BaseTypes.schemaPath(name);
61 if(lengthStatements == null || lengthStatements.size() == 0) {
62 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
63 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
64 this.lengthStatements = Collections.unmodifiableList(constraints);
66 this.lengthStatements = Collections.unmodifiableList(lengthStatements);
68 this.patterns = Collections.unmodifiableList(patterns);
75 * @param lengthStatements
79 public StringType(final String defaultValue,
80 final List<LengthConstraint> lengthStatements,
81 final List<PatternConstraint> patterns, final String units) {
83 path = BaseTypes.schemaPath(name);
84 this.defaultValue = defaultValue;
85 if(lengthStatements == null || lengthStatements.size() == 0) {
86 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
87 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
88 this.lengthStatements = Collections.unmodifiableList(constraints);
90 this.lengthStatements = Collections.unmodifiableList(lengthStatements);
92 this.patterns = patterns;
99 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
102 public StringTypeDefinition getBaseType() {
109 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
112 public String getUnits() {
119 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
122 public Object getDefaultValue() {
129 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
132 public QName getQName() {
139 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
142 public SchemaPath getPath() {
149 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
152 public String getDescription() {
159 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
162 public String getReference() {
169 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
172 public Status getStatus() {
173 return Status.CURRENT;
180 * com.csico.yang.model.base.type.api.StringTypeDefinition#getLengthStatements
184 public List<LengthConstraint> getLengthStatements() {
185 return lengthStatements;
192 * com.csico.yang.model.base.type.api.StringTypeDefinition#getPatterns()
195 public List<PatternConstraint> getPatterns() {
200 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
201 return Collections.emptyList();
205 public int hashCode() {
206 final int prime = 31;
208 result = prime * result
209 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
210 result = prime * result
211 + ((description == null) ? 0 : description.hashCode());
214 + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
215 result = prime * result + ((name == null) ? 0 : name.hashCode());
216 result = prime * result + ((path == null) ? 0 : path.hashCode());
217 result = prime * result
218 + ((patterns == null) ? 0 : patterns.hashCode());
219 result = prime * result
220 + ((reference == null) ? 0 : reference.hashCode());
221 result = prime * result + ((units == null) ? 0 : units.hashCode());
226 public boolean equals(Object obj) {
233 if (getClass() != obj.getClass()) {
236 StringType other = (StringType) obj;
237 if (defaultValue == null) {
238 if (other.defaultValue != null) {
241 } else if (!defaultValue.equals(other.defaultValue)) {
244 if (description == null) {
245 if (other.description != null) {
248 } else if (!description.equals(other.description)) {
251 if (lengthStatements == null) {
252 if (other.lengthStatements != null) {
255 } else if (!lengthStatements.equals(other.lengthStatements)) {
259 if (other.name != null) {
262 } else if (!name.equals(other.name)) {
266 if (other.path != null) {
269 } else if ((path != null) && (other.path != null)) {
270 if (!path.getPath().equals(other.path.getPath())) {
274 if (patterns == null) {
275 if (other.patterns != null) {
278 } else if (!patterns.equals(other.patterns)) {
281 if (reference == null) {
282 if (other.reference != null) {
285 } else if (!reference.equals(other.reference)) {
289 if (other.units != null) {
292 } else if (!units.equals(other.units)) {
299 public String toString() {
300 StringBuilder builder = new StringBuilder();
301 builder.append("StringType [name=");
302 builder.append(name);
303 builder.append(", path=");
304 builder.append(path);
305 builder.append(", defaultValue=");
306 builder.append(defaultValue);
307 builder.append(", description=");
308 builder.append(description);
309 builder.append(", reference=");
310 builder.append(reference);
311 builder.append(", lengthStatements=");
312 builder.append(lengthStatements);
313 builder.append(", patterns=");
314 builder.append(patterns);
315 builder.append(", units=");
316 builder.append(units);
318 return builder.toString();