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.yangtools.yang.model.util;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
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;
23 * The <code>default</code> implementation of String Type Definition interface.
25 * @see StringTypeDefinition
27 public final class StringType implements StringTypeDefinition {
28 private final QName name = BaseTypes.constructQName("string");
29 private final SchemaPath path;
30 private final String defaultValue = "";
31 private final String description = "";
32 private final String reference = "";
33 private final List<LengthConstraint> lengthStatements;
34 private final List<PatternConstraint> patterns;
35 private final String units = "";
36 private final StringTypeDefinition baseType;
39 * Default Constructor.
41 public StringType(final SchemaPath path) {
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();
54 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
57 public StringTypeDefinition getBaseType() {
64 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
67 public String getUnits() {
74 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue()
77 public Object getDefaultValue() {
84 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
87 public QName getQName() {
94 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
97 public SchemaPath getPath() {
104 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
107 public String getDescription() {
114 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
117 public String getReference() {
124 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
127 public Status getStatus() {
128 return Status.CURRENT;
135 * com.csico.yang.model.base.type.api.StringTypeDefinition#getLengthStatements
139 public List<LengthConstraint> getLengthStatements() {
140 return lengthStatements;
147 * com.csico.yang.model.base.type.api.StringTypeDefinition#getPatterns()
150 public List<PatternConstraint> getPatterns() {
155 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
156 return Collections.emptyList();
160 public int hashCode() {
161 final int prime = 31;
163 result = prime * result
164 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
165 result = prime * result
166 + ((description == null) ? 0 : description.hashCode());
169 + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
170 result = prime * result + ((name == null) ? 0 : name.hashCode());
171 result = prime * result + ((path == null) ? 0 : path.hashCode());
172 result = prime * result
173 + ((patterns == null) ? 0 : patterns.hashCode());
174 result = prime * result
175 + ((reference == null) ? 0 : reference.hashCode());
176 result = prime * result + ((units == null) ? 0 : units.hashCode());
181 public boolean equals(Object obj) {
188 if (getClass() != obj.getClass()) {
191 StringType other = (StringType) obj;
192 if (defaultValue == null) {
193 if (other.defaultValue != null) {
196 } else if (!defaultValue.equals(other.defaultValue)) {
199 if (description == null) {
200 if (other.description != null) {
203 } else if (!description.equals(other.description)) {
206 if (lengthStatements == null) {
207 if (other.lengthStatements != null) {
210 } else if (!lengthStatements.equals(other.lengthStatements)) {
214 if (other.name != null) {
217 } else if (!name.equals(other.name)) {
221 if (other.path != null) {
224 } else if ((path != null) && (other.path != null)) {
225 if (!path.getPath().equals(other.path.getPath())) {
229 if (patterns == null) {
230 if (other.patterns != null) {
233 } else if (!patterns.equals(other.patterns)) {
236 if (reference == null) {
237 if (other.reference != null) {
240 } else if (!reference.equals(other.reference)) {
244 if (other.units != null) {
247 } else if (!units.equals(other.units)) {
254 public String toString() {
255 StringBuilder builder = new StringBuilder();
256 builder.append("StringType [name=");
257 builder.append(name);
258 builder.append(", path=");
259 builder.append(path);
260 builder.append(", defaultValue=");
261 builder.append(defaultValue);
262 builder.append(", description=");
263 builder.append(description);
264 builder.append(", reference=");
265 builder.append(reference);
266 builder.append(", lengthStatements=");
267 builder.append(lengthStatements);
268 builder.append(", patterns=");
269 builder.append(patterns);
270 builder.append(", units=");
271 builder.append(units);
273 return builder.toString();