2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.controller.model.util;
\r
10 import java.util.Collections;
\r
11 import java.util.List;
\r
13 import org.opendaylight.controller.yang.common.QName;
\r
14 import org.opendaylight.controller.yang.model.api.SchemaPath;
\r
15 import org.opendaylight.controller.yang.model.api.Status;
\r
16 import org.opendaylight.controller.yang.model.api.TypeDefinition;
\r
17 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
\r
19 public class ExtendedType implements TypeDefinition {
\r
21 private final QName typeName;
\r
22 private final TypeDefinition<?> baseType;
\r
23 private final SchemaPath path;
\r
24 private final String description;
\r
25 private final String reference;
\r
26 private final List<UnknownSchemaNode> unknownSchemaNodes;
\r
28 private Status status;
\r
29 private String units;
\r
30 private Object defaultValue;
\r
32 public static class Builder {
\r
33 private final QName typeName;
\r
34 private final TypeDefinition<?> baseType;
\r
36 private final SchemaPath path;
\r
37 private final String description;
\r
38 private final String reference;
\r
40 private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();;
\r
41 private Status status = Status.CURRENT;
\r
42 private String units = "";
\r
43 private Object defaultValue = null;
\r
45 public Builder(final QName typeName, TypeDefinition<?> baseType,
\r
46 final String description, final String reference) {
\r
47 this.typeName = typeName;
\r
48 this.baseType = baseType;
\r
49 this.path = BaseTypes.schemaPath(typeName);
\r
50 this.description = description;
\r
51 this.reference = reference;
\r
54 public Builder status(Status status) {
\r
55 this.status = status;
\r
59 public Builder units(String units) {
\r
64 public Builder defaultValue(final Object defaultValue) {
\r
65 this.defaultValue = defaultValue;
\r
69 public Builder unknownSchemaNodes(final List<UnknownSchemaNode> unknownSchemaNodes) {
\r
70 this.unknownSchemaNodes = unknownSchemaNodes;
\r
74 public ExtendedType build() {
\r
75 return new ExtendedType(this);
\r
79 private ExtendedType(Builder builder) {
\r
80 this.typeName = builder.typeName;
\r
81 this.baseType = builder.baseType;
\r
82 this.path = builder.path;
\r
83 this.description = builder.description;
\r
84 this.reference = builder.reference;
\r
85 this.unknownSchemaNodes = builder.unknownSchemaNodes;
\r
86 this.status = builder.status;
\r
87 this.units = builder.units;
\r
88 this.defaultValue = builder.defaultValue;
\r
92 public TypeDefinition<?> getBaseType() {
\r
97 public String getUnits() {
\r
102 public Object getDefaultValue() {
\r
103 return defaultValue;
\r
107 public QName getQName() {
\r
112 public SchemaPath getPath() {
\r
117 public String getDescription() {
\r
118 return description;
\r
122 public String getReference() {
\r
127 public Status getStatus() {
\r
132 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
\r
133 return unknownSchemaNodes;
\r
137 public int hashCode() {
\r
138 final int prime = 31;
\r
140 result = prime * result
\r
141 + ((baseType == null) ? 0 : baseType.hashCode());
\r
142 result = prime * result
\r
143 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
\r
144 result = prime * result
\r
145 + ((description == null) ? 0 : description.hashCode());
\r
146 result = prime * result
\r
147 + ((unknownSchemaNodes == null) ? 0 : unknownSchemaNodes.hashCode());
\r
148 result = prime * result + ((path == null) ? 0 : path.hashCode());
\r
149 result = prime * result
\r
150 + ((reference == null) ? 0 : reference.hashCode());
\r
151 result = prime * result + ((status == null) ? 0 : status.hashCode());
\r
152 result = prime * result
\r
153 + ((typeName == null) ? 0 : typeName.hashCode());
\r
154 result = prime * result + ((units == null) ? 0 : units.hashCode());
\r
159 public boolean equals(Object obj) {
\r
166 if (getClass() != obj.getClass()) {
\r
169 ExtendedType other = (ExtendedType) obj;
\r
170 if (baseType == null) {
\r
171 if (other.baseType != null) {
\r
174 } else if (!baseType.equals(other.baseType)) {
\r
177 if (defaultValue == null) {
\r
178 if (other.defaultValue != null) {
\r
181 } else if (!defaultValue.equals(other.defaultValue)) {
\r
184 if (description == null) {
\r
185 if (other.description != null) {
\r
188 } else if (!description.equals(other.description)) {
\r
191 if (unknownSchemaNodes == null) {
\r
192 if (other.unknownSchemaNodes != null) {
\r
195 } else if (!unknownSchemaNodes.equals(other.unknownSchemaNodes)) {
\r
198 if (path == null) {
\r
199 if (other.path != null) {
\r
202 } else if (!path.equals(other.path)) {
\r
205 if (reference == null) {
\r
206 if (other.reference != null) {
\r
209 } else if (!reference.equals(other.reference)) {
\r
212 if (status != other.status) {
\r
215 if (typeName == null) {
\r
216 if (other.typeName != null) {
\r
219 } else if (!typeName.equals(other.typeName)) {
\r
222 if (units == null) {
\r
223 if (other.units != null) {
\r
226 } else if (!units.equals(other.units)) {
\r
233 public String toString() {
\r
234 StringBuilder builder2 = new StringBuilder();
\r
235 builder2.append("ExtendedType [typeName=");
\r
236 builder2.append(typeName);
\r
237 builder2.append(", baseType=");
\r
238 builder2.append(baseType);
\r
239 builder2.append(", path=");
\r
240 builder2.append(path);
\r
241 builder2.append(", description=");
\r
242 builder2.append(description);
\r
243 builder2.append(", reference=");
\r
244 builder2.append(reference);
\r
245 builder2.append(", unknownSchemaNodes=");
\r
246 builder2.append(unknownSchemaNodes);
\r
247 builder2.append(", status=");
\r
248 builder2.append(status);
\r
249 builder2.append(", units=");
\r
250 builder2.append(units);
\r
251 builder2.append(", defaultValue=");
\r
252 builder2.append(defaultValue);
\r
253 builder2.append("]");
\r
254 return builder2.toString();
\r