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 static final String DEFAULT_VALUE = "";
32 private static final String DESCRIPTION = "";
33 private static final String REFERENCE = "";
34 private final List<LengthConstraint> lengthStatements;
35 private final List<PatternConstraint> patterns;
36 private static 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() {
56 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
59 public StringTypeDefinition getBaseType() {
66 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
69 public String getUnits() {
77 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
81 public Object getDefaultValue() {
88 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
91 public QName getQName() {
98 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
101 public SchemaPath getPath() {
109 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
112 public String getDescription() {
119 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
122 public String getReference() {
129 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
132 public Status getStatus() {
133 return Status.CURRENT;
140 * com.csico.yang.model.base.type.api.StringTypeDefinition#getLengthStatements
144 public List<LengthConstraint> getLengthConstraints() {
145 return lengthStatements;
152 * com.csico.yang.model.base.type.api.StringTypeDefinition#getPatterns()
155 public List<PatternConstraint> getPatternConstraints() {
160 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
161 return Collections.emptyList();
165 public int hashCode() {
166 final int prime = 31;
168 result = prime * result + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
169 result = prime * result + ((name == null) ? 0 : name.hashCode());
170 result = prime * result + ((path == null) ? 0 : path.hashCode());
171 result = prime * result + ((patterns == null) ? 0 : patterns.hashCode());
176 public boolean equals(Object obj) {
183 if (getClass() != obj.getClass()) {
186 StringType other = (StringType) obj;
187 if (lengthStatements == null) {
188 if (other.lengthStatements != null) {
191 } else if (!lengthStatements.equals(other.lengthStatements)) {
195 if (other.name != null) {
198 } else if (!name.equals(other.name)) {
202 if (other.path != null) {
205 } else if (!path.getPath().equals(other.path.getPath())) {
208 if (patterns == null) {
209 if (other.patterns != null) {
212 } else if (!patterns.equals(other.patterns)) {
219 public String toString() {
220 StringBuilder builder = new StringBuilder();
221 builder.append("StringType [name=");
222 builder.append(name);
223 builder.append(", path=");
224 builder.append(path);
225 builder.append(", defaultValue=");
226 builder.append(DEFAULT_VALUE);
227 builder.append(", description=");
228 builder.append(DESCRIPTION);
229 builder.append(", reference=");
230 builder.append(REFERENCE);
231 builder.append(", lengthStatements=");
232 builder.append(lengthStatements);
233 builder.append(", patterns=");
234 builder.append(patterns);
235 builder.append(", units=");
236 builder.append(UNITS);
238 return builder.toString();