0cda67c27fe2cf7158c8561bdb44281fb1f24b48
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / yang / model / util / BooleanType.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.UnknownSchemaNode;
17 import org.opendaylight.controller.yang.model.api.type.BooleanTypeDefinition;
18
19 /**
20  * The <code>default</code> implementation of Boolean Type Definition interface.
21  *
22  * @see BooleanTypeDefinition
23  */
24 public final class BooleanType implements BooleanTypeDefinition {
25
26     private final QName name = BaseTypes.constructQName("boolean");
27     private final SchemaPath path;
28     private final String description = "The boolean built-in type represents a boolean value.";
29     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.5";
30     private final BooleanTypeDefinition baseType;
31     private final Boolean defaultValue;
32     private String units = "";
33
34     /**
35      * Default constructor with default value set to "false".
36      */
37     private BooleanType() {
38         super();
39         this.defaultValue = false;
40         this.path = BaseTypes.schemaPath(name);
41         this.baseType = this;
42     }
43
44     public BooleanType(final SchemaPath path) {
45         super();
46         this.defaultValue = false;
47         this.path = path;
48         this.baseType = new BooleanType();
49     }
50
51     /**
52      * Boolean Type constructor.
53      *
54      * @param defaultValue
55      *            Default Value
56      */
57     public BooleanType(final SchemaPath path, final Boolean defaultValue) {
58         super();
59         this.defaultValue = defaultValue;
60         this.path = path;
61         this.baseType = new BooleanType();
62     }
63
64     /**
65      * Boolean Type constructor.
66      *
67      * @param defaultValue
68      *            Default Value
69      * @param units
70      *            Units
71      */
72     public BooleanType(final SchemaPath path, final Boolean defaultValue, final String units) {
73         super();
74         this.defaultValue = defaultValue;
75         this.units = units;
76         this.path = path;
77         this.baseType = new BooleanType();
78     }
79
80     /*
81      * (non-Javadoc)
82      *
83      * @see
84      * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
85      */
86     @Override
87     public BooleanTypeDefinition getBaseType() {
88         return baseType;
89     }
90
91     /*
92      * (non-Javadoc)
93      *
94      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
95      */
96     @Override
97     public String getUnits() {
98         return units;
99     }
100
101     /*
102      * (non-Javadoc)
103      *
104      * @see
105      * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
106      * ()
107      */
108     @Override
109     public Object getDefaultValue() {
110         return defaultValue;
111     }
112
113     /*
114      * (non-Javadoc)
115      *
116      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
117      */
118     @Override
119     public QName getQName() {
120         return name;
121     }
122
123     /*
124      * (non-Javadoc)
125      *
126      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
127      */
128     @Override
129     public SchemaPath getPath() {
130         return path;
131     }
132
133     /*
134      * (non-Javadoc)
135      *
136      * @see
137      * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
138      */
139     @Override
140     public String getDescription() {
141         return description;
142     }
143
144     /*
145      * (non-Javadoc)
146      *
147      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
148      */
149     @Override
150     public String getReference() {
151         return reference;
152     }
153
154     /*
155      * (non-Javadoc)
156      *
157      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
158      */
159     @Override
160     public Status getStatus() {
161         return Status.CURRENT;
162     }
163
164     @Override
165     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
166         return Collections.emptyList();
167     }
168
169     @Override
170     public int hashCode() {
171         final int prime = 31;
172         int result = 1;
173         result = prime * result
174                 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
175         result = prime * result
176                 + ((description == null) ? 0 : description.hashCode());
177         result = prime * result + ((name == null) ? 0 : name.hashCode());
178         result = prime * result + ((path == null) ? 0 : path.hashCode());
179         result = prime * result
180                 + ((reference == null) ? 0 : reference.hashCode());
181         result = prime * result + ((units == null) ? 0 : units.hashCode());
182         return result;
183     }
184
185     @Override
186     public boolean equals(Object obj) {
187         if (this == obj) {
188             return true;
189         }
190         if (obj == null) {
191             return false;
192         }
193         if (getClass() != obj.getClass()) {
194             return false;
195         }
196         BooleanType other = (BooleanType) obj;
197         if (defaultValue == null) {
198             if (other.defaultValue != null) {
199                 return false;
200             }
201         } else if (!defaultValue.equals(other.defaultValue)) {
202             return false;
203         }
204         if (description == null) {
205             if (other.description != null) {
206                 return false;
207             }
208         } else if (!description.equals(other.description)) {
209             return false;
210         }
211         if (name == null) {
212             if (other.name != null) {
213                 return false;
214             }
215         } else if (!name.equals(other.name)) {
216             return false;
217         }
218         if (path == null) {
219             if (other.path != null) {
220                 return false;
221             }
222         } else if (!path.equals(other.path)) {
223             return false;
224         }
225         if (reference == null) {
226             if (other.reference != null) {
227                 return false;
228             }
229         } else if (!reference.equals(other.reference)) {
230             return false;
231         }
232         if (units == null) {
233             if (other.units != null) {
234                 return false;
235             }
236         } else if (!units.equals(other.units)) {
237             return false;
238         }
239         return true;
240     }
241
242     @Override
243     public String toString() {
244         StringBuilder builder = new StringBuilder();
245         builder.append("BooleanType [name=");
246         builder.append(name);
247         builder.append(", path=");
248         builder.append(path);
249         builder.append(", description=");
250         builder.append(description);
251         builder.append(", reference=");
252         builder.append(reference);
253         builder.append(", defaultValue=");
254         builder.append(defaultValue);
255         builder.append(", units=");
256         builder.append(units);
257         builder.append("]");
258         return builder.toString();
259     }
260 }