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 com.google.common.base.Optional;
11 import java.util.Collections;
12 import java.util.List;
13 import java.util.Objects;
14 import org.opendaylight.yangtools.concepts.Immutable;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import org.opendaylight.yangtools.yang.model.api.Status;
18 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
20 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
21 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
24 * The <code>default</code> implementation of String Type Definition interface.
26 * @see StringTypeDefinition
28 public final class StringType implements StringTypeDefinition, Immutable {
29 private static final QName NAME = BaseTypes.STRING_QNAME;
30 private static final SchemaPath PATH = SchemaPath.create(true, NAME);
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 = "";
38 private static final StringType INSTANCE = new StringType();
41 * Default Constructor.
43 private StringType() {
44 lengthStatements = Collections.singletonList(BaseConstraints.newLengthConstraint(0, Integer.MAX_VALUE, Optional.of(""), Optional.of("")));
45 patterns = Collections.emptyList();
48 public static StringType getInstance() {
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 + Objects.hashCode(lengthStatements);
169 result = prime * result + NAME.hashCode();
170 result = prime * result + PATH.hashCode();
171 result = prime * result + Objects.hashCode(patterns);
176 public boolean equals(final 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)) {
194 if (patterns == null) {
195 if (other.patterns != null) {
198 } else if (!patterns.equals(other.patterns)) {
205 public String toString() {
206 StringBuilder builder = new StringBuilder();
207 builder.append("StringType [name=");
208 builder.append(NAME);
209 builder.append(", path=");
210 builder.append(PATH);
211 builder.append(", defaultValue=");
212 builder.append(DEFAULT_VALUE);
213 builder.append(", description=");
214 builder.append(DESCRIPTION);
215 builder.append(", reference=");
216 builder.append(REFERENCE);
217 builder.append(", lengthStatements=");
218 builder.append(lengthStatements);
219 builder.append(", patterns=");
220 builder.append(patterns);
221 builder.append(", units=");
222 builder.append(UNITS);
224 return builder.toString();