File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed
src/main/java/com/datasiqn/commandcore/argument Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -50,4 +50,15 @@ public interface Arguments {
50
50
* @return The newly created {@code ArgumentReader}
51
51
*/
52
52
@ 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
+ }
53
64
}
Original file line number Diff line number Diff line change @@ -29,13 +29,13 @@ public int size() {
29
29
30
30
@ Override
31
31
public @ NotNull <T > Result <T , String > getChecked (int i , @ NotNull ArgumentType <T > type ) {
32
- checkBounds (i );
32
+ Arguments . checkBounds (i , size () );
33
33
return type .parse (new StringArgumentReader (allArguments .get (i )));
34
34
}
35
35
36
36
@ Override
37
37
public @ NotNull String getString (int i ) {
38
- checkBounds (i );
38
+ Arguments . checkBounds (i , size () );
39
39
return allArguments .get (i );
40
40
}
41
41
@@ -44,8 +44,4 @@ public int size() {
44
44
return new StringArgumentReader (stringArguments );
45
45
}
46
46
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
- }
51
47
}
You can’t perform that action at this time.
0 commit comments