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