Added error checks.

This commit is contained in:
Pétur Ingi Egilsson 2015-03-20 21:31:49 +01:00
parent 8f96e8b592
commit bae2ba5e3e
1 changed files with 7 additions and 6 deletions

View File

@ -29,6 +29,7 @@
*/
package org.antlr.v4.runtime.misc;
import java.lang.IllegalArgumentException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@ -57,6 +58,8 @@ public class IntegerList {
if (capacity < 0) {
throw new IllegalArgumentException();
}
if (capacity > MAX_ARRAY_SIZE)
throw new IllegalArgumentException();
if (capacity == 0) {
_data = EMPTY_DATA;
@ -100,13 +103,9 @@ public class IntegerList {
public final void addAll(Collection<Integer> list) {
ensureCapacity(_size + list.size());
int current = 0;
for (int x : list) {
_data[_size + current] = x;
current++;
}
_size += list.size();
_data[_size++] = x;
}
}
public final int get(int index) {
@ -268,6 +267,8 @@ public class IntegerList {
if (fromIndex < 0 || toIndex < 0 || fromIndex > _size || toIndex > _size) {
throw new IndexOutOfBoundsException();
}
if (fromIndex > toIndex)
throw new IllegalArgumentException();
return Arrays.binarySearch(_data, fromIndex, toIndex, key);
}