diff options
author | Bryce McKinlay <bryce@albatross.co.nz> | 2000-11-27 08:30:26 +0000 |
---|---|---|
committer | Bryce McKinlay <bryce@gcc.gnu.org> | 2000-11-27 08:30:26 +0000 |
commit | f24dbacf8520934c43f67f24acbfdc6540688a67 (patch) | |
tree | b0e987ae6c453d2859183427b6ec7482250e8054 /libjava/java/util/ArrayList.java | |
parent | 27e2564ac886bee1a7552df98dcab17a4bf06e26 (diff) | |
download | gcc-f24dbacf8520934c43f67f24acbfdc6540688a67.tar.gz |
Vector.java (ensureCapacity): Don't increment modCount.
2000-11-27 Bryce McKinlay <bryce@albatross.co.nz>
* 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
Diffstat (limited to 'libjava/java/util/ArrayList.java')
-rw-r--r-- | libjava/java/util/ArrayList.java | 11 |
1 files changed, 7 insertions, 4 deletions
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); |