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 static final StringType INSTANCE = new StringType();
29 private final QName name = BaseTypes.constructQName("string");
30 private final SchemaPath path = new SchemaPath(Collections.singletonList(name), true);
31 private final 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 final String units = "";
39 * Default Constructor.
41 private StringType() {
42 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
43 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
44 lengthStatements = Collections.unmodifiableList(constraints);
45 patterns = Collections.emptyList();
48 public static StringType getIntance() {
55 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
58 public StringTypeDefinition getBaseType() {
65 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
68 public String getUnits() {
75 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue()
78 public Object getDefaultValue() {
85 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
88 public QName getQName() {
95 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
98 public SchemaPath getPath() {
105 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
108 public String getDescription() {
115 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
118 public String getReference() {
125 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
128 public Status getStatus() {
129 return Status.CURRENT;
136 * com.csico.yang.model.base.type.api.StringTypeDefinition#getLengthStatements
140 public List<LengthConstraint> getLengthStatements() {
141 return lengthStatements;
148 * com.csico.yang.model.base.type.api.StringTypeDefinition#getPatterns()
151 public List<PatternConstraint> getPatterns() {
156 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
157 return Collections.emptyList();
161 public int hashCode() {
162 final int prime = 31;
164 result = prime * result
165 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
166 result = prime * result
167 + ((description == null) ? 0 : description.hashCode());
170 + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
171 result = prime * result + ((name == null) ? 0 : name.hashCode());
172 result = prime * result + ((path == null) ? 0 : path.hashCode());
173 result = prime * result
174 + ((patterns == null) ? 0 : patterns.hashCode());
175 result = prime * result
176 + ((reference == null) ? 0 : reference.hashCode());
177 result = prime * result + ((units == null) ? 0 : units.hashCode());
182 public boolean equals(Object obj) {
189 if (getClass() != obj.getClass()) {
192 StringType other = (StringType) obj;
193 if (defaultValue == null) {
194 if (other.defaultValue != null) {
197 } else if (!defaultValue.equals(other.defaultValue)) {
200 if (description == null) {
201 if (other.description != null) {
204 } else if (!description.equals(other.description)) {
207 if (lengthStatements == null) {
208 if (other.lengthStatements != null) {
211 } else if (!lengthStatements.equals(other.lengthStatements)) {
215 if (other.name != null) {
218 } else if (!name.equals(other.name)) {
222 if (other.path != null) {
225 } else if ((path != null) && (other.path != null)) {
226 if (!path.getPath().equals(other.path.getPath())) {
230 if (patterns == null) {
231 if (other.patterns != null) {
234 } else if (!patterns.equals(other.patterns)) {
237 if (reference == null) {
238 if (other.reference != null) {
241 } else if (!reference.equals(other.reference)) {
245 if (other.units != null) {
248 } else if (!units.equals(other.units)) {
255 public String toString() {
256 StringBuilder builder = new StringBuilder();
257 builder.append("StringType [name=");
258 builder.append(name);
259 builder.append(", path=");
260 builder.append(path);
261 builder.append(", defaultValue=");
262 builder.append(defaultValue);
263 builder.append(", description=");
264 builder.append(description);
265 builder.append(", reference=");
266 builder.append(reference);
267 builder.append(", lengthStatements=");
268 builder.append(lengthStatements);
269 builder.append(", patterns=");
270 builder.append(patterns);
271 builder.append(", units=");
272 builder.append(units);
274 return builder.toString();