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;
41 private boolean addedByUses;
43 public static class Builder {
44 private final QName typeName;
45 private final TypeDefinition<?> baseType;
47 private final SchemaPath path;
48 private final String description;
49 private final String reference;
51 private List<UnknownSchemaNode> unknownSchemaNodes = Collections
53 private Status status = Status.CURRENT;
54 private String units = null;
55 private Object defaultValue = null;
56 private boolean addedByUses;
58 private List<RangeConstraint> ranges = Collections.emptyList();
59 private List<LengthConstraint> lengths = Collections.emptyList();
60 private List<PatternConstraint> patterns = Collections.emptyList();
61 private Integer fractionDigits = null;
63 public Builder(final List<String> actualPath, final URI namespace,
64 final Date revision, final QName typeName,
65 TypeDefinition<?> baseType, final String description,
66 final String reference) {
67 this.typeName = typeName;
68 this.baseType = baseType;
69 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
70 this.description = description;
71 this.reference = reference;
74 public Builder(final QName typeName, TypeDefinition<?> baseType,
75 final String description, final String reference,
77 this.typeName = typeName;
78 this.baseType = baseType;
80 this.description = description;
81 this.reference = reference;
84 public Builder status(Status status) {
89 public Builder units(String units) {
94 public Builder defaultValue(final Object defaultValue) {
95 this.defaultValue = defaultValue;
99 public Builder addedByUses(final boolean addedByUses) {
100 this.addedByUses = addedByUses;
104 public Builder unknownSchemaNodes(
105 final List<UnknownSchemaNode> unknownSchemaNodes) {
106 this.unknownSchemaNodes = unknownSchemaNodes;
110 public Builder ranges(final List<RangeConstraint> ranges) {
111 if (ranges != null) {
112 this.ranges = ranges;
117 public Builder lengths(final List<LengthConstraint> lengths) {
118 if (lengths != null) {
119 this.lengths = lengths;
124 public Builder patterns(final List<PatternConstraint> patterns) {
125 if (patterns != null) {
126 this.patterns = patterns;
131 public Builder fractionDigits(final Integer fractionDigits) {
132 this.fractionDigits = fractionDigits;
136 public ExtendedType build() {
137 return new ExtendedType(this);
141 private ExtendedType(Builder builder) {
142 this.typeName = builder.typeName;
143 this.baseType = builder.baseType;
144 this.path = builder.path;
145 this.description = builder.description;
146 this.reference = builder.reference;
147 this.unknownSchemaNodes = builder.unknownSchemaNodes;
148 this.status = builder.status;
149 this.units = builder.units;
150 this.defaultValue = builder.defaultValue;
151 this.addedByUses = builder.addedByUses;
153 this.ranges = builder.ranges;
154 this.lengths = builder.lengths;
155 this.patterns = builder.patterns;
156 this.fractionDigits = builder.fractionDigits;
160 public TypeDefinition<?> getBaseType() {
165 public String getUnits() {
170 public Object getDefaultValue() {
174 public boolean isAddedByUses() {
179 public QName getQName() {
184 public SchemaPath getPath() {
189 public String getDescription() {
194 public String getReference() {
199 public Status getStatus() {
204 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
205 return unknownSchemaNodes;
209 public boolean equals(Object o) {
213 if (!(o instanceof ExtendedType)) {
217 ExtendedType that = (ExtendedType) o;
218 if (path != null ? !path.equals(that.path) : that.path != null) {
221 if (typeName != null ? !typeName.equals(that.typeName) : that.typeName != null)
228 public int hashCode() {
229 int result = typeName != null ? typeName.hashCode() : 0;
230 result = 31 * result + (path != null ? path.hashCode() : 0);
235 public String toString() {
236 StringBuilder builder = new StringBuilder();
237 builder.append("ExtendedType [typeName=");
238 builder.append(typeName);
239 builder.append(", baseType=");
240 builder.append(baseType);
241 builder.append(", path=");
242 builder.append(path);
243 builder.append(", description=");
244 builder.append(description);
245 builder.append(", reference=");
246 builder.append(reference);
247 builder.append(", unknownSchemaNodes=");
248 builder.append(unknownSchemaNodes);
249 builder.append(", status=");
250 builder.append(status);
251 builder.append(", units=");
252 builder.append(units);
253 builder.append(", defaultValue=");
254 builder.append(defaultValue);
256 return builder.toString();
259 public List<RangeConstraint> getRanges() {
263 public List<LengthConstraint> getLengths() {
267 public List<PatternConstraint> getPatterns() {
271 public Integer getFractionDigits() {
272 return fractionDigits;