Fixing sonar issues 4
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / BitsType.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.yangtools.yang.model.util;
9
10 import java.util.Collections;
11 import java.util.List;
12
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
15 import org.opendaylight.yangtools.yang.model.api.Status;
16 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
18
19 /**
20  * The <code>default</code> implementation of Bits Type Definition interface.
21  * 
22  * @see BitsTypeDefinition
23  */
24 public final class BitsType implements BitsTypeDefinition {
25     private final QName name = BaseTypes.constructQName("bits");
26     private final SchemaPath path;
27     private final String description = "The bits built-in type represents a bit set.  "
28             + "That is, a bits value is a set of flags identified by small integer position "
29             + "numbers starting at 0.  Each bit number has an assigned name.";
30
31     private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.7";
32     private final BitsTypeDefinition baseType;
33     private final List<Bit> bits;
34     private static final String UNITS = "";
35
36     /**
37      * Default constructor. <br>
38      * Instantiates Bits type as empty bits list.
39      * 
40      * @param path
41      */
42     public BitsType(final SchemaPath path) {
43         super();
44         this.bits = Collections.emptyList();
45         this.path = path;
46         this.baseType = this;
47     }
48
49     /**
50      * Constructor with explicit definition of bits assigned to BitsType.
51      * 
52      * @param path
53      * @param bits
54      */
55     public BitsType(final SchemaPath path, final List<Bit> bits) {
56         super();
57         this.bits = Collections.unmodifiableList(bits);
58         this.path = path;
59         this.baseType = this;
60     }
61
62     /*
63      * (non-Javadoc)
64      * 
65      * @see
66      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
67      */
68     @Override
69     public BitsTypeDefinition getBaseType() {
70         return baseType;
71     }
72
73     /*
74      * (non-Javadoc)
75      * 
76      * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
77      */
78     @Override
79     public String getUnits() {
80         return UNITS;
81     }
82
83     /*
84      * (non-Javadoc)
85      * 
86      * @see
87      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
88      * ()
89      */
90     @Override
91     public Object getDefaultValue() {
92         return bits;
93     }
94
95     /*
96      * (non-Javadoc)
97      * 
98      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
99      */
100     @Override
101     public QName getQName() {
102         return name;
103     }
104
105     /*
106      * (non-Javadoc)
107      * 
108      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
109      */
110     @Override
111     public SchemaPath getPath() {
112         return path;
113     }
114
115     /*
116      * (non-Javadoc)
117      * 
118      * @see
119      * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
120      */
121     @Override
122     public String getDescription() {
123         return description;
124     }
125
126     /*
127      * (non-Javadoc)
128      * 
129      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
130      */
131     @Override
132     public String getReference() {
133         return REFERENCE;
134     }
135
136     /*
137      * (non-Javadoc)
138      * 
139      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
140      */
141     @Override
142     public Status getStatus() {
143         return Status.CURRENT;
144     }
145
146     @Override
147     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
148         return Collections.emptyList();
149     }
150
151     @Override
152     public List<Bit> getBits() {
153         return bits;
154     }
155
156     @Override
157     public int hashCode() {
158         final int prime = 31;
159         int result = 1;
160         result = prime * result + ((bits == null) ? 0 : bits.hashCode());
161         result = prime * result + ((description == null) ? 0 : description.hashCode());
162         result = prime * result + ((name == null) ? 0 : name.hashCode());
163         result = prime * result + ((path == null) ? 0 : path.hashCode());
164         return result;
165     }
166
167     @Override
168     public boolean equals(Object obj) {
169         if (this == obj) {
170             return true;
171         }
172         if (obj == null) {
173             return false;
174         }
175         if (getClass() != obj.getClass()) {
176             return false;
177         }
178         BitsType other = (BitsType) obj;
179         if (bits == null) {
180             if (other.bits != null) {
181                 return false;
182             }
183         } else if (!bits.equals(other.bits)) {
184             return false;
185         }
186         if (description == null) {
187             if (other.description != null) {
188                 return false;
189             }
190         } else if (!description.equals(other.description)) {
191             return false;
192         }
193         if (name == null) {
194             if (other.name != null) {
195                 return false;
196             }
197         } else if (!name.equals(other.name)) {
198             return false;
199         }
200         if (path == null) {
201             if (other.path != null) {
202                 return false;
203             }
204         } else if (!path.equals(other.path)) {
205             return false;
206         }
207         return true;
208     }
209
210     @Override
211     public String toString() {
212         StringBuilder builder = new StringBuilder();
213         builder.append("BitsType [name=");
214         builder.append(name);
215         builder.append(", path=");
216         builder.append(path);
217         builder.append(", description=");
218         builder.append(description);
219         builder.append(", reference=");
220         builder.append(REFERENCE);
221         builder.append(", bits=");
222         builder.append(bits);
223         builder.append(", units=");
224         builder.append(UNITS);
225         builder.append("]");
226         return builder.toString();
227     }
228 }