Skip to content

Commit ee5cb76

Browse files
author
George
committed
Add NotNull annotations for add/get/set/remove operations
add override annotations
1 parent 3060c89 commit ee5cb76

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
<scope>test</scope>
3636
<optional>true</optional>
3737
</dependency>
38+
<dependency>
39+
<groupId>org.jetbrains</groupId>
40+
<artifactId>annotations</artifactId>
41+
<version>22.0.0</version>
42+
<scope>compile</scope>
43+
</dependency>
3844
</dependencies>
3945

4046
<build>

src/main/java/gr/geompokon/bitarray/BitArray.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package gr.geompokon.bitarray;
1818

19+
import org.jetbrains.annotations.NotNull;
20+
1921
import java.util.*;
2022

2123
/**
@@ -108,7 +110,7 @@ public BitArray(int initialCapacity) {
108110
* </p>
109111
*
110112
* @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
112114
*/
113115
public BitArray(Collection<? extends Boolean> other) {
114116
Objects.requireNonNull(other);
@@ -146,10 +148,10 @@ private void initMembers(int initialCapacity) {
146148
*
147149
* @param index array index to insert the element in
148150
* @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
150152
*/
151-
public void add(int index, Boolean bit) {
152-
Objects.requireNonNull(bit);
153+
@Override
154+
public void add(int index, @NotNull Boolean bit) {
153155
ensureIndexInRange(index, elements);
154156
modCount++;
155157
ensureCapacity();
@@ -170,14 +172,27 @@ public void add(int index, Boolean bit) {
170172
elements = elements + 1;
171173
}
172174

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+
173187
/**
174188
* Returns the boolean value of the bit at the selected array index.
175189
*
176190
* @param index index of the element in the array
177191
* @return boolean value of the bit entry
178192
* @throws IndexOutOfBoundsException if index is out of array bounds
179193
*/
180-
public Boolean get(int index) {
194+
@Override
195+
public @NotNull Boolean get(int index) {
181196
ensureIndexInRange(index, elements - 1);
182197
// get bit indices
183198
int longIndex = getLongIndex(index);
@@ -193,9 +208,10 @@ public Boolean get(int index) {
193208
* @param index index of the array element to be changed
194209
* @param bit the new value of the array element
195210
* @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
197212
*/
198-
public Boolean set(int index, Boolean bit) {
213+
@Override
214+
public @NotNull Boolean set(int index, @NotNull Boolean bit) {
199215
Objects.requireNonNull(bit);
200216
ensureIndexInRange(index, elements - 1);
201217
// get bit indices
@@ -217,7 +233,8 @@ public Boolean set(int index, Boolean bit) {
217233
* @return boolean value of the removed bit
218234
* @throws IndexOutOfBoundsException if index is out of array bounds
219235
*/
220-
public Boolean remove(int index) {
236+
@Override
237+
public @NotNull Boolean remove(int index) {
221238
ensureIndexInRange(index, elements - 1);
222239
modCount++;
223240

@@ -240,13 +257,15 @@ public Boolean remove(int index) {
240257
*
241258
* @return number of elements in the array
242259
*/
260+
@Override
243261
public int size() {
244262
return elements;
245263
}
246264

247265
/**
248266
* Clears the contents of the array and releases memory used previously.
249267
*/
268+
@Override
250269
public void clear() {
251270
modCount++;
252271
initMembers(DEFAULT_CAPACITY);
@@ -526,6 +545,7 @@ private int longsRequiredForNBits(int nBits) {
526545
*
527546
* @return deep copy of {@code this}
528547
*/
548+
@Override
529549
public BitArray clone() {
530550
return new BitArray(this);
531551
}
@@ -548,6 +568,7 @@ public BitArray clone() {
548568
*
549569
* @return String representation of the array and its elements
550570
*/
571+
@Override
551572
public String toString() {
552573
StringBuilder s = new StringBuilder(this.size() * 2);
553574

0 commit comments

Comments
 (0)