Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Peugnet <nicolas.peugnet@lip6.fr>2024-01-11 16:44:03 +0300
committerNicolas Peugnet <nicolas.peugnet@lip6.fr>2024-01-11 16:44:03 +0300
commite2d6310591f4547fb1602d8d1511db505cd7fccc (patch)
treea5d7eecbf42ff2d3d417a8442aa4c6085ae05db0
parent2ddc4865c03e35a67e57dab6614b668e46ce0099 (diff)
Finish cleanup of WhipserTargetList
- throw IndexOutOfBoundsException instead of IllegalArgumentException as it seems more appropriate. - also throw in get when trying to access out of bounds elements to be more consistent with free. - simply set the bitset to 0 in clear, setting the first and last bits to one was useless as the rest of the logic already took care of these cases
-rw-r--r--src/main/java/se/lublin/humla/model/WhisperTargetList.java11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/main/java/se/lublin/humla/model/WhisperTargetList.java b/src/main/java/se/lublin/humla/model/WhisperTargetList.java
index 172999a..ae76454 100644
--- a/src/main/java/se/lublin/humla/model/WhisperTargetList.java
+++ b/src/main/java/se/lublin/humla/model/WhisperTargetList.java
@@ -57,21 +57,25 @@ public class WhisperTargetList {
}
public WhisperTarget get(byte id) {
+ if (id < TARGET_MIN || id > TARGET_MAX)
+ throw new IndexOutOfBoundsException();
+
if ((mTakenIds & (1 << id)) == 0)
return null;
+
return mActiveTargets[id - TARGET_MIN];
}
public void free(byte slot) {
if (slot < TARGET_MIN || slot > TARGET_MAX)
- throw new IllegalArgumentException();
+ throw new IndexOutOfBoundsException();
mTakenIds &= ~(1 << slot);
}
public int spaceRemaining() {
int counter = 0;
- for (byte i = TARGET_MIN; i < TARGET_MAX; i++) {
+ for (byte i = TARGET_MIN; i <= TARGET_MAX; i++) {
if ((mTakenIds & (1 << i)) == 0) {
counter++;
}
@@ -80,7 +84,6 @@ public class WhisperTargetList {
}
public void clear() {
- // Slots 0 and 31 are non-whisper targets.
- mTakenIds = 1 | (1 << 31);
+ mTakenIds = 0;
}
}