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.controller.yang.model.util;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
14 import org.opendaylight.controller.yang.common.QName;
15 import org.opendaylight.controller.yang.model.api.SchemaPath;
16 import org.opendaylight.controller.yang.model.api.Status;
17 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
19 import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
20 import org.opendaylight.controller.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 {
29 private final QName name = BaseTypes.constructQName("string");
30 private final SchemaPath path;
31 private 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 String units = "";
37 private final StringTypeDefinition baseType;
39 private StringType() {
41 path = BaseTypes.schemaPath(name);
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();
50 * Default Constructor.
52 public StringType(final SchemaPath path) {
55 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
56 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
57 lengthStatements = Collections.unmodifiableList(constraints);
58 patterns = Collections.emptyList();
59 baseType = new StringType();
67 * @param lengthStatements
70 public StringType(final SchemaPath path, final List<LengthConstraint> lengthStatements,
71 final List<PatternConstraint> patterns) {
74 if(lengthStatements == null || lengthStatements.size() == 0) {
75 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
76 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
77 this.lengthStatements = Collections.unmodifiableList(constraints);
79 this.lengthStatements = Collections.unmodifiableList(lengthStatements);
81 this.patterns = Collections.unmodifiableList(patterns);
82 baseType = new StringType();
89 * @param lengthStatements
93 public StringType(final SchemaPath path, final String defaultValue,
94 final List<LengthConstraint> lengthStatements,
95 final List<PatternConstraint> patterns, final String units) {
98 this.defaultValue = defaultValue;
99 if(lengthStatements == null || lengthStatements.size() == 0) {
100 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
101 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
102 this.lengthStatements = Collections.unmodifiableList(constraints);
104 this.lengthStatements = Collections.unmodifiableList(lengthStatements);
106 this.patterns = Collections.unmodifiableList(patterns);
108 this.baseType = new StringType();
114 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
117 public StringTypeDefinition getBaseType() {
124 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
127 public String getUnits() {
134 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
137 public Object getDefaultValue() {
144 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
147 public QName getQName() {
154 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
157 public SchemaPath getPath() {
164 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
167 public String getDescription() {
174 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
177 public String getReference() {
184 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
187 public Status getStatus() {
188 return Status.CURRENT;
195 * com.csico.yang.model.base.type.api.StringTypeDefinition#getLengthStatements
199 public List<LengthConstraint> getLengthStatements() {
200 return lengthStatements;
207 * com.csico.yang.model.base.type.api.StringTypeDefinition#getPatterns()
210 public List<PatternConstraint> getPatterns() {
215 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
216 return Collections.emptyList();
220 public int hashCode() {
221 final int prime = 31;
223 result = prime * result
224 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
225 result = prime * result
226 + ((description == null) ? 0 : description.hashCode());
229 + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
230 result = prime * result + ((name == null) ? 0 : name.hashCode());
231 result = prime * result + ((path == null) ? 0 : path.hashCode());
232 result = prime * result
233 + ((patterns == null) ? 0 : patterns.hashCode());
234 result = prime * result
235 + ((reference == null) ? 0 : reference.hashCode());
236 result = prime * result + ((units == null) ? 0 : units.hashCode());
241 public boolean equals(Object obj) {
248 if (getClass() != obj.getClass()) {
251 StringType other = (StringType) obj;
252 if (defaultValue == null) {
253 if (other.defaultValue != null) {
256 } else if (!defaultValue.equals(other.defaultValue)) {
259 if (description == null) {
260 if (other.description != null) {
263 } else if (!description.equals(other.description)) {
266 if (lengthStatements == null) {
267 if (other.lengthStatements != null) {
270 } else if (!lengthStatements.equals(other.lengthStatements)) {
274 if (other.name != null) {
277 } else if (!name.equals(other.name)) {
281 if (other.path != null) {
284 } else if ((path != null) && (other.path != null)) {
285 if (!path.getPath().equals(other.path.getPath())) {
289 if (patterns == null) {
290 if (other.patterns != null) {
293 } else if (!patterns.equals(other.patterns)) {
296 if (reference == null) {
297 if (other.reference != null) {
300 } else if (!reference.equals(other.reference)) {
304 if (other.units != null) {
307 } else if (!units.equals(other.units)) {
314 public String toString() {
315 StringBuilder builder = new StringBuilder();
316 builder.append("StringType [name=");
317 builder.append(name);
318 builder.append(", path=");
319 builder.append(path);
320 builder.append(", defaultValue=");
321 builder.append(defaultValue);
322 builder.append(", description=");
323 builder.append(description);
324 builder.append(", reference=");
325 builder.append(reference);
326 builder.append(", lengthStatements=");
327 builder.append(lengthStatements);
328 builder.append(", patterns=");
329 builder.append(patterns);
330 builder.append(", units=");
331 builder.append(units);
333 return builder.toString();