ArrayList.java (addAll(int,Collection)): System.arraycopy all of the remaining elements.
* 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. From-SVN: r51979
This commit is contained in:
parent
0154eaa812
commit
236fc6a041
3 changed files with 28 additions and 5 deletions
|
@ -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>
|
2002-04-05 Mark Wielaard <mark@klomp.org>
|
||||||
|
|
||||||
* java/util/ArrayList.jva (removeRange): If toIndex == fromIndex do
|
* java/util/ArrayList.jva (removeRange): If toIndex == fromIndex do
|
||||||
|
|
|
@ -427,8 +427,8 @@ public class ArrayList extends AbstractList
|
||||||
if (csize + size > data.length)
|
if (csize + size > data.length)
|
||||||
ensureCapacity(size + csize);
|
ensureCapacity(size + csize);
|
||||||
int end = index + csize;
|
int end = index + csize;
|
||||||
if (index != size)
|
if (size > 0 && index != size)
|
||||||
System.arraycopy(data, index, data, end, csize);
|
System.arraycopy(data, index, data, end, size - index);
|
||||||
size += csize;
|
size += csize;
|
||||||
for ( ; index < end; index++)
|
for ( ; index < end; index++)
|
||||||
data[index] = itr.next();
|
data[index] = itr.next();
|
||||||
|
|
|
@ -716,6 +716,9 @@ public class Vector extends AbstractList
|
||||||
*/
|
*/
|
||||||
public synchronized boolean removeAll(Collection c)
|
public synchronized boolean removeAll(Collection c)
|
||||||
{
|
{
|
||||||
|
if (c == null)
|
||||||
|
throw new NullPointerException();
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
for (i = 0; i < elementCount; i++)
|
for (i = 0; i < elementCount; i++)
|
||||||
|
@ -742,6 +745,9 @@ public class Vector extends AbstractList
|
||||||
*/
|
*/
|
||||||
public synchronized boolean retainAll(Collection c)
|
public synchronized boolean retainAll(Collection c)
|
||||||
{
|
{
|
||||||
|
if (c == null)
|
||||||
|
throw new NullPointerException();
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
for (i = 0; i < elementCount; i++)
|
for (i = 0; i < elementCount; i++)
|
||||||
|
@ -779,7 +785,8 @@ public class Vector extends AbstractList
|
||||||
ensureCapacity(elementCount + csize);
|
ensureCapacity(elementCount + csize);
|
||||||
int end = index + csize;
|
int end = index + csize;
|
||||||
if (elementCount > 0 && index != elementCount)
|
if (elementCount > 0 && index != elementCount)
|
||||||
System.arraycopy(elementData, index, elementData, end, csize);
|
System.arraycopy(elementData, index,
|
||||||
|
elementData, end, elementCount - index);
|
||||||
elementCount += csize;
|
elementCount += csize;
|
||||||
for ( ; index < end; index++)
|
for ( ; index < end; index++)
|
||||||
elementData[index] = itr.next();
|
elementData[index] = itr.next();
|
||||||
|
@ -852,23 +859,28 @@ public class Vector extends AbstractList
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a range of elements from this list.
|
* 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 fromIndex the index to start deleting from (inclusive)
|
||||||
* @param toIndex the index to delete up to (exclusive)
|
* @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
|
// This does not need to be synchronized, because it is only called through
|
||||||
// clear() of a sublist, and clear() had already synchronized.
|
// clear() of a sublist, and clear() had already synchronized.
|
||||||
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(elementData, toIndex, elementData, fromIndex,
|
System.arraycopy(elementData, toIndex, elementData, fromIndex,
|
||||||
elementCount - toIndex);
|
elementCount - toIndex);
|
||||||
int save = elementCount;
|
int save = elementCount;
|
||||||
elementCount -= toIndex - fromIndex;
|
elementCount -= change;
|
||||||
Arrays.fill(elementData, elementCount, save, null);
|
Arrays.fill(elementData, elementCount, save, null);
|
||||||
}
|
}
|
||||||
|
else if (change < 0)
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue