Merge "Fix for messags at the boot up time This commit proposes following two sets...
[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 class BooleanType implements BooleanTypeDefinition {
25
26     private final QName name = BaseTypes.constructQName("boolean");
27     private final SchemaPath path = BaseTypes.schemaPath(name);
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
31     private final Boolean defaultValue;
32     private String units = "";
33
34     /**
35      * Default constructor with default value set to "false".
36      */
37     public BooleanType() {
38         super();
39         defaultValue = false;
40     }
41
42     /**
43      * Boolean Type constructor.
44      * 
45      * @param defaultValue Default Value
46      */
47     public BooleanType(final Boolean defaultValue) {
48         super();
49         this.defaultValue = defaultValue;
50     }
51
52     /**
53      * Boolean Type constructor.
54      * 
55      * @param defaultValue Default Value
56      * @param units Units
57      */
58     public BooleanType(final Boolean defaultValue, final String units) {
59         super();
60         this.defaultValue = defaultValue;
61         this.units = units;
62     }
63
64     /*
65      * (non-Javadoc)
66      * 
67      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
68      */
69     @Override
70     public BooleanTypeDefinition getBaseType() {
71         return this;
72     }
73
74     /*
75      * (non-Javadoc)
76      * 
77      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
78      */
79     @Override
80     public String getUnits() {
81         return units;
82     }
83
84     /*
85      * (non-Javadoc)
86      * 
87      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
88      */
89     @Override
90     public Object getDefaultValue() {
91         return defaultValue;
92     }
93
94     /*
95      * (non-Javadoc)
96      * 
97      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
98      */
99     @Override
100     public QName getQName() {
101         return name;
102     }
103
104     /*
105      * (non-Javadoc)
106      * 
107      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
108      */
109     @Override
110     public SchemaPath getPath() {
111         return path;
112     }
113
114     /*
115      * (non-Javadoc)
116      * 
117      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
118      */
119     @Override
120     public String getDescription() {
121         return description;
122     }
123
124     /*
125      * (non-Javadoc)
126      * 
127      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
128      */
129     @Override
130     public String getReference() {
131         return reference;
132     }
133
134     /*
135      * (non-Javadoc)
136      * 
137      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
138      */
139     @Override
140     public Status getStatus() {
141         return Status.CURRENT;
142     }
143
144     @Override
145     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
146         return Collections.emptyList();
147     }
148
149     @Override
150     public int hashCode() {
151         final int prime = 31;
152         int result = 1;
153         result = prime * result
154                 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
155         result = prime * result
156                 + ((description == null) ? 0 : description.hashCode());
157         result = prime * result + ((name == null) ? 0 : name.hashCode());
158         result = prime * result + ((path == null) ? 0 : path.hashCode());
159         result = prime * result
160                 + ((reference == null) ? 0 : reference.hashCode());
161         result = prime * result + ((units == null) ? 0 : units.hashCode());
162         return result;
163     }
164
165     @Override
166     public boolean equals(Object obj) {
167         if (this == obj) {
168             return true;
169         }
170         if (obj == null) {
171             return false;
172         }
173         if (getClass() != obj.getClass()) {
174             return false;
175         }
176         BooleanType other = (BooleanType) obj;
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 (name == null) {
192             if (other.name != null) {
193                 return false;
194             }
195         } else if (!name.equals(other.name)) {
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 (units == null) {
213             if (other.units != null) {
214                 return false;
215             }
216         } else if (!units.equals(other.units)) {
217             return false;
218         }
219         return true;
220     }
221
222     @Override
223     public String toString() {
224         StringBuilder builder = new StringBuilder();
225         builder.append("BooleanType [name=");
226         builder.append(name);
227         builder.append(", path=");
228         builder.append(path);
229         builder.append(", description=");
230         builder.append(description);
231         builder.append(", reference=");
232         builder.append(reference);
233         builder.append(", defaultValue=");
234         builder.append(defaultValue);
235         builder.append(", units=");
236         builder.append(units);
237         builder.append("]");
238         return builder.toString();
239     }
240 }