use fromIndex and toIndex for remove instead of from and length
The new API is consistent with the internal API of ArrayList.
This commit is contained in:
@@ -198,31 +198,31 @@ public class IntList implements Serializable, Cloneable {
|
||||
/**
|
||||
* Removes elements from the list.
|
||||
*
|
||||
* @param from
|
||||
* @param fromIndex
|
||||
* index of the first element to remove
|
||||
* @param length
|
||||
* number of elements to remove
|
||||
* @param toIndex
|
||||
* the index of the last element to remove (exclusive)
|
||||
* @throws IndexOutOfBoundsException
|
||||
* if {@code from} or {@code length} is negative, or if the range
|
||||
* defined by {@code from} and {@code length} is out of bounds
|
||||
* if {@code fromIndex} or {@code toIndex} is negative, or if the
|
||||
* range defined by {@code fromIndex} and {@code toIndex} is out of
|
||||
* bounds
|
||||
*/
|
||||
public void remove(final int from, final int length) {
|
||||
public void remove(final int fromIndex, final int toIndex) {
|
||||
|
||||
if (from < 0) {
|
||||
throw new IndexOutOfBoundsException("from must not be negative, but was: " + from);
|
||||
if (fromIndex < 0) {
|
||||
throw new IndexOutOfBoundsException("from must not be negative, but was: " + fromIndex);
|
||||
}
|
||||
if (length < 0) {
|
||||
throw new IndexOutOfBoundsException("length must not be negative, but was: " + length);
|
||||
if (toIndex < fromIndex) {
|
||||
throw new IndexOutOfBoundsException("toIndex must not be smaller than fromIndex, but was: " + toIndex);
|
||||
}
|
||||
if (from + length > index) {
|
||||
throw new IndexOutOfBoundsException("from: " + from + " length: " + length);
|
||||
if (toIndex > index) {
|
||||
throw new IndexOutOfBoundsException("from: " + fromIndex + " toIndex: " + toIndex);
|
||||
}
|
||||
|
||||
final int[] newData = new int[data.length];
|
||||
System.arraycopy(data, 0, newData, 0, from);
|
||||
System.arraycopy(data, from + length, newData, from, data.length - from - length);
|
||||
data = newData;
|
||||
index -= length;
|
||||
final int numRemoved = index - toIndex;
|
||||
System.arraycopy(data, toIndex, data, fromIndex, numRemoved);
|
||||
|
||||
index = index - (toIndex - fromIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user