diff options
author | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-04-06 08:26:08 +0000 |
---|---|---|
committer | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-04-06 08:26:08 +0000 |
commit | 6f29a6e64648fe98e92714b75aa43e6fff2f172b (patch) | |
tree | dad90f94b7bb393dc0e6e3971b7076615caeb073 /libjava/java/util/ArrayList.java | |
parent | adcdc3d78a8e3aec137eaf696d5dce89877cbe8b (diff) | |
download | ppe42-gcc-6f29a6e64648fe98e92714b75aa43e6fff2f172b.tar.gz ppe42-gcc-6f29a6e64648fe98e92714b75aa43e6fff2f172b.zip |
* java/util/ArrayList.jva (removeRange): If toIndex == fromIndex do
nothing, if toIndex < fromIndex throw IndexOutIfBoundsException.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@51947 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/util/ArrayList.java')
-rw-r--r-- | libjava/java/util/ArrayList.java | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/libjava/java/util/ArrayList.java b/libjava/java/util/ArrayList.java index 34dc48ac179..59ce974b18f 100644 --- a/libjava/java/util/ArrayList.java +++ b/libjava/java/util/ArrayList.java @@ -437,19 +437,23 @@ public class ArrayList extends AbstractList /** * 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 toIndex one greater than the last index which will be removed + * @throws IndexOutOfBoundsException if fromIndex > toIndex */ protected void removeRange(int fromIndex, int toIndex) { - if (fromIndex != toIndex) + int change = toIndex - fromIndex; + if (change > 0) { modCount++; System.arraycopy(data, toIndex, data, fromIndex, size - toIndex); - size -= toIndex - fromIndex; + size -= change; } + else if (change < 0) + throw new IndexOutOfBoundsException(); } /** |