Fixed bugs in naming conventions of packages.
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / yang / model / util / ExtendedType.java
1 /*
2   * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3   *
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
7   */
8 package org.opendaylight.controller.yang.model.util;
9
10 import java.util.Collections;
11 import java.util.List;
12
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
19 public class ExtendedType implements TypeDefinition {
20
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;
27
28     private Status status;
29     private String units;
30     private Object defaultValue;
31
32     public static class Builder {
33         private final QName typeName;
34         private final TypeDefinition<?> baseType;
35
36         private final SchemaPath path;
37         private final String description;
38         private final String reference;
39
40         private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();;
41         private Status status = Status.CURRENT;
42         private String units = "";
43         private Object defaultValue = null;
44
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;
52         }
53
54         public Builder status(Status status) {
55             this.status = status;
56             return this;
57         }
58
59         public Builder units(String units) {
60             this.units = units;
61             return this;
62         }
63
64         public Builder defaultValue(final Object defaultValue) {
65             this.defaultValue = defaultValue;
66             return this;
67         }
68
69         public Builder unknownSchemaNodes(final List<UnknownSchemaNode> unknownSchemaNodes) {
70             this.unknownSchemaNodes = unknownSchemaNodes;
71             return this;
72         }
73
74         public ExtendedType build() {
75             return new ExtendedType(this);
76         }
77     }
78
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;
89     }
90
91     @Override
92     public TypeDefinition<?> getBaseType() {
93         return baseType;
94     }
95
96     @Override
97     public String getUnits() {
98         return units;
99     }
100
101     @Override
102     public Object getDefaultValue() {
103         return defaultValue;
104     }
105
106     @Override
107     public QName getQName() {
108         return typeName;
109     }
110
111     @Override
112     public SchemaPath getPath() {
113         return path;
114     }
115
116     @Override
117     public String getDescription() {
118         return description;
119     }
120
121     @Override
122     public String getReference() {
123         return reference;
124     }
125
126     @Override
127     public Status getStatus() {
128         return status;
129     }
130
131     @Override
132     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
133         return unknownSchemaNodes;
134     }
135
136     @Override
137     public int hashCode() {
138         final int prime = 31;
139         int result = 1;
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());
155         return result;
156     }
157
158     @Override
159     public boolean equals(Object obj) {
160         if (this == obj) {
161             return true;
162         }
163         if (obj == null) {
164             return false;
165         }
166         if (getClass() != obj.getClass()) {
167             return false;
168         }
169         ExtendedType other = (ExtendedType) obj;
170         if (baseType == null) {
171             if (other.baseType != null) {
172                 return false;
173             }
174         } else if (!baseType.equals(other.baseType)) {
175             return false;
176         }
177         if (defaultValue == null) {
178             if (other.defaultValue != null) {
179                 return false;
180             }
181         } else if (!defaultValue.equals(other.defaultValue)) {
182             return false;
183         }
184         if (description == null) {
185             if (other.description != null) {
186                 return false;
187             }
188         } else if (!description.equals(other.description)) {
189             return false;
190         }
191         if (unknownSchemaNodes == null) {
192             if (other.unknownSchemaNodes != null) {
193                 return false;
194             }
195         } else if (!unknownSchemaNodes.equals(other.unknownSchemaNodes)) {
196             return false;
197         }
198         if (path == null) {
199             if (other.path != null) {
200                 return false;
201             }
202         } else if (!path.equals(other.path)) {
203             return false;
204         }
205         if (reference == null) {
206             if (other.reference != null) {
207                 return false;
208             }
209         } else if (!reference.equals(other.reference)) {
210             return false;
211         }
212         if (status != other.status) {
213             return false;
214         }
215         if (typeName == null) {
216             if (other.typeName != null) {
217                 return false;
218             }
219         } else if (!typeName.equals(other.typeName)) {
220             return false;
221         }
222         if (units == null) {
223             if (other.units != null) {
224                 return false;
225             }
226         } else if (!units.equals(other.units)) {
227             return false;
228         }
229         return true;
230     }
231
232     @Override
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();
255     }
256 }