From 7177dab5c931138c85a1762acc54fd53880f4933 Mon Sep 17 00:00:00 2001 From: Bryce McKinlay Date: Thu, 2 Nov 2000 10:08:03 +0000 Subject: AbstractList.java: Throw messages with IndexOutOfBoundsExceptions. 2000-11-02 Bryce McKinlay * 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 --- libjava/java/util/ArrayList.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'libjava/java/util/ArrayList.java') diff --git a/libjava/java/util/ArrayList.java b/libjava/java/util/ArrayList.java index 75d4b406b66..084084cff3d 100644 --- a/libjava/java/util/ArrayList.java +++ b/libjava/java/util/ArrayList.java @@ -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) -- cgit v1.2.3