33cb2b02687f956c2f8dbac5ced59ff9f08f6787
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / model / util / AbstractInteger.java
1 /*\r
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\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
7  */\r
8 package org.opendaylight.controller.model.util;\r
9 \r
10 import java.util.Collections;\r
11 import java.util.List;\r
12 \r
13 import org.opendaylight.controller.model.api.type.IntegerTypeDefinition;\r
14 import org.opendaylight.controller.model.api.type.RangeConstraint;\r
15 import org.opendaylight.controller.yang.common.QName;\r
16 import org.opendaylight.controller.yang.model.api.SchemaPath;\r
17 import org.opendaylight.controller.yang.model.api.Status;\r
18 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;\r
19 \r
20 public abstract class AbstractInteger implements IntegerTypeDefinition {\r
21 \r
22     private final QName name;\r
23     private final SchemaPath path;\r
24 \r
25     private final String description;\r
26     private final String reference;\r
27 \r
28     private String units = "";\r
29     private final List<RangeConstraint> rangeStatements;\r
30 \r
31     public AbstractInteger(final QName name, final String description,\r
32             final String reference) {\r
33         super();\r
34         this.name = name;\r
35         this.description = description;\r
36         this.reference = reference;\r
37         this.path = BaseTypes.schemaPath(name);\r
38 \r
39         final List<? extends RangeConstraint> emptyContstraints = Collections\r
40                 .emptyList();\r
41         this.rangeStatements = Collections.unmodifiableList(emptyContstraints);\r
42     }\r
43 \r
44     public AbstractInteger(QName name, String description, String reference,\r
45             List<RangeConstraint> rangeStatements) {\r
46         super();\r
47         this.name = name;\r
48         this.description = description;\r
49         this.reference = reference;\r
50         this.rangeStatements = rangeStatements;\r
51         this.path = BaseTypes.schemaPath(name);\r
52     }\r
53 \r
54     public AbstractInteger(QName name, String description, String reference,\r
55             String units) {\r
56         super();\r
57         this.name = name;\r
58         this.description = description;\r
59         this.reference = reference;\r
60         this.units = units;\r
61         this.path = BaseTypes.schemaPath(name);\r
62 \r
63         final List<? extends RangeConstraint> emptyContstraints = Collections\r
64                 .emptyList();\r
65         this.rangeStatements = Collections.unmodifiableList(emptyContstraints);\r
66     }\r
67 \r
68     public AbstractInteger(QName name, String description, String reference,\r
69             String units, List<RangeConstraint> rangeStatements) {\r
70         super();\r
71         this.name = name;\r
72         this.description = description;\r
73         this.reference = reference;\r
74         this.units = units;\r
75         this.rangeStatements = rangeStatements;\r
76         this.path = BaseTypes.schemaPath(name);\r
77     }\r
78 \r
79     @Override\r
80     public String getUnits() {\r
81         return units;\r
82     }\r
83 \r
84     @Override\r
85     public QName getQName() {\r
86         return name;\r
87     }\r
88 \r
89     @Override\r
90     public SchemaPath getPath() {\r
91         return path;\r
92     }\r
93 \r
94     @Override\r
95     public String getDescription() {\r
96         return description;\r
97     }\r
98 \r
99     @Override\r
100     public String getReference() {\r
101         return reference;\r
102     }\r
103 \r
104     @Override\r
105     public Status getStatus() {\r
106         return Status.CURRENT;\r
107     }\r
108 \r
109     @Override\r
110     public List<RangeConstraint> getRangeStatements() {\r
111         return rangeStatements;\r
112     }\r
113 \r
114     @Override\r
115     public List<UnknownSchemaNode> getUnknownSchemaNodes() {\r
116         return Collections.emptyList();\r
117     }\r
118 \r
119     @Override\r
120     public int hashCode() {\r
121         final int prime = 31;\r
122         int result = 1;\r
123         result = prime * result\r
124                 + ((description == null) ? 0 : description.hashCode());\r
125         result = prime * result + ((name == null) ? 0 : name.hashCode());\r
126         result = prime * result + ((path == null) ? 0 : path.hashCode());\r
127         result = prime * result\r
128                 + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());\r
129         result = prime * result\r
130                 + ((reference == null) ? 0 : reference.hashCode());\r
131         result = prime * result + ((units == null) ? 0 : units.hashCode());\r
132         return result;\r
133     }\r
134 \r
135     @Override\r
136     public boolean equals(Object obj) {\r
137         if (this == obj) {\r
138             return true;\r
139         }\r
140         if (obj == null) {\r
141             return false;\r
142         }\r
143         if (getClass() != obj.getClass()) {\r
144             return false;\r
145         }\r
146         AbstractInteger other = (AbstractInteger) obj;\r
147         if (description == null) {\r
148             if (other.description != null) {\r
149                 return false;\r
150             }\r
151         } else if (!description.equals(other.description)) {\r
152             return false;\r
153         }\r
154         if (name == null) {\r
155             if (other.name != null) {\r
156                 return false;\r
157             }\r
158         } else if (!name.equals(other.name)) {\r
159             return false;\r
160         }\r
161         if (path == null) {\r
162             if (other.path != null) {\r
163                 return false;\r
164             }\r
165         } else if (!path.equals(other.path)) {\r
166             return false;\r
167         }\r
168         if (rangeStatements == null) {\r
169             if (other.rangeStatements != null) {\r
170                 return false;\r
171             }\r
172         } else if (!rangeStatements.equals(other.rangeStatements)) {\r
173             return false;\r
174         }\r
175         if (reference == null) {\r
176             if (other.reference != null) {\r
177                 return false;\r
178             }\r
179         } else if (!reference.equals(other.reference)) {\r
180             return false;\r
181         }\r
182         if (units == null) {\r
183             if (other.units != null) {\r
184                 return false;\r
185             }\r
186         } else if (!units.equals(other.units)) {\r
187             return false;\r
188         }\r
189         return true;\r
190     }\r
191 \r
192     @Override\r
193     public String toString() {\r
194         StringBuilder builder = new StringBuilder();\r
195         builder.append("AbstractInteger [name=");\r
196         builder.append(name);\r
197         builder.append(", path=");\r
198         builder.append(path);\r
199         builder.append(", description=");\r
200         builder.append(description);\r
201         builder.append(", reference=");\r
202         builder.append(reference);\r
203         builder.append(", units=");\r
204         builder.append(units);\r
205         builder.append(", rangeStatements=");\r
206         builder.append(rangeStatements);\r
207         builder.append("]");\r
208         return builder.toString();\r
209     }\r
210 }\r