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 boolean equals(Object o) {
201 if (!(o instanceof ExtendedType)) {
205 ExtendedType that = (ExtendedType) o;
206 if (path != null ? !path.equals(that.path) : that.path != null) {
209 if (typeName != null ? !typeName.equals(that.typeName) : that.typeName != null)
216 public int hashCode() {
217 int result = typeName != null ? typeName.hashCode() : 0;
218 result = 31 * result + (path != null ? path.hashCode() : 0);
223 public String toString() {
224 StringBuilder builder = new StringBuilder();
225 builder.append("ExtendedType [typeName=");
226 builder.append(typeName);
227 builder.append(", baseType=");
228 builder.append(baseType);
229 builder.append(", path=");
230 builder.append(path);
231 builder.append(", description=");
232 builder.append(description);
233 builder.append(", reference=");
234 builder.append(reference);
235 builder.append(", unknownSchemaNodes=");
236 builder.append(unknownSchemaNodes);
237 builder.append(", status=");
238 builder.append(status);
239 builder.append(", units=");
240 builder.append(units);
241 builder.append(", defaultValue=");
242 builder.append(defaultValue);
244 return builder.toString();
247 public List<RangeConstraint> getRanges() {
251 public List<LengthConstraint> getLengths() {
255 public List<PatternConstraint> getPatterns() {
259 public Integer getFractionDigits() {
260 return fractionDigits;