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 allready processed.
32 public final class UnknownType implements UnknownTypeDefinition {
34 private final QName name;
35 private final SchemaPath path;
36 private final String description;
37 private final String reference;
38 private final List<LengthConstraint> lengthStatements;
39 private final List<PatternConstraint> patterns;
40 private final List<RangeConstraint> rangeStatements;
41 private final List<UnknownSchemaNode> extensions;
42 private final LengthConstraint lengthConstraint;
43 private final Integer fractionDigits;
45 private final Status status;
46 private final String units;
47 private final Object defaultValue;
49 public static class Builder {
51 private final QName name;
52 private final SchemaPath path;
53 private String description;
54 private String reference;
56 private List<LengthConstraint> lengthStatements = Collections.emptyList();
57 private List<PatternConstraint> patterns = Collections.emptyList();
58 private List<RangeConstraint> rangeStatements = Collections.emptyList();
59 private List<UnknownSchemaNode> extensions = Collections.emptyList();
60 private LengthConstraint lengthConstraint = null;
61 private Integer fractionDigits = null;
63 private Status status = Status.CURRENT;
64 private String units = "";
65 private Object defaultValue = null;
67 public Builder(final QName name, final String description, final String reference) {
69 this.path = BaseTypes.schemaPath(name);
70 this.description = description;
71 this.reference = reference;
74 public Builder(final QName name) {
76 this.path = BaseTypes.schemaPath(name);
79 public Builder description(final String description) {
80 this.description = description;
84 public Builder reference(final String reference) {
85 this.reference = reference;
89 public Builder lengthStatements(final List<LengthConstraint> lengthStatements) {
90 this.lengthStatements = lengthStatements;
94 public Builder patterns(final List<PatternConstraint> patterns) {
95 this.patterns = patterns;
99 public Builder rangeStatements(final List<RangeConstraint> rangeStatements) {
100 this.rangeStatements = rangeStatements;
104 public Builder extensions(final List<UnknownSchemaNode> extensions) {
105 this.extensions = extensions;
109 public Builder lengthConstraint(final LengthConstraint lengthConstraint) {
110 this.lengthConstraint = lengthConstraint;
114 public Builder fractionDigits(final Integer fractionDigits) {
115 this.fractionDigits = fractionDigits;
119 public Builder status(final Status status) {
120 this.status = status;
124 public Builder units(final String units) {
129 public Builder defaultValue(final Object defaultValue) {
130 this.defaultValue = defaultValue;
134 public UnknownTypeDefinition build() {
135 return new UnknownType(this);
139 private UnknownType(final Builder builder) {
140 this.name = builder.name;
141 this.path = builder.path;
142 this.description = builder.description;
143 this.reference = builder.reference;
144 this.lengthStatements = builder.lengthStatements;
145 this.patterns = builder.patterns;
146 this.rangeStatements = builder.rangeStatements;
147 this.extensions = builder.extensions;
148 this.lengthConstraint = builder.lengthConstraint;
149 this.status = builder.status;
150 this.units = builder.units;
151 this.defaultValue = builder.defaultValue;
152 this.fractionDigits = builder.fractionDigits;
159 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
162 public UnknownTypeDefinition getBaseType() {
169 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
172 public String getUnits() {
180 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
184 public Object getDefaultValue() {
191 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
194 public QName getQName() {
201 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
204 public SchemaPath getPath() {
212 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
215 public String getDescription() {
222 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
225 public String getReference() {
232 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
235 public Status getStatus() {
243 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getExtensionSchemaNodes
247 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
254 * @see org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition
255 * #getRangeStatements()
258 public List<RangeConstraint> getRangeConstraints() {
259 return rangeStatements;
265 * @see org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition
266 * #getLengthStatements()
269 public List<LengthConstraint> getLengthConstraints() {
270 return lengthStatements;
276 * @see org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition
280 public List<PatternConstraint> getPatternConstraints() {
285 public Integer getFractionDigits() {
286 return fractionDigits;
290 public int hashCode() {
291 final int prime = 31;
293 result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
294 result = prime * result + ((description == null) ? 0 : description.hashCode());
295 result = prime * result + ((extensions == null) ? 0 : extensions.hashCode());
296 result = prime * result + ((lengthConstraint == null) ? 0 : lengthConstraint.hashCode());
297 result = prime * result + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
298 result = prime * result + ((name == null) ? 0 : name.hashCode());
299 result = prime * result + ((path == null) ? 0 : path.hashCode());
300 result = prime * result + ((patterns == null) ? 0 : patterns.hashCode());
301 result = prime * result + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
302 result = prime * result + ((reference == null) ? 0 : reference.hashCode());
303 result = prime * result + ((status == null) ? 0 : status.hashCode());
304 result = prime * result + ((units == null) ? 0 : units.hashCode());
309 public boolean equals(final Object obj) {
316 if (getClass() != obj.getClass()) {
319 UnknownType other = (UnknownType) obj;
320 if (defaultValue == null) {
321 if (other.defaultValue != null) {
324 } else if (!defaultValue.equals(other.defaultValue)) {
327 if (description == null) {
328 if (other.description != null) {
331 } else if (!description.equals(other.description)) {
334 if (extensions == null) {
335 if (other.extensions != null) {
338 } else if (!extensions.equals(other.extensions)) {
341 if (lengthConstraint == null) {
342 if (other.lengthConstraint != null) {
345 } else if (!lengthConstraint.equals(other.lengthConstraint)) {
348 if (lengthStatements == null) {
349 if (other.lengthStatements != null) {
352 } else if (!lengthStatements.equals(other.lengthStatements)) {
356 if (other.name != null) {
359 } else if (!name.equals(other.name)) {
363 if (other.path != null) {
366 } else if (!path.equals(other.path)) {
369 if (patterns == null) {
370 if (other.patterns != null) {
373 } else if (!patterns.equals(other.patterns)) {
376 if (rangeStatements == null) {
377 if (other.rangeStatements != null) {
380 } else if (!rangeStatements.equals(other.rangeStatements)) {
383 if (reference == null) {
384 if (other.reference != null) {
387 } else if (!reference.equals(other.reference)) {
390 if (status != other.status) {
394 if (other.units != null) {
397 } else if (!units.equals(other.units)) {
404 public String toString() {
405 StringBuilder builder2 = new StringBuilder();
406 builder2.append("UnknownType [name=");
407 builder2.append(name);
408 builder2.append(", path=");
409 builder2.append(path);
410 builder2.append(", description=");
411 builder2.append(description);
412 builder2.append(", reference=");
413 builder2.append(reference);
414 builder2.append(", lengthStatements=");
415 builder2.append(lengthStatements);
416 builder2.append(", patterns=");
417 builder2.append(patterns);
418 builder2.append(", rangeStatements=");
419 builder2.append(rangeStatements);
420 builder2.append(", extensions=");
421 builder2.append(extensions);
422 builder2.append(", lengthConstraint=");
423 builder2.append(lengthConstraint);
424 builder2.append(", status=");
425 builder2.append(status);
426 builder2.append(", units=");
427 builder2.append(units);
428 builder2.append(", defaultValue=");
429 builder2.append(defaultValue);
430 builder2.append("]");
431 return builder2.toString();