AbstractCollection.java (addAll): Use size() instead of hasNext() in iterator loop.

2000-10-29  Bryce McKinlay  <bryce@albatross.co.nz>

	* java/util/AbstractCollection.java (addAll): Use size() instead of
	hasNext() in iterator loop.
	(clear): Ditto.
	(contains): Ditto. Simplify loop.
	(containsAll): Ditto.
	(remove): Ditto.
	(removeAll): Ditto.
	(retainAll): Ditto.
	(toArray): Ditto.
	(toString): Ditto. Use string concatenation operators, not
	StringBuffer.
	* java/util/AbstractList.java (addAll): Use size() instead of
	hasNext() in iterator loop.
	(equals): Ditto.
	(hashCode): Ditto.
	(indexOf): Ditto. Don't take null check outside of the loop.
	(iterator): Return an AbstractListItr instead of anonymous class.
	(lastIndexOf): Use a for loop bounded by size() instead of
	hasPrevious() in iterator loop.
	(listIterator): Return an AbstractListItr.
	(removeRange): Remove bounds checking code and docs.
	(AbstractListItr): New inner class. Code moved here from
	listIterator().
	(SubList.iterator): Removed. Use default implementation from
	AbstractList instead.
	(SubList.listIterator): As above.
	* java/util/AbstractMap.java (clear): Use a for loop bounded by size()
	instead of hasNext() in iterator loop.
	(containsValue): Ditto.
	(equals): Ditto.
	(get): Ditto.
	(put): Ditto.
	(putAll): Ditto.
	(remove): Ditto.
	(toString): Ditto. Use string concatenation operators, not
	StringBuffer.
	* java/util/AbstractSequentialList.java (addAll): Use a for loop
	bounded by size() instead of hasNext() in iterator loop.
	* java/util/AbstractSet.java (hashCode): Don't catch exception as
	part of normal execution flow. Do an explicit null check instead.
	* java/util/ArrayList.java (_iSize): Rename to `size'.
	(_arData): Rename to `data'.
	(get): Check lower bounds also. Simplify IndexOutOfBoundsException
	message.
	(remove): Ditto.
	(removeRange): Make protected. Don't check bounds.
	(add): Check lower bounds also. Simplify IndexOutOfBoundsException
	message.
	(addAll (Collection)): Use a size-bounded for loop instead of hasNext()
	check.
	(addAll (int, Collection)): Check lower bounds. Simplify exception
	string.
	(clone): Clone the data array too.
	(indexOf): Inline doesEqual().
	(lastIndexOf): Ditto.
	(clear): Don't set array data to null.
	(set): Check lower bounds. Simplify exception string.
	(toArray): Correct comment.
	(trimToSize): Don't update modCount, this is not a structural change.
	Add comment.

	* java/util/BitSet.java: Merged with classpath, new JDK 1.2 methods
	implemented.
	(toString): Declare `bit' as long, not int.
	(data): Made package-private, not private.

From-SVN: r37116
This commit is contained in:
Bryce McKinlay 2000-10-29 05:06:10 +00:00 committed by Bryce McKinlay
parent e2d7960734
commit 3a73757880
8 changed files with 980 additions and 892 deletions

View file

@ -1,5 +1,5 @@
/* AbstractSequentialList.java -- List implementation for sequential access
Copyright (C) 1998, 1999 Free Software Foundation, Inc.
Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@ -36,7 +36,8 @@ package java.util;
* Abstract superclass to make it easier to implement the List interface when
* backed by a sequential-access store, such as a linked list.
*/
public abstract class AbstractSequentialList extends AbstractList {
public abstract class AbstractSequentialList extends AbstractList
{
/**
* Returns a ListIterator over the list, starting from position index.
@ -57,27 +58,30 @@ public abstract class AbstractSequentialList extends AbstractList {
* @exception UnsupportedOperationException if the iterator returned by
* listIterator(index) does not support the add method.
*/
public void add(int index, Object o) {
public void add(int index, Object o)
{
ListIterator i = listIterator(index);
i.add(o);
}
public boolean addAll(int index, Collection c) {
boolean changed = false;
public boolean addAll(int index, Collection c)
{
boolean modified = false;
Iterator ci = c.iterator();
int size = c.size();
ListIterator i = listIterator(index);
while (ci.hasNext()) {
i.add(ci.next());
changed = true;
}
return changed;
for (int pos = 0; pos < size; pos++)
{
i.add(ci.next());
}
return (size > 0);
}
public Object get(int index) {
public Object get(int index)
{
ListIterator i = listIterator(index);
if (!i.hasNext()) {
if (index < 0 || index > size())
throw new IndexOutOfBoundsException();
}
return i.next();
}
@ -87,25 +91,26 @@ public abstract class AbstractSequentialList extends AbstractList {
*
* @return an Iterator over this List
*/
public Iterator iterator() {
public Iterator iterator()
{
return listIterator();
}
public Object remove(int index) {
public Object remove(int index)
{
ListIterator i = listIterator(index);
if (!i.hasNext()) {
if (index < 0 || index > size())
throw new IndexOutOfBoundsException();
}
Object removed = i.next();
i.remove();
return removed;
}
public Object set(int index, Object o) {
public Object set(int index, Object o)
{
ListIterator i = listIterator(index);
if (!i.hasNext()) {
if (index < 0 || index > size())
throw new IndexOutOfBoundsException();
}
Object old = i.next();
i.set(o);
return old;