Commit d9fd7154 by Bryce McKinlay

Collections drop from Classpath:

2001-12-15  Bryce McKinlay  <bryce@waitaki.otago.ac.nz>

	* java/util/BitSet.java (and): Fix off-by-one bug, don't skip part of
	the bitset.
	(andNot): Likewise.
	(xor): Likewise.

2001-12-15  Bryce McKinlay  <bryce@waitaki.otago.ac.nz>

	* java/util/LinkedList.java (LinkedListItr.add): Don't skip the next
	entry.

2001-12-15  Eric Blake  <ebb9@email.byu.edu>

	* java/util/TreeMap.java (removeNode): Fix bug in node removal.

2001-12-15  Bryce McKinlay  <bryce@waitaki.otago.ac.nz>

	* java/util/AbstractCollection.java (containsAll): Use size of the
	correct collection for loop bound.
	* java/util/AbstractList.java (iterator.next): Increment pos after
	calling get on backing list.
	(listIterator.next): Likewise.
	* java/util/LinkedList.java (addLastEntry): Don't increment size before
	checking for size == 0.
	(addFirstEntry): Rearrange to match addLastEntry.
	(add): Do not increment size before inserting the new entry.

	* java/util/AbstractCollection.java (addAll): Use size of the
	correct collection for loop bound.

2001-12-15  Bryce McKinlay  <bryce@waitaki.otago.ac.nz>

	* java/util/AbstractSet.java (removeAll): Fix scoping thinko.
	* java/util/HashMap.java (putAllInternal): Set size here.
	* java/util/Hashtable.java (putAllInternal): New method. Copy contents
	of a map efficiently without calling put() or putAll().
	(Hashtable (map)): Use putAllInternal.
	(clone): Likewise.

2001-12-15  Eric Blake  <ebb9@email.byu.edu>

	* java/util/Collections.java:
	* java/util/Vector.java:
	* java/util/WeakHashMap.java: Fix spelling errors.

2001-12-15  Eric Blake  <ebb9@email.byu.edu>

	* java/util/AbstractCollection.java (removeAllInternal),
	(retainAllInternal): Add hooks for use by ArrayList.
	* java/util/AbstractList.java: Minor code updates. Fix some
	scoping.
	* java/util/AbstractMap.java: ditto
	* java/util/ArrayList.java (readObject, writeObject): ditto
	(removeAllInternal, retainAllInternal): Optimize.
	* java/util/Arrays.java: ditto
	* java/util/Collections.java: ditto. Change order of parameters
	to equals(Object, Object) to match specs.
	* java/util/Dictionary.java: Improve javadoc.
	(Dictionary): Add explicit constructor.
	* java/util/HashMap.java: Improve javadoc. Rearrange methods to
	follow order in JDK. Cleanups related to recent code migration to
	AbstractMap. Fix some scoping.
	(entrySet): Cache the result.
	(modCount): Ensure that this is updated correctly.
	* java/util/HashSet.java: Improve javadoc. Fix some scoping.
	(init): Add hooks for LinkedHashSet.
	(map): Use "" instead of Boolean.TRUE in backing map. Use
	package-private API where possible for less overhead.
	(readObject, writeObject): Fix serialization.
	* java/util/Hashtable.java: Improve javadoc. Fix some scoping.
	(entrySet, keySet, values): Cache the result.
	(modCount): Ensure that this is updated correctly.
	(contains, remove): Fix NullPointer checking to match specs.
	(class Enumeration): Make more like HashIterator.
	* java/util/IdentityHashMap.java: Minor code updates.
	(modCount): Ensure that this is updated correctly.
	(readObject, writeObject): Fix serialization.
	* java/util/LinkedHashMap.java: Minor code updates. Cleanups
	related to recent code migration to AbstractMap.
	* java/util/LinkedHashSet.java: New file.
	* java/util/LinkedList.java:
	(readObject, writeObject): Fix serialization.
	* java/util/Makefile.am: List recently added files.
	* java/util/Stack.java: Minor code updates.
	* java/util/TreeMap.java: Improve javadoc. Overhaul the class to
	be more efficient. Fix some scoping. Rearrange the methods.
	(nil): Ensure that this can be thread-safe, and make it a static
	final. Initialize it to be more useful as a sentinal node.
	(Node): Specify color in constructor.
	(deleteFixup, insertFixup): Improve comments and algorithm.
	(fabricateTree): Redesign with less overhead.
	(lowestGreaterThan): Add parameter first to make SubMap easier.
	(removeNode): Patch hole where nil was being modified. Choose
	predecessor instead of successor so in-place swap works.
	(class VerifyResult, verifyTree, verifySub, verifyError): Remove
	this dead code after verifying the class works.
	(class SubMap): Rewrite several algorithms to avoid problems with
	comparing nil.
	* java/util/TreeSet.java: Improve javadoc. Fix some scoping.
	(clone): Fix ClassCastException when cloning subSet().
	(readObject, writeObject): Fix serialization.
	* java/util/WeakHashMap.java: Improve javadoc. Fix some scoping.
	(NULL_KEY): Make it compare as null, for ease elsewhere.
	(Class WeakEntry): Rename from Entry, to avoid shadowing
	Map.Entry. Add missing toString.
	(modCount): Ensure that this is updated correctly.
	(clear, containsValue, keySet, putAll, values, WeakHashMap(Map)):
	Add missing methods and constructor.

2001-12-15  Eric Blake  <ebb9@email.byu.edu>

	* java/util/ArrayList.java (checkBoundExclusive),
	(checkBoundInclusive): Rename from range??clusive, to match
	AbstractList.
	* java/util/LinkedList.java (checkBoundsExclusive),
	(checkBoundsInclusive): ditto
	* java/util/Vector.java (checkBoundExclusive),
	(checkBoundInclusive): Move bounds checking into common methods.

2001-12-15  Eric Blake  <ebb9@email.byu.edu>

	* java/util/AbstractList.java:
	(modCount): Make sure it is updated in all needed places.
	* java/util/ArrayList.java: Improve javadoc. Implements
	RandomAccess. Add serialVersionUID. Reorder methods.
	(modCount): Make sure it is updated in all needed places.
	(rangeExclusive, rangeInclusive): Add common methods for bounds
	check.
	(isEmpty): Add missing method.
	* java/util/Collections.java: (class SynchronizedList): Make
	package visible.
	* java/util/ConcurrentModificationException.java: Improve
	javadoc.
	* java/util/EmptyStackException.java: Improve javadoc.
	* java/util/LinkedList.java: Improve javadoc.
	(modCount): Make sure it is updated in all needed places.
	(rangeExclusive, rangeInclusive): Add common methods for bounds
	check.
	* java/util/NoSuchElementException.java: Improve javadoc.
	* java/util/Stack.java: Improve javadoc. Fix synchronization
	issues.
	(modCount): Make sure it is updated in all needed places.
	* java/util/Vector.java: Improve javadoc. Fix synchronization
	issues. Implements RandomAccess. Reorder methods.
	(modCount): Make sure it is updated in all needed places.
	(setSize): Fix according to specifications: this does not dictate
	the backing array size.
	(removeAll, retainAll): Faster implementations.

2001-12-15  Eric Blake  <ebb9@email.byu.edu>

	* java/util/BitSet.java: Improve javadoc.
	(cardinality(), clear(), clear(int, int), flip(int)),
	(flip(int, int), get(int, int), intersects(BitSet), isEmpty()),
	(nextClearBit(int), nextSetBit(int), set(int, boolean)),
	(set(int, int), set(int, int, boolean)): Add new JDK 1.4 methods.
	(clone): Fix so subclasses clone correctly.

2001-12-15  Eric Blake  <ebb9@email.byu.edu>

	* java/util/AbstractCollection.java: Improve javadoc.
	(AbstractCollection()): Make constructor protected.
	(equals(Object, Object), hashCode(Object)): Add utility methods.
	* java/util/AbstractList.java: Improve javadoc.
	(AbstractList()): Make constructor protected.
	(indexOf(Object)): Call listIterator(), not listIterator(int).
	(iterator()): Follow Sun's requirement to not use listIterator(0).
	(listIterator(int)): Make AbstractListItr anonymous.
	(subList(int, int)): Add support for RandomAccess.
	(SubList.add(int, Object), SubList.remove(Object)): Fix bug with
	modCount tracking.
	(SubList.addAll(Collection)): Add missing method.
	(SubList.listIterator(int)): Fix bugs in indexing, modCount
	tracking.
	(class RandomAccessSubList): Add new class.
	* java/util/AbstractMap.java: Improve javadoc.
	(keys, values, KEYS, VALUES, ENTRIES): Consolidate common map
	fields.
	(AbstractMap()): Make constructor protected.
	(equals(Object, Object), hashCode(Object)): Add utility methods.
	(equals(Object)): Change algorithm to
	entrySet().equals(m.entrySet()), as documented by Sun.
	(keySet(), values()): Cache the collections.
	* java/util/AbstractSequentialList.java: Improve javadoc.
	(AbstractSequentialList()): Make constructor protected.
	* java/util/AbstractSet.java: Improve javadoc.
	(AbstractSet()): Make constructor protected.
	(removeAll(Collection)): Add missing method.
	* java/util/Arrays.java: Improve javadoc, rearrange method orders.
	(defaultComparator): Remove, in favor of
	Collections.compare(Object, Object, Comparator).
	(binarySearch, equals, sort): Fix natural order comparison of
	floats and doubles. Also improve Object comparison - when
	comparator is null, use natural order.
	(fill, sort): Add missing checks for IllegalArgumentException.
	(sort, qsort): Fix sorting bugs, rework the code for more
	legibility.
	(mergeSort): Inline into sort(Object[], int, int, Comparator).
	(class ArrayList): Rename from ListImpl, and make compatible with
	JDK serialization. Add methods which more efficiently override
	those of AbstractList.
	* java/util/Collections: Improve javadoc.
	(isSequential(List)): Add and use a method for deciding between
	RandomAccess and sequential algorithms on lists.
	(class Empty*, class Synchronized*, class Unmodifiable*): Make
	compliant with JDK serializability.
	(class Singleton*, class CopiesList, class RevereseComparator),
	(class UnmodifiableMap.UnmodifiableEntrySet),
	(class *RandomAccessList): New classes for serial compatibility.
	(class Empty*, class Singleton*, class CopiesList): Add methods
	which more efficiently override those of Abstract*.
	(search): Inline into binarySearch(List, Object, Comparator).
	(binarySearch): Make sequential search only do log(n) comparisons,
	instead of n.
	(copy(List, List)): Do bounds checking before starting.
	(indexOfSubList, lastIndexOfSubList, list, replaceAll, rotate),
	(swap):	Add new JDK 1.4 methods.
	(binarySearch, max, min, sort): Allow null comparator to represent
	natural ordering.
	(reverse(List)): Avoid unnecessary swap.
	(shuffle(List, Random)): Do shuffle in-place for RandomAccess
	lists.
	(SingletonList.get): Fix logic bug.
	(SingletonMap.entrySet): Make the entry immutable, and cache the
	returned set.
	(SynchronizedCollection, SynchronizedMap, UnmodifiableCollection),
	(UnmodifiableMap): Detect null pointer in construction.
	(SynchronizedMap, UnmodifiableMap): Cache collection views.
	* java/util/BasicMapEntry: Improve javadoc.

From-SVN: r48035
parent def9790d
......@@ -1200,6 +1200,7 @@ java/util/IdentityHashMap.java \
java/util/Iterator.java \
java/util/LinkedList.java \
java/util/LinkedHashMap.java \
java/util/LinkedHashSet.java \
java/util/List.java \
java/util/ListIterator.java \
java/util/ListResourceBundle.java \
......
......@@ -123,19 +123,13 @@ libgcj_basedir = @libgcj_basedir@
mkinstalldirs = @mkinstalldirs@
AUTOMAKE_OPTIONS = foreign
@TESTSUBDIR_TRUE@SUBDIRS = \
@TESTSUBDIR_TRUE@$(DIRLTDL) testsuite gcj include
@TESTSUBDIR_FALSE@SUBDIRS = \
@TESTSUBDIR_FALSE@$(DIRLTDL) gcj include
@USE_LIBDIR_TRUE@toolexeclibdir = \
@USE_LIBDIR_TRUE@$(libdir)$(MULTISUBDIR)
@USE_LIBDIR_FALSE@toolexeclibdir = \
@USE_LIBDIR_FALSE@$(toolexecdir)/lib$(MULTISUBDIR)
@USE_LIBDIR_FALSE@toolexecdir = \
@USE_LIBDIR_FALSE@$(exec_prefix)/$(target_alias)
@XLIB_AWT_TRUE@cond_x_ltlibrary = \
@XLIB_AWT_TRUE@libgcjx.la
@XLIB_AWT_FALSE@cond_x_ltlibrary = \
@TESTSUBDIR_TRUE@SUBDIRS = @TESTSUBDIR_TRUE@$(DIRLTDL) testsuite gcj include
@TESTSUBDIR_FALSE@SUBDIRS = @TESTSUBDIR_FALSE@$(DIRLTDL) gcj include
@USE_LIBDIR_TRUE@toolexeclibdir = @USE_LIBDIR_TRUE@$(libdir)$(MULTISUBDIR)
@USE_LIBDIR_FALSE@toolexeclibdir = @USE_LIBDIR_FALSE@$(toolexecdir)/lib$(MULTISUBDIR)
@USE_LIBDIR_FALSE@toolexecdir = @USE_LIBDIR_FALSE@$(exec_prefix)/$(target_alias)
@XLIB_AWT_TRUE@cond_x_ltlibrary = @XLIB_AWT_TRUE@libgcjx.la
@XLIB_AWT_FALSE@cond_x_ltlibrary =
toolexeclib_LTLIBRARIES = libgcj.la $(cond_x_ltlibrary)
toolexeclib_DATA = libgcj.spec
......@@ -143,20 +137,14 @@ data_DATA = libgcj.jar
secdir = $(libdir)/security
@NATIVE_TRUE@bin_PROGRAMS = \
@NATIVE_TRUE@jv-convert gij rmic rmiregistry
@NATIVE_TRUE@bin_PROGRAMS = @NATIVE_TRUE@jv-convert gij rmic rmiregistry
bin_SCRIPTS = addr2name.awk
@CANADIAN_TRUE@@NULL_TARGET_TRUE@ZIP = \
@CANADIAN_TRUE@@NULL_TARGET_TRUE@$(MULTIBUILDTOP)../$(COMPPATH)/fastjar/jar$(EXEEXT)
@CANADIAN_TRUE@@NULL_TARGET_FALSE@ZIP = \
@CANADIAN_TRUE@@NULL_TARGET_FALSE@jar
@CANADIAN_FALSE@ZIP = \
@CANADIAN_FALSE@$(MULTIBUILDTOP)../$(COMPPATH)/fastjar/jar$(EXEEXT)
@CANADIAN_TRUE@GCJH = \
@CANADIAN_TRUE@gcjh
@CANADIAN_FALSE@GCJH = \
@CANADIAN_FALSE@$(MULTIBUILDTOP)../$(COMPPATH)/gcc/gcjh$(EXEEXT)
@CANADIAN_TRUE@@NULL_TARGET_TRUE@ZIP = @CANADIAN_TRUE@@NULL_TARGET_TRUE@$(MULTIBUILDTOP)../$(COMPPATH)/fastjar/jar$(EXEEXT)
@CANADIAN_TRUE@@NULL_TARGET_FALSE@ZIP = @CANADIAN_TRUE@@NULL_TARGET_FALSE@jar
@CANADIAN_FALSE@ZIP = @CANADIAN_FALSE@$(MULTIBUILDTOP)../$(COMPPATH)/fastjar/jar$(EXEEXT)
@CANADIAN_TRUE@GCJH = @CANADIAN_TRUE@gcjh
@CANADIAN_FALSE@GCJH = @CANADIAN_FALSE@$(MULTIBUILDTOP)../$(COMPPATH)/gcc/gcjh$(EXEEXT)
GCJ_WITH_FLAGS = $(GCJ) --encoding=UTF-8
......@@ -176,10 +164,8 @@ AM_CXXFLAGS = -fno-rtti -fnon-call-exceptions \
@LIBGCJ_CXXFLAGS@ @X_CFLAGS@ $(WARNINGS) -D_GNU_SOURCE \
-DPREFIX="\"$(prefix)\""
@USING_GCC_TRUE@AM_CFLAGS = \
@USING_GCC_TRUE@@LIBGCJ_CFLAGS@ $(WARNINGS)
@USING_GCC_FALSE@AM_CFLAGS = \
@USING_GCC_FALSE@@LIBGCJ_CFLAGS@
@USING_GCC_TRUE@AM_CFLAGS = @USING_GCC_TRUE@@LIBGCJ_CFLAGS@ $(WARNINGS)
@USING_GCC_FALSE@AM_CFLAGS = @USING_GCC_FALSE@@LIBGCJ_CFLAGS@
JCFLAGS = -g
JC1FLAGS = @LIBGCJ_JAVAFLAGS@ $(GCJFLAGS)
......@@ -252,8 +238,7 @@ extra_headers = java/lang/Object.h java/lang/Class.h
NM = nm
@NATIVE_TRUE@@MAINTAINER_MODE_TRUE@noinst_PROGRAMS = \
@NATIVE_TRUE@@MAINTAINER_MODE_TRUE@gen-from-JIS
@NATIVE_TRUE@@MAINTAINER_MODE_TRUE@noinst_PROGRAMS = @NATIVE_TRUE@@MAINTAINER_MODE_TRUE@gen-from-JIS
CONVERT_DIR = gnu/gcj/convert
......@@ -950,6 +935,7 @@ java/util/IdentityHashMap.java \
java/util/Iterator.java \
java/util/LinkedList.java \
java/util/LinkedHashMap.java \
java/util/LinkedHashSet.java \
java/util/List.java \
java/util/ListIterator.java \
java/util/ListResourceBundle.java \
......@@ -1585,7 +1571,7 @@ libgcj-test.spec.in libgcj.spec.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
TAR = gtar
GZIP_ENV = --best
DIST_SUBDIRS = @DIRLTDL@ testsuite gcj include @DIRLTDL@ gcj include
DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
......@@ -2224,10 +2210,11 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
.deps/java/util/GregorianCalendar.P .deps/java/util/HashMap.P \
.deps/java/util/HashSet.P .deps/java/util/Hashtable.P \
.deps/java/util/IdentityHashMap.P .deps/java/util/Iterator.P \
.deps/java/util/LinkedHashMap.P .deps/java/util/LinkedList.P \
.deps/java/util/List.P .deps/java/util/ListIterator.P \
.deps/java/util/ListResourceBundle.P .deps/java/util/Locale.P \
.deps/java/util/Map.P .deps/java/util/MissingResourceException.P \
.deps/java/util/LinkedHashMap.P .deps/java/util/LinkedHashSet.P \
.deps/java/util/LinkedList.P .deps/java/util/List.P \
.deps/java/util/ListIterator.P .deps/java/util/ListResourceBundle.P \
.deps/java/util/Locale.P .deps/java/util/Map.P \
.deps/java/util/MissingResourceException.P \
.deps/java/util/NoSuchElementException.P .deps/java/util/Observable.P \
.deps/java/util/Observer.P .deps/java/util/Properties.P \
.deps/java/util/PropertyPermission.P \
......@@ -2735,7 +2722,7 @@ distdir: $(DISTFILES)
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$/$$file $(distdir)/$$file; \
cp -pr $$d/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
......
/* AbstractSequentialList.java -- List implementation for sequential access
Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
......@@ -25,100 +25,192 @@ This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
// TO DO:
// ~ Lots of doc comments still missing.
// ~ The class comment should include a description of what should be overridden
// to provide what features, as should the listIterator comment.
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.
* backed by a sequential-access store, such as a linked list. For random
* access data, use AbstractList. This class implements the random access
* methods (<code>get</code>, <code>set</code>, <code>add</code>, and
* <code>remove</code>) atop the list iterator, opposite of AbstractList's
* approach of implementing the iterator atop random access.
* <p>
*
* To implement a list, you need an implementation for <code>size()</code>
* and <code>listIterator</code>. With just <code>hasNext</code>,
* <code>next</code>, <code>hasPrevious</code>, <code>previous</code>,
* <code>nextIndex</code>, and <code>previousIndex</code>, you have an
* unmodifiable list. For a modifiable one, add <code>set</code>, and for
* a variable-size list, add <code>add</code> and <code>remove</code>.
* <p>
*
* The programmer should provide a no-argument constructor, and one that
* accepts another Collection, as recommended by the Collection interface.
* Unfortunately, there is no way to enforce this in Java.
*
* @author Original author unknown
* @author Bryce McKinlay
* @author Eric Blake <ebb9@email.byu.edu>
* @see Collection
* @see List
* @see AbstractList
* @see AbstractCollection
* @see ListIterator
* @see LinkedList
* @since 1.2
* @status updated to 1.4
*/
public abstract class AbstractSequentialList extends AbstractList
{
/**
* The main constructor, for use by subclasses.
*/
protected AbstractSequentialList()
{
}
/**
* Returns a ListIterator over the list, starting from position index.
* Subclasses must provide an implementation of this method.
*
* @exception IndexOutOfBoundsException if index < 0 || index > size()
* @param index the starting position of the list
* @return the list iterator
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; size()
*/
public abstract ListIterator listIterator(int index);
/**
* Add an element to the list at a given index. This implementation obtains a
* ListIterator positioned at the specified index, and then adds the element
* using the ListIterator's add method.
* Insert an element into the list at a given position (optional operation).
* This shifts all existing elements from that position to the end one
* index to the right. This version of add has no return, since it is
* assumed to always succeed if there is no exception. This iteration
* uses listIterator(index).add(o).
*
* @param index the position to add the element
* @param o the element to insert
* @exception IndexOutOfBoundsException if index < 0 || index > size()
* @exception UnsupportedOperationException if the iterator returned by
* listIterator(index) does not support the add method.
* @param index the location to insert the item
* @param o the object to insert
* @throws UnsupportedOperationException if this list does not support the
* add operation
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; size()
* @throws ClassCastException if o cannot be added to this list due to its
* type
* @throws IllegalArgumentException if o cannot be added to this list for
* some other reason
*/
public void add(int index, Object o)
{
ListIterator i = listIterator(index);
i.add(o);
listIterator(index).add(o);
}
/**
* @specnote The spec in the JDK1.3 online docs is wrong. The implementation
* should not call next() to skip over new elements as they are
* added, because iterator.add() should add new elements BEFORE
* the cursor.
* Insert the contents of a collection into the list at a given position
* (optional operation). Shift all elements at that position to the right
* by the number of elements inserted. This operation is undefined if
* this list is modified during the operation (for example, if you try
* to insert a list into itself).
* <p>
*
* This implementation grabs listIterator(index), then proceeds to use add
* for each element returned by c's iterator. Sun's online specs are wrong,
* claiming that this also calls next(): listIterator.add() correctly
* skips the added element.
*
* @param index the location to insert the collection
* @param c the collection to insert
* @return true if the list was modified by this action, that is, if c is
* non-empty
* @throws UnsupportedOperationException if this list does not support the
* addAll operation
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; size()
* @throws ClassCastException if some element of c cannot be added to this
* list due to its type
* @throws IllegalArgumentException if some element of c cannot be added
* to this list for some other reason
* @throws NullPointerException if the specified collection is null
* @see #add(int, Object)
*/
public boolean addAll(int index, Collection c)
{
boolean modified = false;
Iterator ci = c.iterator();
int size = c.size();
ListIterator i = listIterator(index);
for (int pos = 0; pos < size; pos++)
{
i.add(ci.next());
}
return (size > 0);
for (int pos = size; pos > 0; pos--)
i.add(ci.next());
return size > 0;
}
/**
* Get the element at a given index in this list. This implementation
* returns listIterator(index).next().
*
* @param index the index of the element to be returned
* @return the element at index index in this list
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
*/
public Object get(int index)
{
ListIterator i = listIterator(index);
if (index < 0 || index > size())
throw new IndexOutOfBoundsException("Index: " + index + ", Size:" +
size());
return i.next();
// This is a legal listIterator position, but an illegal get.
if (index == size())
throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
+ size());
return listIterator(index).next();
}
/**
* Return an Iterator over this List. This implementation returns
* listIterator().
* Obtain an Iterator over this list, whose sequence is the list order. This
* implementation returns listIterator().
*
* @return an Iterator over this List
* @return an Iterator over the elements of this list, in order
*/
public Iterator iterator()
{
return listIterator();
}
/**
* Remove the element at a given position in this list (optional operation).
* Shifts all remaining elements to the left to fill the gap. This
* implementation uses listIterator(index) and ListIterator.remove().
*
* @param index the position within the list of the object to remove
* @return the object that was removed
* @throws UnsupportedOperationException if this list does not support the
* remove operation
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
*/
public Object remove(int index)
{
// This is a legal listIterator position, but an illegal remove.
if (index == size())
throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
+ size());
ListIterator i = listIterator(index);
if (index < 0 || index > size())
throw new IndexOutOfBoundsException("Index: " + index + ", Size:" +
size());
Object removed = i.next();
i.remove();
return removed;
}
/**
* Replace an element of this list with another object (optional operation).
* This implementation uses listIterator(index) and ListIterator.set(o).
*
* @param index the position within this list of the element to be replaced
* @param o the object to replace it with
* @return the object that was replaced
* @throws UnsupportedOperationException if this list does not support the
* set operation
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
* @throws ClassCastException if o cannot be added to this list due to its
* type
* @throws IllegalArgumentException if o cannot be added to this list for
* some other reason
*/
public Object set(int index, Object o)
{
// This is a legal listIterator position, but an illegal set.
if (index == size())
throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
+ size());
ListIterator i = listIterator(index);
if (index < 0 || index > size())
throw new IndexOutOfBoundsException("Index: " + index + ", Size:" +
size());
Object old = i.next();
i.set(o);
return old;
......
/* AbstractSet.java -- Abstract implementation of most of Set
Copyright (C) 1998, 2000 Free Software Foundation, Inc.
Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
......@@ -35,10 +35,28 @@ package java.util;
* on them - specifically, no element may be in the set more than once). This
* class simply provides implementations of equals() and hashCode() to fulfil
* the requirements placed on them by the Set interface.
*
* @author Original author unknown
* @author Eric Blake <ebb9@email.byu.edu>
* @see Collection
* @see AbstractCollection
* @see Set
* @see HashSet
* @see TreeSet
* @see LinkedHashSet
* @since 1.2
* @status updated to 1.4
*/
public abstract class AbstractSet extends AbstractCollection implements Set
{
/**
* The main constructor, for use by subclasses.
*/
protected AbstractSet()
{
}
/**
* Tests whether the given object is equal to this Set. This implementation
* first checks whether this set <em>is</em> the given object, and returns
* true if so. Otherwise, if o is a Set and is the same size as this one, it
......@@ -50,12 +68,9 @@ public abstract class AbstractSet extends AbstractCollection implements Set
*/
public boolean equals(Object o)
{
if (o == this)
return true;
else if (o instanceof Set && ((Set) o).size() == size())
return containsAll((Collection) o);
else
return false;
return (o == this ||
(o instanceof Set && ((Set) o).size() == size()
&& containsAll((Collection) o)));
}
/**
......@@ -69,14 +84,45 @@ public abstract class AbstractSet extends AbstractCollection implements Set
public int hashCode()
{
Iterator itr = iterator();
int size = size();
int hash = 0;
for (int pos = 0; pos < size; pos++)
int pos = size();
while (--pos >= 0)
hash += hashCode(itr.next());
return hash;
}
/**
* Removes from this set all elements in the given collection (optional
* operation). This implementation uses <code>size()</code> to determine
* the smaller collection. Then, if this set is smaller, it iterates
* over the set, calling Iterator.remove if the collection contains
* the element. If this set is larger, it iterates over the collection,
* calling Set.remove for all elements in the collection. Note that
* this operation will fail if a remove methods is not supported.
*
* @param c the collection of elements to remove
* @return true if the set was modified as a result
* @throws UnsupportedOperationException if remove is not supported
* @throws NullPointerException if the collection is null
* @see AbstractCollection#remove(Object)
* @see Collection#contains(Object)
* @see Iterator#remove()
*/
public boolean removeAll(Collection c)
{
int oldsize = size();
int count = c.size();
Iterator i;
if (oldsize < count)
{
Object obj = itr.next();
if (obj != null)
hash += obj.hashCode();
for (i = iterator(), count = oldsize; count > 0; count--)
if (c.contains(i.next()))
i.remove();
}
return hash;
else
for (i = c.iterator(); count > 0; count--)
remove(i.next());
return oldsize != size();
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
/* BasicMapEntry.java -- a class providing a plain-vanilla implementation of
the Map.Entry interface; could be used anywhere in java.util
Copyright (C) 1998, 2000 Free Software Foundation, Inc.
Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
......@@ -29,52 +29,113 @@ executable file might be covered by the GNU General Public License. */
package java.util;
/**
* A class which implements Map.Entry. It is shared by HashMap, TreeMap, and
* Hashtable.
* A class which implements Map.Entry. It is shared by HashMap, TreeMap,
* Hashtable, and Collections. It is not specified by the JDK, but makes
* life much easier.
*
* @author Jon Zeppieri
* @author Jon Zeppieri
* @author Eric Blake <ebb9@email.byu.edu>
*/
class BasicMapEntry implements Map.Entry
{
/**
* The key. Package visible for direct manipulation.
*/
Object key;
/**
* The value. Package visible for direct manipulation.
*/
Object value;
/**
* Basic constructor initializes the fields.
* @param newKey the key
* @param newValue the value
*/
BasicMapEntry(Object newKey, Object newValue)
{
key = newKey;
value = newValue;
}
/**
* Compares the specified object with this entry. Returns true only if
* the object is a mapping of identical key and value. In other words,
* this must be:
* <pre>
* (o instanceof Map.Entry) &&
* (getKey() == null ? ((HashMap) o).getKey() == null
* : getKey().equals(((HashMap) o).getKey())) &&
* (getValue() == null ? ((HashMap) o).getValue() == null
* : getValue().equals(((HashMap) o).getValue()))
* </pre>
*
* @param o the object to compare
* @return true if it is equal
*/
public final boolean equals(Object o)
{
if (!(o instanceof Map.Entry))
if (! (o instanceof Map.Entry))
return false;
// Optimize for our own entries.
if (o instanceof BasicMapEntry)
{
BasicMapEntry e = (BasicMapEntry) o;
return (AbstractCollection.equals(key, e.key)
&& AbstractCollection.equals(value, e.value));
}
Map.Entry e = (Map.Entry) o;
return (key == null ? e.getKey() == null : key.equals(e.getKey())
&& value == null ? e.getValue() == null
: value.equals(e.getValue()));
return (AbstractCollection.equals(key, e.getKey())
&& AbstractCollection.equals(value, e.getValue()));
}
/**
* Get the key corresponding to this entry.
*
* @return the key
*/
public final Object getKey()
{
return key;
}
/**
* Get the value corresponding to this entry. If you already called
* Iterator.remove(), the behavior undefined, but in this case it works.
*
* @return the value
*/
public final Object getValue()
{
return value;
}
/**
* Returns the hash code of the entry. This is defined as the exclusive-or
* of the hashcodes of the key and value (using 0 for null). In other
* words, this must be:
* <pre>
* (getKey() == null ? 0 : getKey().hashCode()) ^
* (getValue() == null ? 0 : getValue().hashCode())
* </pre>
*
* @return the hash code
*/
public final int hashCode()
{
int kc = (key == null ? 0 : key.hashCode());
int vc = (value == null ? 0 : value.hashCode());
return kc ^ vc;
return (AbstractCollection.hashCode(key)
^ AbstractCollection.hashCode(value));
}
/**
* sets the value of this Map.Entry. Note that this is overriden by
* Hashtable.Entry, which does not permit a null value.
/**
* Replaces the value with the specified object. This writes through
* to the map, unless you have already called Iterator.remove(). It
* may be overridden to restrict a null value.
*
* @param newVal the new value to store
* @return the old value
* @throws NullPointerException if the map forbids null values
*/
public Object setValue(Object newVal)
{
......@@ -83,6 +144,12 @@ class BasicMapEntry implements Map.Entry
return r;
}
/**
* This provides a string representation of the entry. It is of the form
* "key=value", where string concatenation is used on key and value.
*
* @return the string representation
*/
public final String toString()
{
return key + "=" + value;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
/* Dictionary.java -- an abstract (and essentially worthless)
class which is Hashtable's superclass
Copyright (C) 1998 Free Software Foundation, Inc.
Copyright (C) 1998, 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
......@@ -35,49 +35,88 @@ package java.util;
* This is an abstract class which has really gone by the wayside.
* People at Javasoft are probably embarrassed by it. At this point,
* it might as well be an interface rather than a class, but it remains
* this poor, laugable skeleton for the sake of backwards compatibility.
* this poor, laughable skeleton for the sake of backwards compatibility.
* At any rate, this was what came before the <pre>Map</pre> interface
* in the Collections framework.
*
* @author Jon Zeppieri
* @author Jon Zeppieri
* @author Eric Blake <ebb9@email.byu.edu>
* @see Map
* @see Hashtable
* @since 1.0
* @status updated to 1.4
*/
public abstract class Dictionary extends Object
{
/** returns an Enumeration of the values in this Dictionary */
/**
* Sole constructor (often called implicitly).
*/
public Dictionary()
{
}
/**
* Returns an Enumeration of the values in this Dictionary.
*
* @return an Enumeration of the values
* @see #keys()
*/
public abstract Enumeration elements();
/**
* returns the value associated with the supplied key, or null
* if no such value exists
* Returns the value associated with the supplied key, or null
* if no such value exists. Since Dictionaries are not allowed null keys
* or elements, a null result always means the key is not present.
*
* @param key the key to use to fetch the value
* @param key the key to use to fetch the value
* @return the mapped value
* @throws NullPointerException if key is null
* @see #put(Object, Object)
*/
public abstract Object get(Object key);
/** returns true IFF there are no elements in this Dictionary (size() == 0) */
/**
* Returns true when there are no elements in this Dictionary.
*
* @return <code>size() == 0</code>
*/
public abstract boolean isEmpty();
/** returns an Enumeration of the keys in this Dictionary */
/**
* Returns an Enumeration of the keys in this Dictionary
*
* @return an Enumeration of the keys
* @see #elements()
*/
public abstract Enumeration keys();
/**
* inserts a new value into this Dictionary, located by the
* supllied key; note: Dictionary's subclasses (all 1 of them)
* do not support null keys or values (I can only assume this
* would have been more general)
* Inserts a new value into this Dictionary, located by the
* supplied key. Dictionary does not support null keys or values, so
* a null return can safely be interpreted as adding a new key.
*
* @param key the key which locates the value
* @param value the value to put into the Dictionary
* @param key the key which locates the value
* @param value the value to put into the Dictionary
* @return the previous value of the key, or null if there was none
* @throws NullPointerException if key or value is null
* @see #get(Object)
*/
public abstract Object put(Object key, Object value);
/**
* removes fro the Dictionary the value located by the given key
* Removes from the Dictionary the value located by the given key. A null
* return safely means that the key was not mapped in the Dictionary.
*
* @param key the key used to locate the value to be removed
* @param key the key used to locate the value to be removed
* @return the value associated with the removed key
* @throws NullPointerException if key is null
*/
public abstract Object remove(Object key);
/** returns the number of values currently in this Dictionary */
/**
* Returns the number of values currently in this Dictionary.
*
* @return the number of keys in the Dictionary
*/
public abstract int size();
}
......@@ -28,11 +28,6 @@ executable file might be covered by the GNU General Public License. */
package java.util;
import java.io.IOException;
import java.io.Serializable;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* This class provides a hashtable-backed implementation of the
* Map interface, with predictable traversal order.
......@@ -89,6 +84,7 @@ import java.io.ObjectOutputStream;
* @see TreeMap
* @see Hashtable
* @since 1.4
* @status updated to 1.4
*/
public class LinkedHashMap extends HashMap
{
......@@ -218,8 +214,8 @@ public class LinkedHashMap extends HashMap
* Construct a new insertion-ordered LinkedHashMap with a specific
* inital capacity and default load factor of 0.75.
*
* @param initialCapacity the initial capacity of this HashMap (>=0)
* @throws IllegalArgumentException if (initialCapacity < 0)
* @param initialCapacity the initial capacity of this HashMap (&gt;= 0)
* @throws IllegalArgumentException if (initialCapacity &lt; 0)
*/
public LinkedHashMap(int initialCapacity)
{
......@@ -231,10 +227,10 @@ public class LinkedHashMap extends HashMap
* Construct a new insertion-orderd LinkedHashMap with a specific
* inital capacity and load factor.
*
* @param initialCapacity the initial capacity (>=0)
* @param loadFactor the load factor (>0, not NaN)
* @throws IllegalArgumentException if (initialCapacity < 0) ||
* ! (loadFactor > 0.0)
* @param initialCapacity the initial capacity (&gt;= 0)
* @param loadFactor the load factor (&gt; 0, not NaN)
* @throws IllegalArgumentException if (initialCapacity &lt; 0) ||
* ! (loadFactor &gt; 0.0)
*/
public LinkedHashMap(int initialCapacity, float loadFactor)
{
......@@ -281,7 +277,7 @@ public class LinkedHashMap extends HashMap
LinkedHashEntry e = head;
while (e != null)
{
if (value == null ? e.value == null : value.equals(e.value))
if (equals(value, e.value))
return true;
e = e.succ;
}
......@@ -307,7 +303,7 @@ public class LinkedHashMap extends HashMap
HashEntry e = buckets[idx];
while (e != null)
{
if (key == null ? e.key == null : key.equals(e.key))
if (equals(key, e.key))
{
if (accessOrder)
{
......@@ -376,13 +372,14 @@ public class LinkedHashMap extends HashMap
return false;
}
/** Helper method called by <code>put</code>, which creates and adds a
/**
* Helper method called by <code>put</code>, which creates and adds a
* new Entry, followed by performing bookkeeping (like removeEldestEntry).
*
* @param key the key of the new Entry
* @param value the value
* @param idx the index in buckets where the new Entry belongs
* @param callRemove Whether to call the removeEldestEntry method.
* @param callRemove whether to call the removeEldestEntry method
* @see #put(Object, Object)
* @see #removeEldestEntry(Map.Entry)
*/
......@@ -397,6 +394,11 @@ public class LinkedHashMap extends HashMap
remove(head);
}
/**
* Helper method, called by clone() to reset the doubly-linked list.
* @param m the map to add entries from
* @see #clone()
*/
void putAllInternal(Map m)
{
head = null;
......@@ -466,8 +468,8 @@ public class LinkedHashMap extends HashMap
throw new IllegalStateException();
LinkedHashMap.this.remove(last.key);
knownMod++;
last = null;
knownMod++;
}
};
}
......
/* LinkedHashSet.java -- a set backed by a LinkedHashMap, for linked
list traversal.
Copyright (C) 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.util;
import java.io.Serializable;
/**
* This class provides a hashtable-backed implementation of the
* Set interface, with predictable traversal order.
* <p>
*
* It uses a hash-bucket approach; that is, hash collisions are handled
* by linking the new node off of the pre-existing node (or list of
* nodes). In this manner, techniques such as linear probing (which
* can cause primary clustering) and rehashing (which does not fit very
* well with Java's method of precomputing hash codes) are avoided. In
* addition, this maintains a doubly-linked list which tracks insertion
* order. Note that the insertion order is not modified if an
* <code>add</code> simply reinserts an element in the set.
* <p>
*
* One of the nice features of tracking insertion order is that you can
* copy a set, and regardless of the implementation of the original,
* produce the same results when iterating over the copy. This is possible
* without needing the overhead of <code>TreeSet</code>.
* <p>
*
* Under ideal circumstances (no collisions), LinkedHashSet offers O(1)
* performance on most operations. In the worst case (all elements map
* to the same hash code -- very unlikely), most operations are O(n).
* <p>
*
* LinkedHashSet accepts the null entry. It is not synchronized, so if
* you need multi-threaded access, consider using:<br>
* <code>Set s = Collections.synchronizedSet(new LinkedHashSet(...));</code>
* <p>
*
* The iterators are <i>fail-fast</i>, meaning that any structural
* modification, except for <code>remove()</code> called on the iterator
* itself, cause the iterator to throw a
* {@link ConcurrentModificationException} rather than exhibit
* non-deterministic behavior.
*
* @author Eric Blake <ebb9@email.byu.edu>
* @see Object#hashCode()
* @see Collection
* @see Set
* @see HashSet
* @see TreeSet
* @see Collections#synchronizedSet(Set)
* @since 1.4
* @status updated to 1.4
*/
public class LinkedHashSet extends HashSet
implements Set, Cloneable, Serializable
{
/**
* Compatible with JDK 1.4.
*/
private static final long serialVersionUID = -2851667679971038690L;
/**
* Construct a new, empty HashSet whose backing HashMap has the default
* capacity (11) and loadFacor (0.75).
*/
public LinkedHashSet()
{
super();
}
/**
* Construct a new, empty HashSet whose backing HashMap has the supplied
* capacity and the default load factor (0.75).
*
* @param initialCapacity the initial capacity of the backing HashMap
* @throws IllegalArgumentException if the capacity is negative
*/
public LinkedHashSet(int initialCapacity)
{
super(initialCapacity);
}
/**
* Construct a new, empty HashSet whose backing HashMap has the supplied
* capacity and load factor.
*
* @param initialCapacity the initial capacity of the backing HashMap
* @param loadFactor the load factor of the backing HashMap
* @throws IllegalArgumentException if either argument is negative, or
* if loadFactor is POSITIVE_INFINITY or NaN
*/
public LinkedHashSet(int initialCapacity, float loadFactor)
{
super(initialCapacity, loadFactor);
}
/**
* Construct a new HashSet with the same elements as are in the supplied
* collection (eliminating any duplicates, of course). The backing storage
* has twice the size of the collection, or the default size of 11,
* whichever is greater; and the default load factor (0.75).
*
* @param c a collection of initial set elements
* @throws NullPointerException if c is null
*/
public LinkedHashSet(Collection c)
{
super(c);
}
/**
* Helper method which initializes the backing Map.
*
* @param capacity the initial capacity
* @param load the initial load factor
* @return the backing HashMap
*/
HashMap init(int capacity, float load)
{
return new LinkedHashMap(capacity, load);
}
}
......@@ -190,7 +190,7 @@ public interface List extends Collection
* @see Object#equals(Object)
* @see #hashCode()
*/
boolean equals(Object o);
/* boolean equals(Object o);*/
/**
* Get the element at a given index in this list.
......@@ -288,7 +288,7 @@ public interface List extends Collection
Object remove(int index);
/**
* Remove the first occurrence of an object from this list (optional
* Remove the first occurence of an object from this list (optional
* operation). That is, remove the first element e such that
* <code>o == null ? e == null : o.equals(e)</code>.
*
......
......@@ -32,24 +32,30 @@ package java.util;
* "The Java Language Specification", ISBN 0-201-63451-1
* plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
* Status: Believed complete and correct
*/
/**
* Stack provides a Last In First Out (LIFO) data type, commonly known
* as a Stack.
*
* Stack itself extends Vector and provides the additional methods
* for stack manipulation (push, pop, peek).
* as a Stack. Stack itself extends Vector and provides the additional
* methods for stack manipulation (push, pop, peek). You can also seek for
* the 1-based position of an element on the stack.
*
* @author Warren Levy <warrenl@cygnus.com>
* @date August 20, 1998.
* @author Eric Blake <ebb9@email.byu.edu>
* @see List
* @see AbstractList
* @see LinkedList
* @since 1.0
* @status updated to 1.4
*/
public class Stack extends Vector
{
// Could use Vector methods internally for the following methods
// We could use Vector methods internally for the following methods,
// but have used Vector fields directly for efficiency (i.e. this
// often reduces out duplicate bounds checking).
/**
* Compatible with JDK 1.0+.
*/
private static final long serialVersionUID = 1224463164541339165L;
/**
......@@ -57,16 +63,15 @@ public class Stack extends Vector
*/
public Stack()
{
super();
}
/**
* Pushes an Object onto the top of the stack. This method is effectively
* the same as addElement(item)
* the same as addElement(item).
*
* @param item the Object to push onto the stack
* @returns the Object pushed onto the stack
* @see java.util.Vector#addElement(java.util.Object)
* @return the Object pushed onto the stack
* @see Vector#addElement(Object)
*/
public Object push(Object item)
{
......@@ -80,26 +85,29 @@ public class Stack extends Vector
/**
* Pops an item from the stack and returns it. The item popped is
* removed from the Stack
* removed from the Stack.
*
* @returns the Object popped from the stack
* @return the Object popped from the stack
* @throws EmptyStackException if the stack is empty
*/
public synchronized Object pop()
{
if (elementCount == 0)
throw new EmptyStackException();
modCount++;
Object obj = elementData[--elementCount];
// Set topmost element to null to assist the gc in cleanup
// Set topmost element to null to assist the gc in cleanup.
elementData[elementCount] = null;
return obj;
}
/**
* Returns the top Object on the stack without removing it
* Returns the top Object on the stack without removing it.
*
* @returns the top Object on the stack
* @return the top Object on the stack
* @throws EmptyStackException if the stack is empty
*/
public synchronized Object peek()
{
......@@ -110,11 +118,11 @@ public class Stack extends Vector
}
/**
* Tests if the stack is empty
* Tests if the stack is empty.
*
* @returns true if the stack contains no items, false otherwise
* @return true if the stack contains no items, false otherwise
*/
public boolean empty()
public synchronized boolean empty()
{
return elementCount == 0;
}
......@@ -122,18 +130,18 @@ public class Stack extends Vector
/**
* Returns the position of an Object on the stack, with the top
* most Object being at position 1, and each Object deeper in the
* stack at depth + 1
* stack at depth + 1.
*
* @param o The object to search for
* @returns The 1 based depth of the Object, or -1 if the Object
* is not on the stack.
* @return The 1 based depth of the Object, or -1 if the Object
* is not on the stack
*/
public synchronized int search(Object o)
{
for (int i = elementCount-1; i >=0; --i)
if (elementData[i].equals(o))
int i = elementCount;
while (--i >= 0)
if (equals(o, elementData[i]))
return elementCount - i;
return -1;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment