Parents pom distribution
[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.net.URI;
11 import java.util.Collections;
12 import java.util.Date;
13 import java.util.List;
14
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;
23
24 public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
25
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;
32
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;
37
38     private Status status;
39     private String units;
40     private Object defaultValue;
41
42     public static class Builder {
43         private final QName typeName;
44         private final TypeDefinition<?> baseType;
45
46         private final SchemaPath path;
47         private final String description;
48         private final String reference;
49
50         private List<UnknownSchemaNode> unknownSchemaNodes = Collections
51                 .emptyList();
52         private Status status = Status.CURRENT;
53         private String units = "";
54         private Object defaultValue = null;
55
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;
60
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;
70         }
71
72         public Builder(final QName typeName, TypeDefinition<?> baseType,
73                 final String description, final String reference,
74                 SchemaPath path) {
75             this.typeName = typeName;
76             this.baseType = baseType;
77             this.path = path;
78             this.description = description;
79             this.reference = reference;
80         }
81
82         public Builder status(Status status) {
83             this.status = status;
84             return this;
85         }
86
87         public Builder units(String units) {
88             this.units = units;
89             return this;
90         }
91
92         public Builder defaultValue(final Object defaultValue) {
93             this.defaultValue = defaultValue;
94             return this;
95         }
96
97         public Builder unknownSchemaNodes(
98                 final List<UnknownSchemaNode> unknownSchemaNodes) {
99             this.unknownSchemaNodes = unknownSchemaNodes;
100             return this;
101         }
102
103         public Builder ranges(final List<RangeConstraint> ranges) {
104             if (ranges != null) {
105                 this.ranges = ranges;
106             }
107             return this;
108         }
109
110         public Builder lengths(final List<LengthConstraint> lengths) {
111             if (lengths != null) {
112                 this.lengths = lengths;
113             }
114             return this;
115         }
116
117         public Builder patterns(final List<PatternConstraint> patterns) {
118             if (patterns != null) {
119                 this.patterns = patterns;
120             }
121             return this;
122         }
123
124         public Builder fractionDigits(final Integer fractionDigits) {
125             this.fractionDigits = fractionDigits;
126             return this;
127         }
128
129         public ExtendedType build() {
130             return new ExtendedType(this);
131         }
132     }
133
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;
144
145         this.ranges = builder.ranges;
146         this.lengths = builder.lengths;
147         this.patterns = builder.patterns;
148         this.fractionDigits = builder.fractionDigits;
149     }
150
151     @Override
152     public TypeDefinition<?> getBaseType() {
153         return baseType;
154     }
155
156     @Override
157     public String getUnits() {
158         return units;
159     }
160
161     @Override
162     public Object getDefaultValue() {
163         return defaultValue;
164     }
165
166     @Override
167     public QName getQName() {
168         return typeName;
169     }
170
171     @Override
172     public SchemaPath getPath() {
173         return path;
174     }
175
176     @Override
177     public String getDescription() {
178         return description;
179     }
180
181     @Override
182     public String getReference() {
183         return reference;
184     }
185
186     @Override
187     public Status getStatus() {
188         return status;
189     }
190
191     @Override
192     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
193         return unknownSchemaNodes;
194     }
195
196     @Override
197     public int hashCode() {
198         final int prime = 31;
199         int result = 1;
200         result = prime * result
201                 + ((baseType == null) ? 0 : baseType.hashCode());
202         result = prime * result
203                 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
204         result = prime * result
205                 + ((description == null) ? 0 : description.hashCode());
206         result = prime
207                 * result
208                 + ((unknownSchemaNodes == null) ? 0 : unknownSchemaNodes
209                         .hashCode());
210         result = prime * result + ((path == null) ? 0 : path.hashCode());
211         result = prime * result
212                 + ((reference == null) ? 0 : reference.hashCode());
213         result = prime * result + ((status == null) ? 0 : status.hashCode());
214         result = prime * result
215                 + ((typeName == null) ? 0 : typeName.hashCode());
216         result = prime * result + ((units == null) ? 0 : units.hashCode());
217         return result;
218     }
219
220     @Override
221     public boolean equals(Object obj) {
222         if (this == obj) {
223             return true;
224         }
225         if (obj == null) {
226             return false;
227         }
228         if (getClass() != obj.getClass()) {
229             return false;
230         }
231         ExtendedType other = (ExtendedType) obj;
232         if (baseType == null) {
233             if (other.baseType != null) {
234                 return false;
235             }
236         } else if (!baseType.equals(other.baseType)) {
237             return false;
238         }
239         if (defaultValue == null) {
240             if (other.defaultValue != null) {
241                 return false;
242             }
243         } else if (!defaultValue.equals(other.defaultValue)) {
244             return false;
245         }
246         if (description == null) {
247             if (other.description != null) {
248                 return false;
249             }
250         } else if (!description.equals(other.description)) {
251             return false;
252         }
253         if (unknownSchemaNodes == null) {
254             if (other.unknownSchemaNodes != null) {
255                 return false;
256             }
257         } else if (!unknownSchemaNodes.equals(other.unknownSchemaNodes)) {
258             return false;
259         }
260         if (path == null) {
261             if (other.path != null) {
262                 return false;
263             }
264         } else if (!path.equals(other.path)) {
265             return false;
266         }
267         if (reference == null) {
268             if (other.reference != null) {
269                 return false;
270             }
271         } else if (!reference.equals(other.reference)) {
272             return false;
273         }
274         if (status != other.status) {
275             return false;
276         }
277         if (typeName == null) {
278             if (other.typeName != null) {
279                 return false;
280             }
281         } else if (!typeName.equals(other.typeName)) {
282             return false;
283         }
284         if (units == null) {
285             if (other.units != null) {
286                 return false;
287             }
288         } else if (!units.equals(other.units)) {
289             return false;
290         }
291         return true;
292     }
293
294     @Override
295     public String toString() {
296         StringBuilder builder2 = new StringBuilder();
297         builder2.append("ExtendedType [typeName=");
298         builder2.append(typeName);
299         builder2.append(", baseType=");
300         builder2.append(baseType);
301         builder2.append(", path=");
302         builder2.append(path);
303         builder2.append(", description=");
304         builder2.append(description);
305         builder2.append(", reference=");
306         builder2.append(reference);
307         builder2.append(", unknownSchemaNodes=");
308         builder2.append(unknownSchemaNodes);
309         builder2.append(", status=");
310         builder2.append(status);
311         builder2.append(", units=");
312         builder2.append(units);
313         builder2.append(", defaultValue=");
314         builder2.append(defaultValue);
315         builder2.append("]");
316         return builder2.toString();
317     }
318
319     public List<RangeConstraint> getRanges() {
320         return ranges;
321     }
322
323     public List<LengthConstraint> getLengths() {
324         return lengths;
325     }
326
327     public List<PatternConstraint> getPatterns() {
328         return patterns;
329     }
330
331     public Integer getFractionDigits() {
332         return fractionDigits;
333     }
334 }