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;
19 public class ExtendedType implements TypeDefinition {
21 private final QName typeName;
22 private final TypeDefinition<?> baseType;
23 private final SchemaPath path;
24 private final String description;
25 private final String reference;
26 private final List<UnknownSchemaNode> unknownSchemaNodes;
28 private Status status;
30 private Object defaultValue;
32 public static class Builder {
33 private final QName typeName;
34 private final TypeDefinition<?> baseType;
36 private final SchemaPath path;
37 private final String description;
38 private final String reference;
40 private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();;
41 private Status status = Status.CURRENT;
42 private String units = "";
43 private Object defaultValue = null;
45 public Builder(final QName typeName, TypeDefinition<?> baseType,
46 final String description, final String reference) {
47 this.typeName = typeName;
48 this.baseType = baseType;
49 this.path = BaseTypes.schemaPath(typeName);
50 this.description = description;
51 this.reference = reference;
54 public Builder status(Status status) {
59 public Builder units(String units) {
64 public Builder defaultValue(final Object defaultValue) {
65 this.defaultValue = defaultValue;
69 public Builder unknownSchemaNodes(final List<UnknownSchemaNode> unknownSchemaNodes) {
70 this.unknownSchemaNodes = unknownSchemaNodes;
74 public ExtendedType build() {
75 return new ExtendedType(this);
79 private ExtendedType(Builder builder) {
80 this.typeName = builder.typeName;
81 this.baseType = builder.baseType;
82 this.path = builder.path;
83 this.description = builder.description;
84 this.reference = builder.reference;
85 this.unknownSchemaNodes = builder.unknownSchemaNodes;
86 this.status = builder.status;
87 this.units = builder.units;
88 this.defaultValue = builder.defaultValue;
92 public TypeDefinition<?> getBaseType() {
97 public String getUnits() {
102 public Object getDefaultValue() {
107 public QName getQName() {
112 public SchemaPath getPath() {
117 public String getDescription() {
122 public String getReference() {
127 public Status getStatus() {
132 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
133 return unknownSchemaNodes;
137 public int hashCode() {
138 final int prime = 31;
140 result = prime * result
141 + ((baseType == null) ? 0 : baseType.hashCode());
142 result = prime * result
143 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
144 result = prime * result
145 + ((description == null) ? 0 : description.hashCode());
146 result = prime * result
147 + ((unknownSchemaNodes == null) ? 0 : unknownSchemaNodes.hashCode());
148 result = prime * result + ((path == null) ? 0 : path.hashCode());
149 result = prime * result
150 + ((reference == null) ? 0 : reference.hashCode());
151 result = prime * result + ((status == null) ? 0 : status.hashCode());
152 result = prime * result
153 + ((typeName == null) ? 0 : typeName.hashCode());
154 result = prime * result + ((units == null) ? 0 : units.hashCode());
159 public boolean equals(Object obj) {
166 if (getClass() != obj.getClass()) {
169 ExtendedType other = (ExtendedType) obj;
170 if (baseType == null) {
171 if (other.baseType != null) {
174 } else if (!baseType.equals(other.baseType)) {
177 if (defaultValue == null) {
178 if (other.defaultValue != null) {
181 } else if (!defaultValue.equals(other.defaultValue)) {
184 if (description == null) {
185 if (other.description != null) {
188 } else if (!description.equals(other.description)) {
191 if (unknownSchemaNodes == null) {
192 if (other.unknownSchemaNodes != null) {
195 } else if (!unknownSchemaNodes.equals(other.unknownSchemaNodes)) {
199 if (other.path != null) {
202 } else if (!path.equals(other.path)) {
205 if (reference == null) {
206 if (other.reference != null) {
209 } else if (!reference.equals(other.reference)) {
212 if (status != other.status) {
215 if (typeName == null) {
216 if (other.typeName != null) {
219 } else if (!typeName.equals(other.typeName)) {
223 if (other.units != null) {
226 } else if (!units.equals(other.units)) {
233 public String toString() {
234 StringBuilder builder2 = new StringBuilder();
235 builder2.append("ExtendedType [typeName=");
236 builder2.append(typeName);
237 builder2.append(", baseType=");
238 builder2.append(baseType);
239 builder2.append(", path=");
240 builder2.append(path);
241 builder2.append(", description=");
242 builder2.append(description);
243 builder2.append(", reference=");
244 builder2.append(reference);
245 builder2.append(", unknownSchemaNodes=");
246 builder2.append(unknownSchemaNodes);
247 builder2.append(", status=");
248 builder2.append(status);
249 builder2.append(", units=");
250 builder2.append(units);
251 builder2.append(", defaultValue=");
252 builder2.append(defaultValue);
253 builder2.append("]");
254 return builder2.toString();