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.Collections;
11 import java.util.List;
13 import org.opendaylight.yangtools.concepts.Immutable;
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;
22 import com.google.common.base.Optional;
25 * The <code>default</code> implementation of String Type Definition interface.
27 * @see StringTypeDefinition
29 public final class StringType implements StringTypeDefinition, Immutable {
30 private static final QName NAME = BaseTypes.STRING_QNAME;
31 private static final SchemaPath PATH = SchemaPath.create(Collections.singletonList(NAME), true);
32 private static final String DEFAULT_VALUE = "";
33 private static final String DESCRIPTION = "";
34 private static final String REFERENCE = "";
35 private final List<LengthConstraint> lengthStatements;
36 private final List<PatternConstraint> patterns;
37 private static final String UNITS = "";
39 private static final StringType INSTANCE = new StringType();
42 * Default Constructor.
44 private StringType() {
45 lengthStatements = Collections.singletonList(BaseConstraints.newLengthConstraint(0, Integer.MAX_VALUE, Optional.of(""), Optional.of("")));
46 patterns = Collections.emptyList();
49 public static StringType getInstance() {
57 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
60 public StringTypeDefinition getBaseType() {
67 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
70 public String getUnits() {
78 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
82 public Object getDefaultValue() {
89 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
92 public QName getQName() {
99 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
102 public SchemaPath getPath() {
110 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
113 public String getDescription() {
120 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
123 public String getReference() {
130 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
133 public Status getStatus() {
134 return Status.CURRENT;
141 * com.csico.yang.model.base.type.api.StringTypeDefinition#getLengthStatements
145 public List<LengthConstraint> getLengthConstraints() {
146 return lengthStatements;
153 * com.csico.yang.model.base.type.api.StringTypeDefinition#getPatterns()
156 public List<PatternConstraint> getPatternConstraints() {
161 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
162 return Collections.emptyList();
166 public int hashCode() {
167 final int prime = 31;
169 result = prime * result + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
170 result = prime * result + NAME.hashCode();
171 result = prime * result + PATH.hashCode();
172 result = prime * result + ((patterns == null) ? 0 : patterns.hashCode());
177 public boolean equals(final Object obj) {
184 if (getClass() != obj.getClass()) {
187 StringType other = (StringType) obj;
188 if (lengthStatements == null) {
189 if (other.lengthStatements != null) {
192 } else if (!lengthStatements.equals(other.lengthStatements)) {
195 if (patterns == null) {
196 if (other.patterns != null) {
199 } else if (!patterns.equals(other.patterns)) {
206 public String toString() {
207 StringBuilder builder = new StringBuilder();
208 builder.append("StringType [name=");
209 builder.append(NAME);
210 builder.append(", path=");
211 builder.append(PATH);
212 builder.append(", defaultValue=");
213 builder.append(DEFAULT_VALUE);
214 builder.append(", description=");
215 builder.append(DESCRIPTION);
216 builder.append(", reference=");
217 builder.append(REFERENCE);
218 builder.append(", lengthStatements=");
219 builder.append(lengthStatements);
220 builder.append(", patterns=");
221 builder.append(patterns);
222 builder.append(", units=");
223 builder.append(UNITS);
225 return builder.toString();