Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Collections.java

00001 package ca.mcgill.sable.util;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * SableUtil, a clean room implementation of the Collection API.     *
00005  * Copyright (C) 1997, 1998 Raja Vallee-Rai (kor@sable.mcgill.ca).   *
00006  * All rights reserved.                                              *
00007  *                                                                   *
00008  * Modifications by Patrick Lam are                                  *
00009  * Copyright (C) 1998 Patrick Lam (plam@sable.mcgill.ca).  All       *
00010  * rights reserved.                                                  *
00011  *                                                                   *
00012  * Modifications by Etienne Gagnon (gagnon@sable.mcgill.ca) are      *
00013  * Copyright (C) 1998 Etienne Gagnon (gagnon@sable.mcgill.ca). All   *
00014  * rights reserved.                                                  *
00015  *                                                                   *
00016  * This work was done as a project of the Sable Research Group,      *
00017  * School of Computer Science, McGill University, Canada             *
00018  * (http://www.sable.mcgill.ca/).  It is understood that any         *
00019  * modification not identified as such is not covered by the         *
00020  * preceding statement.                                              *
00021  *                                                                   *
00022  * This work is free software; you can redistribute it and/or        *
00023  * modify it under the terms of the GNU Library General Public       *
00024  * License as published by the Free Software Foundation; either      *
00025  * version 2 of the License, or (at your option) any later version.  *
00026  *                                                                   *
00027  * This work is distributed in the hope that it will be useful,      *
00028  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00029  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00030  * Library General Public License for more details.                  *
00031  *                                                                   *
00032  * You should have received a copy of the GNU Library General Public *
00033  * License along with this library; if not, write to the             *
00034  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00035  * Boston, MA  02111-1307, USA.                                      *
00036  *                                                                   *
00037  * To submit a bug report, send a comment, or get the latest news on *
00038  * this project and other Sable Research Group projects, please      *
00039  * visit the web site: http://www.sable.mcgill.ca/                   *
00040  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00041 
00042 /*
00043  Reference Version
00044  -----------------
00045  This is the latest official version on which this file is based.
00046  The reference version is: $SableUtilVersion: 1.11 $
00047 
00048  Change History
00049  --------------
00050  A) Notes:
00051 
00052  Please use the following template.  Most recent changes should
00053  appear at the top of the list.
00054 
00055  - Modified on [date (March 1, 1900)] by [name]. [(*) if appropriate]
00056    [description of modification].
00057 
00058  Any Modification flagged with "(*)" was done as a project of the
00059  Sable Research Group, School of Computer Science,
00060  McGill University, Canada (http://www.sable.mcgill.ca/).
00061 
00062  You should add your copyright, using the following template, at
00063  the top of this file, along with other copyrights.
00064 
00065  *                                                                   *
00066  * Modifications by [name] are                                       *
00067  * Copyright (C) [year(s)] [your name (or company)].  All rights     *
00068  * reserved.                                                         *
00069  *                                                                   *
00070 
00071  B) Changes:
00072 
00073  - Modified on August 10, 1998 by Patrick Lam (plam@sable.mcgill.ca) (*)
00074    Added pass-through toString to UnmodifiableList.
00075 
00076  - Modified on July 23, 1998 by Raja Vallee-Rai (kor@sable.mcgill.ca) (*)
00077    Changed some constructors to satisfy jikes.
00078 
00079  - Modified on July 23, 1998 by Etienne Gagnon (gagnon@sable.mcgill.ca). (*)
00080    Added toArray(Object[]).
00081 
00082  - Modified on June 15, 1998 by Patrick Lam (plam@sable.mcgill.ca). (*)
00083    Added UnmodifiableList and associated inner classes.
00084 
00085  - Modified on June 15, 1998 by Raja Vallee-Rai (kor@sable.mcgill.ca). (*)
00086    First release of this file.
00087 */
00088 
00089 public class Collections
00090 {
00091   static class UnmodIterator implements Iterator
00092   {
00093     Iterator it;
00094     public UnmodIterator(Iterator it) { this.it = it; }
00095 
00096     public boolean hasNext() { return it.hasNext(); }
00097     public Object next() { return it.next(); }
00098     public void remove()
00099       throws UnsupportedOperationException, NoSuchElementException
00100       { throw new UnsupportedOperationException(); }
00101   }
00102 
00103   static class UnmodListIterator implements ListIterator
00104   {
00105     ListIterator li;
00106 
00107     public UnmodListIterator(ListIterator li) { this.li = li; }
00108 
00109     public boolean hasNext() { return li.hasNext(); }
00110     public Object next() throws NoSuchElementException
00111       { return li.next(); }
00112     public boolean hasPrevious() { return li.hasPrevious(); }
00113     public Object previous() throws NoSuchElementException
00114       { return li.previous(); }
00115     public int nextIndex() { return li.nextIndex(); }
00116     public int previousIndex() { return li.previousIndex(); }
00117     public void remove()
00118       throws UnsupportedOperationException, NoSuchElementException
00119       { throw new UnsupportedOperationException(); }
00120     public void set(Object o)
00121       throws UnsupportedOperationException, NoSuchElementException
00122       { throw new UnsupportedOperationException(); }
00123     public void add(Object o)
00124       throws UnsupportedOperationException
00125       { throw new UnsupportedOperationException(); }
00126   }
00127 
00128   static class UnmodList implements List
00129   {
00130     private List l;
00131 
00132     public UnmodList(List l) { this.l = l; }
00133 
00134     public int size() { return l.size(); }
00135     public boolean isEmpty() { return l.isEmpty(); }
00136     public boolean contains(Object o) { return l.contains(o); }
00137     public Object[] toArray() { return l.toArray(); }
00138 
00139     public void toArray(Object[] a)
00140     {
00141         l.toArray(a);
00142     }
00143 
00144     public boolean add(Object o)
00145       throws UnsupportedOperationException,
00146       ClassCastException, IllegalArgumentException
00147       { throw new UnsupportedOperationException(); }
00148     public boolean remove(Object o)
00149       throws UnsupportedOperationException
00150       { throw new UnsupportedOperationException(); }
00151     public boolean containsAll(Collection c) { return l.containsAll(c); }
00152     public boolean addAll(Collection c)
00153       throws UnsupportedOperationException,
00154       ClassCastException, IllegalArgumentException
00155       { throw new UnsupportedOperationException(); }
00156     public boolean removeAll(Collection c)
00157       throws UnsupportedOperationException
00158       { throw new UnsupportedOperationException(); }
00159     public boolean retainAll(Collection c)
00160       throws UnsupportedOperationException
00161       { throw new UnsupportedOperationException(); }
00162     public void clear()
00163       throws UnsupportedOperationException
00164       { throw new UnsupportedOperationException(); }
00165     public boolean equals(Object o) { return l.equals(o); }
00166     public int hashCode() { return l.hashCode(); }
00167     public Object get(int index)
00168       throws ArrayIndexOutOfBoundsException
00169       { return l.get(index); }
00170     public Object set(int index, Object element)
00171       throws UnsupportedOperationException, ClassCastException,
00172       IllegalArgumentException, ArrayIndexOutOfBoundsException
00173       { throw new UnsupportedOperationException(); }
00174     public void add(int index, Object element)
00175       throws UnsupportedOperationException, ClassCastException,
00176       IllegalArgumentException, ArrayIndexOutOfBoundsException
00177       { throw new UnsupportedOperationException(); }
00178     public Object remove(int index)
00179       throws UnsupportedOperationException, ArrayIndexOutOfBoundsException
00180       { throw new UnsupportedOperationException(); }
00181     public int indexOf(Object o) { return l.indexOf(o); }
00182     public int indexOf(Object o, int index)
00183       throws ArrayIndexOutOfBoundsException
00184       { return l.indexOf(o, index); }
00185     public int lastIndexOf(Object o) { return l.lastIndexOf(o); }
00186     public int lastIndexOf(Object o, int index)
00187       throws ArrayIndexOutOfBoundsException
00188       { return l.lastIndexOf(o, index); }
00189     public void removeRange(int fromIndex, int toIndex)
00190       throws UnsupportedOperationException, ArrayIndexOutOfBoundsException
00191       { throw new UnsupportedOperationException(); }
00192     public boolean addAll(int index, Collection c)
00193       throws UnsupportedOperationException, ClassCastException,
00194       IllegalArgumentException, ArrayIndexOutOfBoundsException
00195       { throw new UnsupportedOperationException(); }
00196     public String toString() { return l.toString(); }
00197 
00198     public Iterator iterator() { return new UnmodIterator(l.iterator()); }
00199     public ListIterator listIterator()
00200       { return new UnmodListIterator(l.listIterator()); }
00201     public ListIterator listIterator(int index)
00202       throws ArrayIndexOutOfBoundsException
00203       { return new UnmodListIterator(l.listIterator(index)); }
00204     }
00205 
00206   public static List unmodifiableList(List list)
00207     {
00208       return new UnmodList(list);
00209     }
00210 }

Generated at Thu Feb 7 06:42:40 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001