diff options
author | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-04-07 07:40:49 +0000 |
---|---|---|
committer | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-04-07 07:40:49 +0000 |
commit | 3e14667ce50c402688128b3ac1f9d6ec688cbe62 (patch) | |
tree | efc2dd6dee0958f9f023d37fda7c28d454cb8596 | |
parent | 242fc35cceaa8f16b20e10b03da279fc04794ee5 (diff) | |
download | gcc-3e14667ce50c402688128b3ac1f9d6ec688cbe62.tar.gz |
* java/util/ArrayList.java (addAll(int,Collection)): System.arraycopy
all of the remaining elements.
* java/util/Vector.java (addAll(int,Collection)): Likewise.
(removeRange): If toIndex == fromIndex do
nothing, if toIndex < fromIndex throw IndexOutIfBoundsException.
(removeAll): Always throw NullPointerException when collection is
null.
(retrainAll): Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@51979 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | libjava/ChangeLog | 11 | ||||
-rw-r--r-- | libjava/java/util/ArrayList.java | 4 | ||||
-rw-r--r-- | libjava/java/util/Vector.java | 18 |
3 files changed, 28 insertions, 5 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index a48ba515750..5ef858c631f 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,14 @@ +2002-04-06 Mark Wielaard <mark@klomp.org> + + * java/util/ArrayList.java (addAll(int,Collection)): System.arraycopy + all of the remaining elements. + * java/util/Vector.java (addAll(int,Collection)): Likewise. + (removeRange): If toIndex == fromIndex do + nothing, if toIndex < fromIndex throw IndexOutIfBoundsException. + (removeAll): Always throw NullPointerException when collection is + null. + (retrainAll): Likewise. + 2002-04-05 Mark Wielaard <mark@klomp.org> * java/util/ArrayList.jva (removeRange): If toIndex == fromIndex do diff --git a/libjava/java/util/ArrayList.java b/libjava/java/util/ArrayList.java index 59ce974b18f..99745d0f648 100644 --- a/libjava/java/util/ArrayList.java +++ b/libjava/java/util/ArrayList.java @@ -427,8 +427,8 @@ public class ArrayList extends AbstractList if (csize + size > data.length) ensureCapacity(size + csize); int end = index + csize; - if (index != size) - System.arraycopy(data, index, data, end, csize); + if (size > 0 && index != size) + System.arraycopy(data, index, data, end, size - index); size += csize; for ( ; index < end; index++) data[index] = itr.next(); diff --git a/libjava/java/util/Vector.java b/libjava/java/util/Vector.java index e8d1c96ad01..9cf8639fc3b 100644 --- a/libjava/java/util/Vector.java +++ b/libjava/java/util/Vector.java @@ -716,6 +716,9 @@ public class Vector extends AbstractList */ public synchronized boolean removeAll(Collection c) { + if (c == null) + throw new NullPointerException(); + int i; int j; for (i = 0; i < elementCount; i++) @@ -742,6 +745,9 @@ public class Vector extends AbstractList */ public synchronized boolean retainAll(Collection c) { + if (c == null) + throw new NullPointerException(); + int i; int j; for (i = 0; i < elementCount; i++) @@ -779,7 +785,8 @@ public class Vector extends AbstractList ensureCapacity(elementCount + csize); int end = index + csize; if (elementCount > 0 && index != elementCount) - System.arraycopy(elementData, index, elementData, end, csize); + System.arraycopy(elementData, index, + elementData, end, elementCount - index); elementCount += csize; for ( ; index < end; index++) elementData[index] = itr.next(); @@ -852,23 +859,28 @@ public class Vector extends AbstractList /** * Removes a range of elements from this list. + * Does nothing when toIndex is equal to fromIndex. * * @param fromIndex the index to start deleting from (inclusive) * @param toIndex the index to delete up to (exclusive) + * @throws IndexOutOfBoundsException if fromIndex > toIndex */ // This does not need to be synchronized, because it is only called through // clear() of a sublist, and clear() had already synchronized. protected void removeRange(int fromIndex, int toIndex) { - if (fromIndex != toIndex) + int change = toIndex - fromIndex; + if (change > 0) { modCount++; System.arraycopy(elementData, toIndex, elementData, fromIndex, elementCount - toIndex); int save = elementCount; - elementCount -= toIndex - fromIndex; + elementCount -= change; Arrays.fill(elementData, elementCount, save, null); } + else if (change < 0) + throw new IndexOutOfBoundsException(); } /** |