16
16
17
17
package gr .geompokon .bitarray ;
18
18
19
+ import org .jetbrains .annotations .NotNull ;
20
+
19
21
import java .util .*;
20
22
21
23
/**
@@ -108,7 +110,7 @@ public BitArray(int initialCapacity) {
108
110
* </p>
109
111
*
110
112
* @param other the collection supplying the elements
111
- * @throws java.lang. NullPointerException if the collection is null
113
+ * @throws NullPointerException if the collection is null
112
114
*/
113
115
public BitArray (Collection <? extends Boolean > other ) {
114
116
Objects .requireNonNull (other );
@@ -146,10 +148,10 @@ private void initMembers(int initialCapacity) {
146
148
*
147
149
* @param index array index to insert the element in
148
150
* @param bit the boolean value to be inserted
149
- * @throws java.lang. IndexOutOfBoundsException if index is out of array insertion bounds
151
+ * @throws IndexOutOfBoundsException if index is out of array insertion bounds
150
152
*/
151
- public void add ( int index , Boolean bit ) {
152
- Objects . requireNonNull ( bit );
153
+ @ Override
154
+ public void add ( int index , @ NotNull Boolean bit ) {
153
155
ensureIndexInRange (index , elements );
154
156
modCount ++;
155
157
ensureCapacity ();
@@ -170,14 +172,27 @@ public void add(int index, Boolean bit) {
170
172
elements = elements + 1 ;
171
173
}
172
174
175
+ /**
176
+ * Inserts the boolean value as a bit at the tail of the array
177
+ *
178
+ * @param bit the boolean value to be inserted
179
+ * @return success / failure of the add operation
180
+ */
181
+ @ Override
182
+ public boolean add (@ NotNull Boolean bit ) {
183
+ add (elements , bit );
184
+ return true ;
185
+ }
186
+
173
187
/**
174
188
* Returns the boolean value of the bit at the selected array index.
175
189
*
176
190
* @param index index of the element in the array
177
191
* @return boolean value of the bit entry
178
192
* @throws IndexOutOfBoundsException if index is out of array bounds
179
193
*/
180
- public Boolean get (int index ) {
194
+ @ Override
195
+ public @ NotNull Boolean get (int index ) {
181
196
ensureIndexInRange (index , elements - 1 );
182
197
// get bit indices
183
198
int longIndex = getLongIndex (index );
@@ -193,9 +208,10 @@ public Boolean get(int index) {
193
208
* @param index index of the array element to be changed
194
209
* @param bit the new value of the array element
195
210
* @return boolean value of the previous bit at that index
196
- * @throws java.lang. IndexOutOfBoundsException if index is out of array bounds
211
+ * @throws IndexOutOfBoundsException if index is out of array bounds
197
212
*/
198
- public Boolean set (int index , Boolean bit ) {
213
+ @ Override
214
+ public @ NotNull Boolean set (int index , @ NotNull Boolean bit ) {
199
215
Objects .requireNonNull (bit );
200
216
ensureIndexInRange (index , elements - 1 );
201
217
// get bit indices
@@ -217,7 +233,8 @@ public Boolean set(int index, Boolean bit) {
217
233
* @return boolean value of the removed bit
218
234
* @throws IndexOutOfBoundsException if index is out of array bounds
219
235
*/
220
- public Boolean remove (int index ) {
236
+ @ Override
237
+ public @ NotNull Boolean remove (int index ) {
221
238
ensureIndexInRange (index , elements - 1 );
222
239
modCount ++;
223
240
@@ -240,13 +257,15 @@ public Boolean remove(int index) {
240
257
*
241
258
* @return number of elements in the array
242
259
*/
260
+ @ Override
243
261
public int size () {
244
262
return elements ;
245
263
}
246
264
247
265
/**
248
266
* Clears the contents of the array and releases memory used previously.
249
267
*/
268
+ @ Override
250
269
public void clear () {
251
270
modCount ++;
252
271
initMembers (DEFAULT_CAPACITY );
@@ -526,6 +545,7 @@ private int longsRequiredForNBits(int nBits) {
526
545
*
527
546
* @return deep copy of {@code this}
528
547
*/
548
+ @ Override
529
549
public BitArray clone () {
530
550
return new BitArray (this );
531
551
}
@@ -548,6 +568,7 @@ public BitArray clone() {
548
568
*
549
569
* @return String representation of the array and its elements
550
570
*/
571
+ @ Override
551
572
public String toString () {
552
573
StringBuilder s = new StringBuilder (this .size () * 2 );
553
574
0 commit comments