polyglot.util
Class TypedList

java.lang.Object
  extended by polyglot.util.TypedList
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.List

public class TypedList
extends java.lang.Object
implements java.util.List, java.io.Serializable, java.lang.Cloneable

A TypedList is an List which will not allow members not belonging to a given type to be added to a collection. Optionally, it may also present an immutable view. If an attempt is made to change an immutable list, or if an attempt is made to insert an improperly-typed element, an UnsupportedOperationException is thrown. This class is given so that we can present a List for a given class without worrying about outsiders breaking the rep. This is a poor substitute for PolyJ.

See Also:
Serialized Form

Constructor Summary
TypedList(java.util.List list, java.lang.Class c, boolean immutable)
          Requires: not null, and every element of may be cast to class .
 
Method Summary
 void add(int idx, java.lang.Object o)
           
 boolean add(java.lang.Object o)
           
 boolean addAll(java.util.Collection coll)
           
 boolean addAll(int idx, java.util.Collection coll)
           
static void check(java.util.List list, java.lang.Class c)
          Throws an UnsupportedOperationException if any member of may not be cast to class .
 void clear()
           
 java.lang.Object clone()
           
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection coll)
           
 TypedList copy()
          Copies this list.
static TypedList copy(java.util.List list, java.lang.Class c, boolean immutable)
          Requires: not null, and every element of may be cast to class .
static TypedList copyAndCheck(java.util.List list, java.lang.Class c, boolean immutable)
          Creates a new TypedList, containing all the elements of , which restricts all members to belong to class .
 boolean equals(java.lang.Object o)
           
 java.lang.Object get(int idx)
           
 java.lang.Class getAllowedType()
          Gets the allowed type for this list.
 int hashCode()
           
 int indexOf(java.lang.Object o)
           
 boolean isEmpty()
           
 java.util.Iterator iterator()
           
 int lastIndexOf(java.lang.Object o)
           
 java.util.ListIterator listIterator()
           
 java.util.ListIterator listIterator(int idx)
           
 java.lang.Object remove(int idx)
           
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection coll)
           
 boolean retainAll(java.util.Collection coll)
           
 java.lang.Object set(int idx, java.lang.Object o)
           
 int size()
           
 java.util.List subList(int from, int to)
           
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] oa)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TypedList

public TypedList(java.util.List list,
                 java.lang.Class c,
                 boolean immutable)
Requires: not null, and every element of may be cast to class . Effects: Creates a new TypedList around which restricts all members to belong to class . If is null, no typing restriction is made. If is true, no modifications are allowed.

Method Detail

copy

public static TypedList copy(java.util.List list,
                             java.lang.Class c,
                             boolean immutable)
Requires: not null, and every element of may be cast to class . Creates a new TypedList, containing all the elements of , which restricts all members to belong to class . If is null, no typing restriction is made. If is true, no modifications are allowed.


copyAndCheck

public static TypedList copyAndCheck(java.util.List list,
                                     java.lang.Class c,
                                     boolean immutable)
Creates a new TypedList, containing all the elements of , which restricts all members to belong to class . If is null, no typing restriction is made. If is true, no modifications are allowed. Throws an UnsupportedOperationException if any member of may not be cast to class .


check

public static void check(java.util.List list,
                         java.lang.Class c)
Throws an UnsupportedOperationException if any member of may not be cast to class . Otherwise does nothing.


getAllowedType

public java.lang.Class getAllowedType()
Gets the allowed type for this list.


copy

public TypedList copy()
Copies this list.


clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

add

public void add(int idx,
                java.lang.Object o)
Specified by:
add in interface java.util.List

add

public boolean add(java.lang.Object o)
Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.List

addAll

public boolean addAll(int idx,
                      java.util.Collection coll)
Specified by:
addAll in interface java.util.List

addAll

public boolean addAll(java.util.Collection coll)
Specified by:
addAll in interface java.util.Collection
Specified by:
addAll in interface java.util.List

listIterator

public java.util.ListIterator listIterator()
Specified by:
listIterator in interface java.util.List

listIterator

public java.util.ListIterator listIterator(int idx)
Specified by:
listIterator in interface java.util.List

set

public java.lang.Object set(int idx,
                            java.lang.Object o)
Specified by:
set in interface java.util.List

subList

public java.util.List subList(int from,
                              int to)
Specified by:
subList in interface java.util.List

clear

public void clear()
Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.List

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection
Specified by:
contains in interface java.util.List

containsAll

public boolean containsAll(java.util.Collection coll)
Specified by:
containsAll in interface java.util.Collection
Specified by:
containsAll in interface java.util.List

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Collection
Specified by:
equals in interface java.util.List
Overrides:
equals in class java.lang.Object

get

public java.lang.Object get(int idx)
Specified by:
get in interface java.util.List

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Collection
Specified by:
hashCode in interface java.util.List
Overrides:
hashCode in class java.lang.Object

indexOf

public int indexOf(java.lang.Object o)
Specified by:
indexOf in interface java.util.List

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection
Specified by:
isEmpty in interface java.util.List

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in interface java.util.List

lastIndexOf

public int lastIndexOf(java.lang.Object o)
Specified by:
lastIndexOf in interface java.util.List

remove

public java.lang.Object remove(int idx)
Specified by:
remove in interface java.util.List

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.List

removeAll

public boolean removeAll(java.util.Collection coll)
Specified by:
removeAll in interface java.util.Collection
Specified by:
removeAll in interface java.util.List

retainAll

public boolean retainAll(java.util.Collection coll)
Specified by:
retainAll in interface java.util.Collection
Specified by:
retainAll in interface java.util.List

size

public int size()
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.List

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List

toArray

public java.lang.Object[] toArray(java.lang.Object[] oa)
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object