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.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
15 import org.opendaylight.yangtools.yang.model.api.Status;
16 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
18 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
19 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
20 import org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition;
23 * Utility implementation of unknown type definition.
25 * Unknown type definition is derived type, for
26 * which base built-in type is not yet known. This types
27 * are possible during parsing and resolving of YANG model
28 * without all requisites already processed.
30 public final class UnknownType implements UnknownTypeDefinition {
32 private final QName name;
33 private final SchemaPath path;
34 private final String description;
35 private final String reference;
36 private final List<LengthConstraint> lengthStatements;
37 private final List<PatternConstraint> patterns;
38 private final List<RangeConstraint> rangeStatements;
39 private final List<UnknownSchemaNode> extensions;
40 private final LengthConstraint lengthConstraint;
41 private final Integer fractionDigits;
43 private final Status status;
44 private final String units;
45 private final Object defaultValue;
47 public static class Builder {
49 private final QName name;
50 private final SchemaPath path;
51 private String description;
52 private String reference;
54 private List<LengthConstraint> lengthStatements = Collections.emptyList();
55 private List<PatternConstraint> patterns = Collections.emptyList();
56 private List<RangeConstraint> rangeStatements = Collections.emptyList();
57 private List<UnknownSchemaNode> extensions = Collections.emptyList();
58 private LengthConstraint lengthConstraint = null;
59 private Integer fractionDigits = null;
61 private Status status = Status.CURRENT;
62 private String units = "";
63 private Object defaultValue = null;
65 public Builder(final QName name, final String description, final String reference) {
67 this.path = SchemaPath.create(true, name);
68 this.description = description;
69 this.reference = reference;
72 public Builder(final QName name) {
74 this.path = SchemaPath.create(true, name);
77 public Builder description(final String description) {
78 this.description = description;
82 public Builder reference(final String reference) {
83 this.reference = reference;
87 public Builder lengthStatements(final List<LengthConstraint> lengthStatements) {
88 this.lengthStatements = lengthStatements;
92 public Builder patterns(final List<PatternConstraint> patterns) {
93 this.patterns = patterns;
97 public Builder rangeStatements(final List<RangeConstraint> rangeStatements) {
98 this.rangeStatements = rangeStatements;
102 public Builder extensions(final List<UnknownSchemaNode> extensions) {
103 this.extensions = extensions;
107 public Builder lengthConstraint(final LengthConstraint lengthConstraint) {
108 this.lengthConstraint = lengthConstraint;
112 public Builder fractionDigits(final Integer fractionDigits) {
113 this.fractionDigits = fractionDigits;
117 public Builder status(final Status status) {
118 this.status = status;
122 public Builder units(final String units) {
127 public Builder defaultValue(final Object defaultValue) {
128 this.defaultValue = defaultValue;
132 public UnknownTypeDefinition build() {
133 return new UnknownType(this);
137 private UnknownType(final Builder builder) {
138 this.name = builder.name;
139 this.path = builder.path;
140 this.description = builder.description;
141 this.reference = builder.reference;
142 this.lengthStatements = builder.lengthStatements;
143 this.patterns = builder.patterns;
144 this.rangeStatements = builder.rangeStatements;
145 this.extensions = builder.extensions;
146 this.lengthConstraint = builder.lengthConstraint;
147 this.status = builder.status;
148 this.units = builder.units;
149 this.defaultValue = builder.defaultValue;
150 this.fractionDigits = builder.fractionDigits;
157 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
160 public UnknownTypeDefinition getBaseType() {
167 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
170 public String getUnits() {
178 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
182 public Object getDefaultValue() {
189 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
192 public QName getQName() {
199 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
202 public SchemaPath getPath() {
210 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
213 public String getDescription() {
220 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
223 public String getReference() {
230 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
233 public Status getStatus() {
241 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getExtensionSchemaNodes
245 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
252 * @see org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition
253 * #getRangeStatements()
256 public List<RangeConstraint> getRangeConstraints() {
257 return rangeStatements;
263 * @see org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition
264 * #getLengthStatements()
267 public List<LengthConstraint> getLengthConstraints() {
268 return lengthStatements;
274 * @see org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition
278 public List<PatternConstraint> getPatternConstraints() {
283 public Integer getFractionDigits() {
284 return fractionDigits;
288 public int hashCode() {
289 final int prime = 31;
291 result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
292 result = prime * result + ((description == null) ? 0 : description.hashCode());
293 result = prime * result + ((extensions == null) ? 0 : extensions.hashCode());
294 result = prime * result + ((lengthConstraint == null) ? 0 : lengthConstraint.hashCode());
295 result = prime * result + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
296 result = prime * result + ((name == null) ? 0 : name.hashCode());
297 result = prime * result + ((path == null) ? 0 : path.hashCode());
298 result = prime * result + ((patterns == null) ? 0 : patterns.hashCode());
299 result = prime * result + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
300 result = prime * result + ((reference == null) ? 0 : reference.hashCode());
301 result = prime * result + ((status == null) ? 0 : status.hashCode());
302 result = prime * result + ((units == null) ? 0 : units.hashCode());
307 public boolean equals(final Object obj) {
314 if (getClass() != obj.getClass()) {
317 UnknownType other = (UnknownType) obj;
318 if (defaultValue == null) {
319 if (other.defaultValue != null) {
322 } else if (!defaultValue.equals(other.defaultValue)) {
325 if (description == null) {
326 if (other.description != null) {
329 } else if (!description.equals(other.description)) {
332 if (extensions == null) {
333 if (other.extensions != null) {
336 } else if (!extensions.equals(other.extensions)) {
339 if (lengthConstraint == null) {
340 if (other.lengthConstraint != null) {
343 } else if (!lengthConstraint.equals(other.lengthConstraint)) {
346 if (lengthStatements == null) {
347 if (other.lengthStatements != null) {
350 } else if (!lengthStatements.equals(other.lengthStatements)) {
354 if (other.name != null) {
357 } else if (!name.equals(other.name)) {
361 if (other.path != null) {
364 } else if (!path.equals(other.path)) {
367 if (patterns == null) {
368 if (other.patterns != null) {
371 } else if (!patterns.equals(other.patterns)) {
374 if (rangeStatements == null) {
375 if (other.rangeStatements != null) {
378 } else if (!rangeStatements.equals(other.rangeStatements)) {
381 if (reference == null) {
382 if (other.reference != null) {
385 } else if (!reference.equals(other.reference)) {
388 if (status != other.status) {
392 if (other.units != null) {
395 } else if (!units.equals(other.units)) {
402 public String toString() {
403 StringBuilder builder2 = new StringBuilder();
404 builder2.append("UnknownType [name=");
405 builder2.append(name);
406 builder2.append(", path=");
407 builder2.append(path);
408 builder2.append(", description=");
409 builder2.append(description);
410 builder2.append(", reference=");
411 builder2.append(reference);
412 builder2.append(", lengthStatements=");
413 builder2.append(lengthStatements);
414 builder2.append(", patterns=");
415 builder2.append(patterns);
416 builder2.append(", rangeStatements=");
417 builder2.append(rangeStatements);
418 builder2.append(", extensions=");
419 builder2.append(extensions);
420 builder2.append(", lengthConstraint=");
421 builder2.append(lengthConstraint);
422 builder2.append(", status=");
423 builder2.append(status);
424 builder2.append(", units=");
425 builder2.append(units);
426 builder2.append(", defaultValue=");
427 builder2.append(defaultValue);
428 builder2.append("]");
429 return builder2.toString();