From f24dbacf8520934c43f67f24acbfdc6540688a67 Mon Sep 17 00:00:00 2001 From: Bryce McKinlay Date: Mon, 27 Nov 2000 08:30:26 +0000 Subject: Vector.java (ensureCapacity): Don't increment modCount. 2000-11-27 Bryce McKinlay * java/util/Vector.java (ensureCapacity): Don't increment modCount. (addElement): Don't increment elementCount twice. Doh. * java/util/ArrayList.java (add): Only call ensureCapacity if the array needs to be expanded. (addAll): Ditto. * java/util/Collections.java (UnmodifiableCollection): Implement toString(). (UnmodifiableList): Throw UnsupportedOperationException from modification methods. Set `l' from the one-parameter constructor. (UnmodifiableMap): Implement toString(). (SynchronizedCollection): Ditto. (SynchronizedList): Set `l' from the one-parameter constructor. (SynchronizedSortedSet): Set `ss' from the one-parameter constructor. (SynchronizedMap): Implement toString(). From-SVN: r37785 --- libjava/java/util/ArrayList.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'libjava/java/util/ArrayList.java') diff --git a/libjava/java/util/ArrayList.java b/libjava/java/util/ArrayList.java index ef7d6e5f7d3..d440cdaec52 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.3 2000/11/02 10:08:03 bryce Exp $ + * @version $Id: ArrayList.java,v 1.4 2000/11/22 11:59:59 bryce Exp $ * @see java.util.AbstractList * @see java.util.List */ @@ -127,7 +127,8 @@ public class ArrayList extends AbstractList public boolean add(Object e) { modCount++; - ensureCapacity(size + 1); + if (size == data.length) + ensureCapacity(size + 1); data[size++] = e; return true; } @@ -204,7 +205,8 @@ public class ArrayList extends AbstractList if (index < 0 || index > size) throw new IndexOutOfBoundsException("Index: " + index + ", Size:" + size); - ensureCapacity(size + 1); + if (size == data.length) + ensureCapacity(size + 1); if (index != size) System.arraycopy(data, index, data, index + 1, size - index); data[index] = e; @@ -239,7 +241,8 @@ public class ArrayList extends AbstractList Iterator itr = c.iterator(); int csize = c.size(); - ensureCapacity(size + csize); + if (csize + size > data.length) + ensureCapacity(size + csize); int end = index + csize; if (size > 0 && index != size) System.arraycopy(data, index, data, end, csize); -- cgit v1.2.1