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.TypeDefinition;
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.RangeConstraint;
22 public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
24 private final QName typeName;
25 private final TypeDefinition<?> baseType;
26 private final SchemaPath path;
27 private final String description;
28 private final String reference;
29 private final List<UnknownSchemaNode> unknownSchemaNodes;
31 private List<RangeConstraint> ranges = Collections.emptyList();
32 private List<LengthConstraint> lengths = Collections.emptyList();
33 private List<PatternConstraint> patterns = Collections.emptyList();
34 private Integer fractionDigits = null;
37 private Status status;
39 private Object defaultValue;
41 public static class Builder {
42 private final QName typeName;
43 private final TypeDefinition<?> baseType;
45 private final SchemaPath path;
46 private final String description;
47 private final String reference;
49 private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();;
50 private Status status = Status.CURRENT;
51 private String units = "";
52 private Object defaultValue = null;
54 private List<RangeConstraint> ranges = Collections.emptyList();
55 private List<LengthConstraint> lengths = Collections.emptyList();
56 private List<PatternConstraint> patterns = Collections.emptyList();
57 private Integer fractionDigits = null;
59 public Builder(final QName typeName, TypeDefinition<?> baseType,
60 final String description, final String reference) {
61 this.typeName = typeName;
62 this.baseType = baseType;
63 this.path = BaseTypes.schemaPath(typeName);
64 this.description = description;
65 this.reference = reference;
68 public Builder status(Status status) {
73 public Builder units(String units) {
78 public Builder defaultValue(final Object defaultValue) {
79 this.defaultValue = defaultValue;
83 public Builder unknownSchemaNodes(final List<UnknownSchemaNode> unknownSchemaNodes) {
84 this.unknownSchemaNodes = unknownSchemaNodes;
88 public Builder ranges(final List<RangeConstraint> ranges) {
95 public Builder lengths(final List<LengthConstraint> lengths) {
97 this.lengths = lengths;
102 public Builder patterns(final List<PatternConstraint> patterns) {
103 if(patterns != null) {
104 this.patterns = patterns;
109 public Builder fractionDigits(final Integer fractionDigits) {
110 this.fractionDigits = fractionDigits;
114 public ExtendedType build() {
115 return new ExtendedType(this);
119 private ExtendedType(Builder builder) {
120 this.typeName = builder.typeName;
121 this.baseType = builder.baseType;
122 this.path = builder.path;
123 this.description = builder.description;
124 this.reference = builder.reference;
125 this.unknownSchemaNodes = builder.unknownSchemaNodes;
126 this.status = builder.status;
127 this.units = builder.units;
128 this.defaultValue = builder.defaultValue;
130 this.ranges = builder.ranges;
131 this.lengths = builder.lengths;
132 this.patterns = builder.patterns;
133 this.fractionDigits = builder.fractionDigits;
137 public TypeDefinition<?> getBaseType() {
142 public String getUnits() {
147 public Object getDefaultValue() {
152 public QName getQName() {
157 public SchemaPath getPath() {
162 public String getDescription() {
167 public String getReference() {
172 public Status getStatus() {
177 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
178 return unknownSchemaNodes;
182 public int hashCode() {
183 final int prime = 31;
185 result = prime * result
186 + ((baseType == null) ? 0 : baseType.hashCode());
187 result = prime * result
188 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
189 result = prime * result
190 + ((description == null) ? 0 : description.hashCode());
191 result = prime * result
192 + ((unknownSchemaNodes == null) ? 0 : unknownSchemaNodes.hashCode());
193 result = prime * result + ((path == null) ? 0 : path.hashCode());
194 result = prime * result
195 + ((reference == null) ? 0 : reference.hashCode());
196 result = prime * result + ((status == null) ? 0 : status.hashCode());
197 result = prime * result
198 + ((typeName == null) ? 0 : typeName.hashCode());
199 result = prime * result + ((units == null) ? 0 : units.hashCode());
204 public boolean equals(Object obj) {
211 if (getClass() != obj.getClass()) {
214 ExtendedType other = (ExtendedType) obj;
215 if (baseType == null) {
216 if (other.baseType != null) {
219 } else if (!baseType.equals(other.baseType)) {
222 if (defaultValue == null) {
223 if (other.defaultValue != null) {
226 } else if (!defaultValue.equals(other.defaultValue)) {
229 if (description == null) {
230 if (other.description != null) {
233 } else if (!description.equals(other.description)) {
236 if (unknownSchemaNodes == null) {
237 if (other.unknownSchemaNodes != null) {
240 } else if (!unknownSchemaNodes.equals(other.unknownSchemaNodes)) {
244 if (other.path != null) {
247 } else if (!path.equals(other.path)) {
250 if (reference == null) {
251 if (other.reference != null) {
254 } else if (!reference.equals(other.reference)) {
257 if (status != other.status) {
260 if (typeName == null) {
261 if (other.typeName != null) {
264 } else if (!typeName.equals(other.typeName)) {
268 if (other.units != null) {
271 } else if (!units.equals(other.units)) {
278 public String toString() {
279 StringBuilder builder2 = new StringBuilder();
280 builder2.append("ExtendedType [typeName=");
281 builder2.append(typeName);
282 builder2.append(", baseType=");
283 builder2.append(baseType);
284 builder2.append(", path=");
285 builder2.append(path);
286 builder2.append(", description=");
287 builder2.append(description);
288 builder2.append(", reference=");
289 builder2.append(reference);
290 builder2.append(", unknownSchemaNodes=");
291 builder2.append(unknownSchemaNodes);
292 builder2.append(", status=");
293 builder2.append(status);
294 builder2.append(", units=");
295 builder2.append(units);
296 builder2.append(", defaultValue=");
297 builder2.append(defaultValue);
298 builder2.append("]");
299 return builder2.toString();
302 public List<RangeConstraint> getRanges() {
306 public List<LengthConstraint> getLengths() {
310 public List<PatternConstraint> getPatterns() {
314 public Integer getFractionDigits() {
315 return fractionDigits;