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;
11 import java.util.Collections;
12 import java.util.Date;
13 import java.util.List;
15 import org.opendaylight.controller.yang.common.QName;
16 import org.opendaylight.controller.yang.model.api.SchemaPath;
17 import org.opendaylight.controller.yang.model.api.Status;
18 import org.opendaylight.controller.yang.model.api.TypeDefinition;
19 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
20 import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
21 import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
22 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
24 public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
26 private final QName typeName;
27 private final TypeDefinition<?> baseType;
28 private final SchemaPath path;
29 private final String description;
30 private final String reference;
31 private final List<UnknownSchemaNode> unknownSchemaNodes;
33 private List<RangeConstraint> ranges = Collections.emptyList();
34 private List<LengthConstraint> lengths = Collections.emptyList();
35 private List<PatternConstraint> patterns = Collections.emptyList();
36 private Integer fractionDigits = null;
38 private Status status;
40 private Object defaultValue;
42 public static class Builder {
43 private final QName typeName;
44 private final TypeDefinition<?> baseType;
46 private final SchemaPath path;
47 private final String description;
48 private final String reference;
50 private List<UnknownSchemaNode> unknownSchemaNodes = Collections
52 private Status status = Status.CURRENT;
53 private String units = "";
54 private Object defaultValue = null;
56 private List<RangeConstraint> ranges = Collections.emptyList();
57 private List<LengthConstraint> lengths = Collections.emptyList();
58 private List<PatternConstraint> patterns = Collections.emptyList();
59 private Integer fractionDigits = null;
61 public Builder(final List<String> actualPath, final URI namespace,
62 final Date revision, final QName typeName,
63 TypeDefinition<?> baseType, final String description,
64 final String reference) {
65 this.typeName = typeName;
66 this.baseType = baseType;
67 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
68 this.description = description;
69 this.reference = reference;
72 public Builder(final QName typeName, TypeDefinition<?> baseType,
73 final String description, final String reference,
75 this.typeName = typeName;
76 this.baseType = baseType;
78 this.description = description;
79 this.reference = reference;
82 public Builder status(Status status) {
87 public Builder units(String units) {
92 public Builder defaultValue(final Object defaultValue) {
93 this.defaultValue = defaultValue;
97 public Builder unknownSchemaNodes(
98 final List<UnknownSchemaNode> unknownSchemaNodes) {
99 this.unknownSchemaNodes = unknownSchemaNodes;
103 public Builder ranges(final List<RangeConstraint> ranges) {
104 if (ranges != null) {
105 this.ranges = ranges;
110 public Builder lengths(final List<LengthConstraint> lengths) {
111 if (lengths != null) {
112 this.lengths = lengths;
117 public Builder patterns(final List<PatternConstraint> patterns) {
118 if (patterns != null) {
119 this.patterns = patterns;
124 public Builder fractionDigits(final Integer fractionDigits) {
125 this.fractionDigits = fractionDigits;
129 public ExtendedType build() {
130 return new ExtendedType(this);
134 private ExtendedType(Builder builder) {
135 this.typeName = builder.typeName;
136 this.baseType = builder.baseType;
137 this.path = builder.path;
138 this.description = builder.description;
139 this.reference = builder.reference;
140 this.unknownSchemaNodes = builder.unknownSchemaNodes;
141 this.status = builder.status;
142 this.units = builder.units;
143 this.defaultValue = builder.defaultValue;
145 this.ranges = builder.ranges;
146 this.lengths = builder.lengths;
147 this.patterns = builder.patterns;
148 this.fractionDigits = builder.fractionDigits;
152 public TypeDefinition<?> getBaseType() {
157 public String getUnits() {
162 public Object getDefaultValue() {
167 public QName getQName() {
172 public SchemaPath getPath() {
177 public String getDescription() {
182 public String getReference() {
187 public Status getStatus() {
192 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
193 return unknownSchemaNodes;
197 public int hashCode() {
198 final int prime = 31;
200 result = prime * result
201 + ((baseType == null) ? 0 : baseType.hashCode());
202 result = prime * result
203 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
204 result = prime * result
205 + ((description == null) ? 0 : description.hashCode());
208 + ((unknownSchemaNodes == null) ? 0 : unknownSchemaNodes
210 result = prime * result + ((path == null) ? 0 : path.hashCode());
211 result = prime * result
212 + ((reference == null) ? 0 : reference.hashCode());
213 result = prime * result + ((status == null) ? 0 : status.hashCode());
214 result = prime * result
215 + ((typeName == null) ? 0 : typeName.hashCode());
216 result = prime * result + ((units == null) ? 0 : units.hashCode());
221 public boolean equals(Object obj) {
228 if (getClass() != obj.getClass()) {
231 ExtendedType other = (ExtendedType) obj;
232 if (baseType == null) {
233 if (other.baseType != null) {
236 } else if (!baseType.equals(other.baseType)) {
239 if (defaultValue == null) {
240 if (other.defaultValue != null) {
243 } else if (!defaultValue.equals(other.defaultValue)) {
246 if (description == null) {
247 if (other.description != null) {
250 } else if (!description.equals(other.description)) {
253 if (unknownSchemaNodes == null) {
254 if (other.unknownSchemaNodes != null) {
257 } else if (!unknownSchemaNodes.equals(other.unknownSchemaNodes)) {
261 if (other.path != null) {
264 } else if (!path.equals(other.path)) {
267 if (reference == null) {
268 if (other.reference != null) {
271 } else if (!reference.equals(other.reference)) {
274 if (status != other.status) {
277 if (typeName == null) {
278 if (other.typeName != null) {
281 } else if (!typeName.equals(other.typeName)) {
285 if (other.units != null) {
288 } else if (!units.equals(other.units)) {
295 public String toString() {
296 StringBuilder builder2 = new StringBuilder();
297 builder2.append("ExtendedType [typeName=");
298 builder2.append(typeName);
299 builder2.append(", baseType=");
300 builder2.append(baseType);
301 builder2.append(", path=");
302 builder2.append(path);
303 builder2.append(", description=");
304 builder2.append(description);
305 builder2.append(", reference=");
306 builder2.append(reference);
307 builder2.append(", unknownSchemaNodes=");
308 builder2.append(unknownSchemaNodes);
309 builder2.append(", status=");
310 builder2.append(status);
311 builder2.append(", units=");
312 builder2.append(units);
313 builder2.append(", defaultValue=");
314 builder2.append(defaultValue);
315 builder2.append("]");
316 return builder2.toString();
319 public List<RangeConstraint> getRanges() {
323 public List<LengthConstraint> getLengths() {
327 public List<PatternConstraint> getPatterns() {
331 public Integer getFractionDigits() {
332 return fractionDigits;