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.Collections;
11 import java.util.List;
13 import org.opendaylight.controller.yang.common.QName;
14 import org.opendaylight.controller.yang.model.api.SchemaPath;
15 import org.opendaylight.controller.yang.model.api.Status;
16 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
17 import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
18 import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
19 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
20 import org.opendaylight.controller.yang.model.api.type.UnknownTypeDefinition;
22 public class UnknownType implements UnknownTypeDefinition {
24 private final QName name;
25 private final SchemaPath path;
26 private final String description;
27 private final String reference;
29 private final List<LengthConstraint> lengthStatements;
30 private final List<PatternConstraint> patterns;
31 private final List<RangeConstraint> rangeStatements;
32 private final List<UnknownSchemaNode> extensions;
33 private final LengthConstraint lengthConstraint;
34 private final Integer fractionDigits;
36 private final Status status;
37 private final String units;
38 private final Object defaultValue;
40 public static class Builder {
42 private final QName name;
43 private final SchemaPath path;
44 private String description;
45 private String reference;
47 private List<LengthConstraint> lengthStatements = Collections
49 private List<PatternConstraint> patterns = Collections.emptyList();
50 private List<RangeConstraint> rangeStatements = Collections.emptyList();
51 private List<UnknownSchemaNode> extensions = Collections.emptyList();
52 private LengthConstraint lengthConstraint = null;
53 private Integer fractionDigits = null;
55 private Status status = Status.CURRENT;
56 private String units = "";
57 private Object defaultValue = null;
59 public Builder(final QName name, final String description,
60 final String reference) {
62 this.path = BaseTypes.schemaPath(name);
63 this.description = description;
64 this.reference = reference;
67 public Builder(final QName name) {
69 this.path = BaseTypes.schemaPath(name);
72 public Builder description(String description) {
73 this.description = description;
77 public Builder reference(String reference) {
78 this.reference = reference;
82 public Builder lengthStatements(
83 final List<LengthConstraint> lengthStatements) {
84 this.lengthStatements = lengthStatements;
88 public Builder patterns(final List<PatternConstraint> patterns) {
89 this.patterns = patterns;
93 public Builder rangeStatements(
94 final List<RangeConstraint> rangeStatements) {
95 this.rangeStatements = rangeStatements;
99 public Builder extensions(final List<UnknownSchemaNode> extensions) {
100 this.extensions = extensions;
104 public Builder lengthConstraint(final LengthConstraint lengthConstraint) {
105 this.lengthConstraint = lengthConstraint;
109 public Builder fractionDigits(final Integer fractionDigits) {
110 this.fractionDigits = fractionDigits;
114 public Builder status(Status status) {
115 this.status = status;
119 public Builder units(String units) {
124 public Builder defaultValue(final Object defaultValue) {
125 this.defaultValue = defaultValue;
129 public UnknownTypeDefinition build() {
130 return new UnknownType(this);
134 private UnknownType(Builder builder) {
135 this.name = builder.name;
136 this.path = builder.path;
137 this.description = builder.description;
138 this.reference = builder.reference;
139 this.lengthStatements = builder.lengthStatements;
140 this.patterns = builder.patterns;
141 this.rangeStatements = builder.rangeStatements;
142 this.extensions = builder.extensions;
143 this.lengthConstraint = builder.lengthConstraint;
144 this.status = builder.status;
145 this.units = builder.units;
146 this.defaultValue = builder.defaultValue;
147 this.fractionDigits = builder.fractionDigits;
154 * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
157 public UnknownTypeDefinition getBaseType() {
164 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
167 public String getUnits() {
175 * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
179 public Object getDefaultValue() {
186 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
189 public QName getQName() {
196 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
199 public SchemaPath getPath() {
207 * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
210 public String getDescription() {
217 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
220 public String getReference() {
227 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
230 public Status getStatus() {
238 * org.opendaylight.controller.yang.model.api.SchemaNode#getExtensionSchemaNodes
242 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
250 * org.opendaylight.controller.yang.model.api.type.UnknownTypeDefinition
251 * #getRangeStatements()
254 public List<RangeConstraint> getRangeStatements() {
255 return rangeStatements;
262 * org.opendaylight.controller.yang.model.api.type.UnknownTypeDefinition
263 * #getLengthStatements()
266 public List<LengthConstraint> getLengthStatements() {
267 return lengthStatements;
274 * org.opendaylight.controller.yang.model.api.type.UnknownTypeDefinition
278 public List<PatternConstraint> getPatterns() {
286 * org.opendaylight.controller.yang.model.api.type.UnknownTypeDefinition
287 * #getLengthConstraint()
290 public LengthConstraint getLengthConstraint() {
291 return lengthConstraint;
295 public Integer getFractionDigits() {
296 return fractionDigits;
300 public int hashCode() {
301 final int prime = 31;
303 result = prime * result
304 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
305 result = prime * result
306 + ((description == null) ? 0 : description.hashCode());
307 result = prime * result
308 + ((extensions == null) ? 0 : extensions.hashCode());
311 + ((lengthConstraint == null) ? 0 : lengthConstraint.hashCode());
314 + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
315 result = prime * result + ((name == null) ? 0 : name.hashCode());
316 result = prime * result + ((path == null) ? 0 : path.hashCode());
317 result = prime * result
318 + ((patterns == null) ? 0 : patterns.hashCode());
319 result = prime * result
320 + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
321 result = prime * result
322 + ((reference == null) ? 0 : reference.hashCode());
323 result = prime * result + ((status == null) ? 0 : status.hashCode());
324 result = prime * result + ((units == null) ? 0 : units.hashCode());
329 public boolean equals(Object obj) {
336 if (getClass() != obj.getClass()) {
339 UnknownType other = (UnknownType) obj;
340 if (defaultValue == null) {
341 if (other.defaultValue != null) {
344 } else if (!defaultValue.equals(other.defaultValue)) {
347 if (description == null) {
348 if (other.description != null) {
351 } else if (!description.equals(other.description)) {
354 if (extensions == null) {
355 if (other.extensions != null) {
358 } else if (!extensions.equals(other.extensions)) {
361 if (lengthConstraint == null) {
362 if (other.lengthConstraint != null) {
365 } else if (!lengthConstraint.equals(other.lengthConstraint)) {
368 if (lengthStatements == null) {
369 if (other.lengthStatements != null) {
372 } else if (!lengthStatements.equals(other.lengthStatements)) {
376 if (other.name != null) {
379 } else if (!name.equals(other.name)) {
383 if (other.path != null) {
386 } else if (!path.equals(other.path)) {
389 if (patterns == null) {
390 if (other.patterns != null) {
393 } else if (!patterns.equals(other.patterns)) {
396 if (rangeStatements == null) {
397 if (other.rangeStatements != null) {
400 } else if (!rangeStatements.equals(other.rangeStatements)) {
403 if (reference == null) {
404 if (other.reference != null) {
407 } else if (!reference.equals(other.reference)) {
410 if (status != other.status) {
414 if (other.units != null) {
417 } else if (!units.equals(other.units)) {
424 public String toString() {
425 StringBuilder builder2 = new StringBuilder();
426 builder2.append("UnknownType [name=");
427 builder2.append(name);
428 builder2.append(", path=");
429 builder2.append(path);
430 builder2.append(", description=");
431 builder2.append(description);
432 builder2.append(", reference=");
433 builder2.append(reference);
434 builder2.append(", lengthStatements=");
435 builder2.append(lengthStatements);
436 builder2.append(", patterns=");
437 builder2.append(patterns);
438 builder2.append(", rangeStatements=");
439 builder2.append(rangeStatements);
440 builder2.append(", extensions=");
441 builder2.append(extensions);
442 builder2.append(", lengthConstraint=");
443 builder2.append(lengthConstraint);
444 builder2.append(", status=");
445 builder2.append(status);
446 builder2.append(", units=");
447 builder2.append(units);
448 builder2.append(", defaultValue=");
449 builder2.append(defaultValue);
450 builder2.append("]");
451 return builder2.toString();