Back to index

plt-scheme  4.2.1
AbstractSequentialList.java
Go to the documentation of this file.
00001 /* AbstractSequentialList.java -- List implementation for sequential access
00002    Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
00003 
00004 This file is part of GNU Classpath.
00005 
00006 GNU Classpath is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU General Public License as published by
00008 the Free Software Foundation; either version 2, or (at your option)
00009 any later version.
00010 
00011 GNU Classpath is distributed in the hope that it will be useful, but
00012 WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with GNU Classpath; see the file COPYING.  If not, write to the
00018 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019 02111-1307 USA.
00020 
00021 Linking this library statically or dynamically with other modules is
00022 making a combined work based on this library.  Thus, the terms and
00023 conditions of the GNU General Public License cover the whole
00024 combination.
00025 
00026 As a special exception, the copyright holders of this library give you
00027 permission to link this library with independent modules to produce an
00028 executable, regardless of the license terms of these independent
00029 modules, and to copy and distribute the resulting executable under
00030 terms of your choice, provided that you also meet, for each linked
00031 independent module, the terms and conditions of the license of that
00032 module.  An independent module is a module which is not derived from
00033 or based on this library.  If you modify this library, you may extend
00034 this exception to your version of the library, but you are not
00035 obligated to do so.  If you do not wish to do so, delete this
00036 exception statement from your version. */
00037 
00038 
00039 package java.util;
00040 
00074 public abstract class AbstractSequentialList extends AbstractList
00075 {
00079   protected AbstractSequentialList()
00080   {
00081   }
00082 
00091   public abstract ListIterator listIterator(int index);
00092 
00110   public void add(int index, Object o)
00111   {
00112     listIterator(index).add(o);
00113   }
00114 
00142   public boolean addAll(int index, Collection c)
00143   {
00144     Iterator ci = c.iterator();
00145     int size = c.size();
00146     ListIterator i = listIterator(index);
00147     for (int pos = size; pos > 0; pos--)
00148       i.add(ci.next());
00149     return size > 0;
00150   }
00151 
00160   public Object get(int index)
00161   {
00162     // This is a legal listIterator position, but an illegal get.
00163     if (index == size())
00164       throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
00165                                           + size());
00166     return listIterator(index).next();
00167   }
00168 
00175   public Iterator iterator()
00176   {
00177     return (Iterator) ((Object) listIterator());
00178   }
00179 
00191   public Object remove(int index)
00192   {
00193     // This is a legal listIterator position, but an illegal remove.
00194     if (index == size())
00195       throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
00196                                           + size());
00197     ListIterator i = listIterator(index);
00198     Object removed = i.next();
00199     i.remove();
00200     return removed;
00201   }
00202 
00218   public Object set(int index, Object o)
00219   {
00220     // This is a legal listIterator position, but an illegal set.
00221     if (index == size())
00222       throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
00223                                           + size());
00224     ListIterator i = listIterator(index);
00225     Object old = i.next();
00226     i.set(o);
00227     return old;
00228   }
00229 }