Skip to content

Commit

Permalink
Update checkPositionIndices
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed Nov 19, 2024
1 parent 1e89629 commit b5a0ad3
Showing 1 changed file with 1 addition and 28 deletions.
29 changes: 1 addition & 28 deletions kala-base/src/main/java/kala/Conditions.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,7 @@ private static void checkPositionIndexFailed(int index, int size) {
public static void checkPositionIndices(int beginIndex, int endIndex,
@Range(from = 0, to = Integer.MAX_VALUE) int size)
throws IndexOutOfBoundsException, IllegalArgumentException {
if (beginIndex < 0 || beginIndex > endIndex || endIndex > size) {
// Optimized for execution by hotspot
checkPositionIndicesFailed(beginIndex, endIndex, size);
}
}

@Contract("_, _, _ -> fail")
private static void checkPositionIndicesFailed(int beginIndex, int endIndex, int size) {
if (size < 0) {
throw new IllegalArgumentException("size(" + size + ") < 0");
}
if (beginIndex < 0) {
throw new IndexOutOfBoundsException("beginIndex(" + beginIndex + ") < 0");
}
if (beginIndex > size) {
throw new IndexOutOfBoundsException("beginIndex(" + beginIndex + ") > size(" + size + ")");
}
if (endIndex < 0) {
throw new IndexOutOfBoundsException("endIndex(" + endIndex + ") < 0");
}
if (endIndex > size) {
throw new IndexOutOfBoundsException("endIndex(" + endIndex + ") > size(" + size + ")");
}
if (beginIndex > endIndex) {
throw new IndexOutOfBoundsException("beginIndex(" + beginIndex + ") > endIndex(" + endIndex + ")");
}

throw new AssertionError("checkPositionIndicesFailed");
Objects.checkFromToIndex(beginIndex, endIndex, size);
}

//region Equals
Expand Down

0 comments on commit b5a0ad3

Please sign in to comment.