2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.controller.model.util;
\r
10 import java.util.ArrayList;
\r
11 import java.util.Collections;
\r
12 import java.util.List;
\r
14 import org.opendaylight.controller.model.api.type.LengthConstraint;
\r
15 import org.opendaylight.controller.model.api.type.PatternConstraint;
\r
16 import org.opendaylight.controller.model.api.type.StringTypeDefinition;
\r
17 import org.opendaylight.controller.yang.common.QName;
\r
18 import org.opendaylight.controller.yang.model.api.SchemaPath;
\r
19 import org.opendaylight.controller.yang.model.api.Status;
\r
20 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
\r
23 * The <code>default</code> implementation of String Type Definition interface.
\r
25 * @see StringTypeDefinition
\r
27 public class StringType implements StringTypeDefinition {
\r
29 private final QName name = BaseTypes.constructQName("string");;
\r
30 private final SchemaPath path;
\r
31 private String defaultValue = "";
\r
32 private final String description = "";
\r
33 private final String reference = "";
\r
34 private final List<LengthConstraint> lengthStatements;
\r
35 private final List<PatternConstraint> patterns;
\r
36 private String units = "";
\r
39 * Default Constructor.
\r
41 public StringType() {
\r
43 path = BaseTypes.schemaPath(name);
\r
44 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
\r
45 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
\r
46 lengthStatements = Collections.unmodifiableList(constraints);
\r
48 this.patterns = Collections.emptyList();
\r
54 * @param lengthStatements
\r
57 public StringType(final List<LengthConstraint> lengthStatements,
\r
58 final List<PatternConstraint> patterns) {
\r
60 path = BaseTypes.schemaPath(name);
\r
61 this.lengthStatements = Collections.unmodifiableList(lengthStatements);
\r
62 this.patterns = Collections.unmodifiableList(patterns);
\r
68 * @param defaultValue
\r
69 * @param lengthStatements
\r
73 public StringType(final String defaultValue,
\r
74 final List<LengthConstraint> lengthStatements,
\r
75 final List<PatternConstraint> patterns, final String units) {
\r
77 path = BaseTypes.schemaPath(name);
\r
78 this.defaultValue = defaultValue;
\r
79 this.lengthStatements = lengthStatements;
\r
80 this.patterns = patterns;
\r
87 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
\r
90 public StringTypeDefinition getBaseType() {
\r
97 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
\r
100 public String getUnits() {
\r
107 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
\r
110 public Object getDefaultValue() {
\r
111 return defaultValue;
\r
117 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
\r
120 public QName getQName() {
\r
127 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
\r
130 public SchemaPath getPath() {
\r
137 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
\r
140 public String getDescription() {
\r
141 return description;
\r
147 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
\r
150 public String getReference() {
\r
157 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
\r
160 public Status getStatus() {
\r
161 return Status.CURRENT;
\r
168 * com.csico.yang.model.base.type.api.StringTypeDefinition#getLengthStatements
\r
172 public List<LengthConstraint> getLengthStatements() {
\r
173 return lengthStatements;
\r
180 * com.csico.yang.model.base.type.api.StringTypeDefinition#getPatterns()
\r
183 public List<PatternConstraint> getPatterns() {
\r
188 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
\r
189 return Collections.emptyList();
\r
193 public int hashCode() {
\r
194 final int prime = 31;
\r
196 result = prime * result
\r
197 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
\r
198 result = prime * result
\r
199 + ((description == null) ? 0 : description.hashCode());
\r
202 + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
\r
203 result = prime * result + ((name == null) ? 0 : name.hashCode());
\r
204 result = prime * result + ((path == null) ? 0 : path.hashCode());
\r
205 result = prime * result
\r
206 + ((patterns == null) ? 0 : patterns.hashCode());
\r
207 result = prime * result
\r
208 + ((reference == null) ? 0 : reference.hashCode());
\r
209 result = prime * result + ((units == null) ? 0 : units.hashCode());
\r
214 public boolean equals(Object obj) {
\r
221 if (getClass() != obj.getClass()) {
\r
224 StringType other = (StringType) obj;
\r
225 if (defaultValue == null) {
\r
226 if (other.defaultValue != null) {
\r
229 } else if (!defaultValue.equals(other.defaultValue)) {
\r
232 if (description == null) {
\r
233 if (other.description != null) {
\r
236 } else if (!description.equals(other.description)) {
\r
239 if (lengthStatements == null) {
\r
240 if (other.lengthStatements != null) {
\r
243 } else if (!lengthStatements.equals(other.lengthStatements)) {
\r
246 if (name == null) {
\r
247 if (other.name != null) {
\r
250 } else if (!name.equals(other.name)) {
\r
253 if (path == null) {
\r
254 if (other.path != null) {
\r
257 } else if ((path != null) && (other.path != null)) {
\r
258 if (!path.getPath().equals(other.path.getPath())) {
\r
262 if (patterns == null) {
\r
263 if (other.patterns != null) {
\r
266 } else if (!patterns.equals(other.patterns)) {
\r
269 if (reference == null) {
\r
270 if (other.reference != null) {
\r
273 } else if (!reference.equals(other.reference)) {
\r
276 if (units == null) {
\r
277 if (other.units != null) {
\r
280 } else if (!units.equals(other.units)) {
\r
287 public String toString() {
\r
288 StringBuilder builder = new StringBuilder();
\r
289 builder.append("StringType [name=");
\r
290 builder.append(name);
\r
291 builder.append(", path=");
\r
292 builder.append(path);
\r
293 builder.append(", defaultValue=");
\r
294 builder.append(defaultValue);
\r
295 builder.append(", description=");
\r
296 builder.append(description);
\r
297 builder.append(", reference=");
\r
298 builder.append(reference);
\r
299 builder.append(", lengthStatements=");
\r
300 builder.append(lengthStatements);
\r
301 builder.append(", patterns=");
\r
302 builder.append(patterns);
\r
303 builder.append(", units=");
\r
304 builder.append(units);
\r
305 builder.append("]");
\r
306 return builder.toString();
\r