Skip to content

Commit c43b32a

Browse files
moved StringArguments.checkBounds to a static method in Arguments
1 parent 644705c commit c43b32a

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/main/java/com/datasiqn/commandcore/argument/Arguments.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,15 @@ public interface Arguments {
5050
* @return The newly created {@code ArgumentReader}
5151
*/
5252
@NotNull ArgumentReader asReader();
53+
54+
/**
55+
* Checks if {@code i} is smaller than {@code size} and at least 0
56+
* @param i The number to check
57+
* @param size The total size
58+
* @throws IndexOutOfBoundsException If {@code i} >= {@code size} or {@code i} < 0
59+
*/
60+
static void checkBounds(int i, int size) {
61+
if (i >= size) throw new IndexOutOfBoundsException("index (" + i + ") is greater than total size (" + size + ")");
62+
if (i < 0) throw new IndexOutOfBoundsException("index cannot be negative");
63+
}
5364
}

src/main/java/com/datasiqn/commandcore/argument/StringArguments.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ public int size() {
2929

3030
@Override
3131
public @NotNull <T> Result<T, String> getChecked(int i, @NotNull ArgumentType<T> type) {
32-
checkBounds(i);
32+
Arguments.checkBounds(i, size());
3333
return type.parse(new StringArgumentReader(allArguments.get(i)));
3434
}
3535

3636
@Override
3737
public @NotNull String getString(int i) {
38-
checkBounds(i);
38+
Arguments.checkBounds(i, size());
3939
return allArguments.get(i);
4040
}
4141

@@ -44,8 +44,4 @@ public int size() {
4444
return new StringArgumentReader(stringArguments);
4545
}
4646

47-
private void checkBounds(int i) {
48-
if (i >= size()) throw new IndexOutOfBoundsException("index (" + i + ") is greater than total size (" + size() + ")");
49-
if (i < 0) throw new IndexOutOfBoundsException("index cannot be negative");
50-
}
5147
}

0 commit comments

Comments
 (0)