AbstractList.java: Throw messages with IndexOutOfBoundsExceptions.
2000-11-02 Bryce McKinlay <bryce@albatross.co.nz> * java/util/AbstractList.java: Throw messages with IndexOutOfBoundsExceptions. (listIterator()): Call listIterator(0). (size): New field. Initialize to size(). (hasNext): Test position against size, not size(). (remove): Increment knownMod by one instead of resetting it from modCount. (add): Ditto. (SubList.upMod): Removed. (SubList.set): Don't call upMod() or update knownMod. (SubList.add(int,Object)): Increment modCount instead of calling upMod(). (SubList.remove): Ditto. (SubList.addAll): Don't call backingList.size(). Increment size from c.size(). (SubList.iterator): New method. Call listIterator(0). (SubList.listIterator): New method. Restore code to return an anonymous listIterator implementation (with some changes). * java/util/AbstractSequentialList.java: Throw messages with IndexOutOfBoundsExceptions. (addAll): Add a specnote. * java/util/ArrayList.java (removeRange): Get the math right. (addAll): Increment modCount _before_ creating iterator. * java/util/LinkedList.java: Rewritten, mostly. From-SVN: r37203
This commit is contained in:
parent
17e2e7f92d
commit
7177dab5c9
5 changed files with 660 additions and 455 deletions
|
@ -43,7 +43,7 @@ import java.io.ObjectStreamField;
|
|||
* to or removing from the end of a list, checking the size, &c.
|
||||
*
|
||||
* @author Jon A. Zeppieri
|
||||
* @version $Id: ArrayList.java,v 1.6 2000/10/26 10:19:00 bryce Exp $
|
||||
* @version $Id: ArrayList.java,v 1.2 2000/10/29 05:06:10 bryce Exp $
|
||||
* @see java.util.AbstractList
|
||||
* @see java.util.List
|
||||
*/
|
||||
|
@ -187,7 +187,7 @@ public class ArrayList extends AbstractList
|
|||
if (fromIndex != toIndex)
|
||||
{
|
||||
System.arraycopy(data, toIndex, data, fromIndex, size - toIndex);
|
||||
size -= (fromIndex - toIndex);
|
||||
size -= (toIndex - fromIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,9 +219,9 @@ public class ArrayList extends AbstractList
|
|||
*/
|
||||
public boolean addAll(Collection c)
|
||||
{
|
||||
modCount++;
|
||||
Iterator itr = c.iterator();
|
||||
int csize = c.size();
|
||||
modCount++;
|
||||
ensureCapacity(size + csize);
|
||||
for (int pos = 0; pos < csize; pos++)
|
||||
{
|
||||
|
@ -240,13 +240,13 @@ public class ArrayList extends AbstractList
|
|||
*/
|
||||
public boolean addAll(int index, Collection c)
|
||||
{
|
||||
Iterator itr = c.iterator();
|
||||
int csize = c.size();
|
||||
|
||||
modCount++;
|
||||
if (index < 0 || index > size)
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size:" +
|
||||
size);
|
||||
modCount++;
|
||||
Iterator itr = c.iterator();
|
||||
int csize = c.size();
|
||||
|
||||
ensureCapacity(size + csize);
|
||||
int end = index + csize;
|
||||
if (size > 0 && index != size)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue