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 this.lengthStatements = Collections.unmodifiableList(lengthStatements);
62 this.patterns = Collections.unmodifiableList(patterns);
69 * @param lengthStatements
73 public StringType(final String defaultValue,
74 final List<LengthConstraint> lengthStatements,
75 final List<PatternConstraint> patterns, final String units) {
77 path = BaseTypes.schemaPath(name);
78 this.defaultValue = defaultValue;
79 this.lengthStatements = lengthStatements;
80 this.patterns = patterns;
87 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
90 public StringTypeDefinition getBaseType() {
97 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
100 public String getUnits() {
107 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
110 public Object getDefaultValue() {
117 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
120 public QName getQName() {
127 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
130 public SchemaPath getPath() {
137 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
140 public String getDescription() {
147 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
150 public String getReference() {
157 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
160 public Status getStatus() {
161 return Status.CURRENT;
168 * com.csico.yang.model.base.type.api.StringTypeDefinition#getLengthStatements
172 public List<LengthConstraint> getLengthStatements() {
173 return lengthStatements;
180 * com.csico.yang.model.base.type.api.StringTypeDefinition#getPatterns()
183 public List<PatternConstraint> getPatterns() {
188 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
189 return Collections.emptyList();
193 public int hashCode() {
194 final int prime = 31;
196 result = prime * result
197 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
198 result = prime * result
199 + ((description == null) ? 0 : description.hashCode());
202 + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
203 result = prime * result + ((name == null) ? 0 : name.hashCode());
204 result = prime * result + ((path == null) ? 0 : path.hashCode());
205 result = prime * result
206 + ((patterns == null) ? 0 : patterns.hashCode());
207 result = prime * result
208 + ((reference == null) ? 0 : reference.hashCode());
209 result = prime * result + ((units == null) ? 0 : units.hashCode());
214 public boolean equals(Object obj) {
221 if (getClass() != obj.getClass()) {
224 StringType other = (StringType) obj;
225 if (defaultValue == null) {
226 if (other.defaultValue != null) {
229 } else if (!defaultValue.equals(other.defaultValue)) {
232 if (description == null) {
233 if (other.description != null) {
236 } else if (!description.equals(other.description)) {
239 if (lengthStatements == null) {
240 if (other.lengthStatements != null) {
243 } else if (!lengthStatements.equals(other.lengthStatements)) {
247 if (other.name != null) {
250 } else if (!name.equals(other.name)) {
254 if (other.path != null) {
257 } else if ((path != null) && (other.path != null)) {
258 if (!path.getPath().equals(other.path.getPath())) {
262 if (patterns == null) {
263 if (other.patterns != null) {
266 } else if (!patterns.equals(other.patterns)) {
269 if (reference == null) {
270 if (other.reference != null) {
273 } else if (!reference.equals(other.reference)) {
277 if (other.units != null) {
280 } else if (!units.equals(other.units)) {
287 public String toString() {
288 StringBuilder builder = new StringBuilder();
289 builder.append("StringType [name=");
290 builder.append(name);
291 builder.append(", path=");
292 builder.append(path);
293 builder.append(", defaultValue=");
294 builder.append(defaultValue);
295 builder.append(", description=");
296 builder.append(description);
297 builder.append(", reference=");
298 builder.append(reference);
299 builder.append(", lengthStatements=");
300 builder.append(lengthStatements);
301 builder.append(", patterns=");
302 builder.append(patterns);
303 builder.append(", units=");
304 builder.append(units);
306 return builder.toString();