diff options
author | green <green@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-08-27 22:06:44 +0000 |
---|---|---|
committer | green <green@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-08-27 22:06:44 +0000 |
commit | 66784a64e6d660f047249ab6d4eafaf180744796 (patch) | |
tree | c342711888f627f7baae5e2abb62a00909d971ea /libjava/java/util/AbstractSequentialList.java | |
parent | d476f3c9f78d74eb0bc0ff36e9f10364cdb286c1 (diff) | |
download | ppe42-gcc-66784a64e6d660f047249ab6d4eafaf180744796.tar.gz ppe42-gcc-66784a64e6d660f047249ab6d4eafaf180744796.zip |
2000-08-27 Anthony Green <green@redhat.com>
* java/util/ArrayList.java, java/util/Timer.java,
java/util/LinkedList.java, java/util/TimerTask.java,
java/util/HashMap.java, java/util/AbstractMap.java,
java/util/SortedMap.java, java/util/AbstractSequentialList.java,
java/util/SortedSet.java: Imported from GNU Classpath.
* Makefile.in: Rebuilt.
* Makefile.am: Added new files.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@36006 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/util/AbstractSequentialList.java')
-rw-r--r-- | libjava/java/util/AbstractSequentialList.java | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/libjava/java/util/AbstractSequentialList.java b/libjava/java/util/AbstractSequentialList.java new file mode 100644 index 00000000000..69bdc4ae220 --- /dev/null +++ b/libjava/java/util/AbstractSequentialList.java @@ -0,0 +1,113 @@ +/* AbstractSequentialList.java -- List implementation for sequential access + Copyright (C) 1998, 1999 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. */ + + +// 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. + */ +public abstract class AbstractSequentialList extends AbstractList { + + /** + * 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() + */ + 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. + * + * @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. + */ + public void add(int index, Object o) { + ListIterator i = listIterator(index); + i.add(o); + } + + public boolean addAll(int index, Collection c) { + boolean changed = false; + Iterator ci = c.iterator(); + ListIterator i = listIterator(index); + while (ci.hasNext()) { + i.add(ci.next()); + changed = true; + } + return changed; + } + + public Object get(int index) { + ListIterator i = listIterator(index); + if (!i.hasNext()) { + throw new IndexOutOfBoundsException(); + } + return i.next(); + } + + /** + * Return an Iterator over this List. This implementation returns + * listIterator(). + * + * @return an Iterator over this List + */ + public Iterator iterator() { + return listIterator(); + } + + public Object remove(int index) { + ListIterator i = listIterator(index); + if (!i.hasNext()) { + throw new IndexOutOfBoundsException(); + } + Object removed = i.next(); + i.remove(); + return removed; + } + + public Object set(int index, Object o) { + ListIterator i = listIterator(index); + if (!i.hasNext()) { + throw new IndexOutOfBoundsException(); + } + Object old = i.next(); + i.set(o); + return old; + } +} |