ArrayList.jva (removeRange): If toIndex == fromIndex do nothing...
* java/util/ArrayList.jva (removeRange): If toIndex == fromIndex do nothing, if toIndex < fromIndex throw IndexOutIfBoundsException. From-SVN: r51947
This commit is contained in:
parent
392fc5b068
commit
8e9603b0c2
2 changed files with 12 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2002-04-05 Mark Wielaard <mark@klomp.org>
|
||||||
|
|
||||||
|
* java/util/ArrayList.jva (removeRange): If toIndex == fromIndex do
|
||||||
|
nothing, if toIndex < fromIndex throw IndexOutIfBoundsException.
|
||||||
|
|
||||||
2002-04-05 Adam Megacz <adam@xwt.org>
|
2002-04-05 Adam Megacz <adam@xwt.org>
|
||||||
|
|
||||||
* exception.cc (abort): added static modifier
|
* exception.cc (abort): added static modifier
|
||||||
|
|
|
@ -437,19 +437,23 @@ public class ArrayList extends AbstractList
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all elements in the half-open interval [fromIndex, toIndex).
|
* Removes all elements in the half-open interval [fromIndex, toIndex).
|
||||||
* You asked for it if you call this with invalid arguments.
|
* Does nothing when toIndex is equal to fromIndex.
|
||||||
*
|
*
|
||||||
* @param fromIndex the first index which will be removed
|
* @param fromIndex the first index which will be removed
|
||||||
* @param toIndex one greater than the last index which will be removed
|
* @param toIndex one greater than the last index which will be removed
|
||||||
|
* @throws IndexOutOfBoundsException if fromIndex > toIndex
|
||||||
*/
|
*/
|
||||||
protected void removeRange(int fromIndex, int toIndex)
|
protected void removeRange(int fromIndex, int toIndex)
|
||||||
{
|
{
|
||||||
if (fromIndex != toIndex)
|
int change = toIndex - fromIndex;
|
||||||
|
if (change > 0)
|
||||||
{
|
{
|
||||||
modCount++;
|
modCount++;
|
||||||
System.arraycopy(data, toIndex, data, fromIndex, size - toIndex);
|
System.arraycopy(data, toIndex, data, fromIndex, size - toIndex);
|
||||||
size -= toIndex - fromIndex;
|
size -= change;
|
||||||
}
|
}
|
||||||
|
else if (change < 0)
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue