Skip to content

Commit

Permalink
close #66: Improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed Feb 17, 2023
1 parent 2c0bbb5 commit e7244f6
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,8 @@ public final class Mutable${Type}ArrayList extends AbstractMutable${Type}List im

@Override
public void insert(int index, ${PrimitiveType} value) {
int size = this.size;
if (index < 0 || index > size) {
throw new IndexOutOfBoundsException();
}
Conditions.checkPositionIndex(index, size);

if (index == size) {
append(value);
return;
Expand Down
2 changes: 1 addition & 1 deletion kala-collection/src/main/java/kala/collection/SeqLike.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ default E elementAt(int index) {
@Flow(sourceIsContainer = true)
default E get(@Range(from = 0, to = Integer.MAX_VALUE) int index) {
Iterator<E> it = iterator(index);
if (!it.hasNext()) throw new IndexOutOfBoundsException();
if (!it.hasNext()) throw new IndexOutOfBoundsException("Index: " + index);

return it.next();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public int size() {

@Override
public E get(int index) {
throw new IndexOutOfBoundsException();
throw new IndexOutOfBoundsException("Index: " + index);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public int size() {

@Override
public Object get(int index) {
throw new IndexOutOfBoundsException();
throw new IndexOutOfBoundsException("Index: " + index);
}

@Override
Expand Down Expand Up @@ -202,7 +202,7 @@ public E get(int index) {
try {
return (E) prefix1[index];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IndexOutOfBoundsException();
throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,8 @@ public void sort(Comparator<? super E> comparator) {

@Override
public void insert(int index, E value) {
int size = this.size;
if (index < 0 || index > size) {
throw new IndexOutOfBoundsException();
}
Conditions.checkPositionIndex(index, size);

if (index == size) {
append(value);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,8 @@ public int getIndex(Node<E> node) {

@Override
public E get(int index) {
if (index < 0 || index >= len) {
throw new IndexOutOfBoundsException();
}
Conditions.checkElementIndex(index, len);

return internalGetNode(index).value;
}

Expand Down

0 comments on commit e7244f6

Please sign in to comment.