polyglot.util
Class SubtypeSet

java.lang.Object
  extended by polyglot.util.SubtypeSet
All Implemented Interfaces:
java.lang.Iterable, java.util.Collection, java.util.Set

public class SubtypeSet
extends java.lang.Object
implements java.util.Set

Class to implement sets containing polyglot.types.Type . Set membership is based on the subtype relationships. Thus, if S is a supertype of A and B, then { S } union { A,B } = { S }. Similarily, we remove elements from the set such that if s is an element of a set S, then a call to remove r removes all s s.t. r is a a supertype of s.


Constructor Summary
SubtypeSet(SubtypeSet s)
          Creates a copy of the given SubtypeSet
SubtypeSet(Type top)
           
SubtypeSet(Type top, java.util.Collection c)
           
SubtypeSet(TypeSystem ts)
          Creates an empty SubtypeSet
SubtypeSet(TypeSystem ts, java.util.Collection c)
           
 
Method Summary
 boolean add(java.lang.Object o)
          Add an element of type polyglot.types.Type to the set only if it has no supertypes already in the set.
 boolean addAll(java.util.Collection c)
          Adds all elements from c into this set.
 void clear()
          Removes all elements from the set
 boolean contains(java.lang.Object o)
          Check whether object o is in the set.
 boolean containsAll(java.util.Collection c)
          Checks whether all elements of the collection are in the set
 boolean containsSubtype(Type type)
          Check whether the type t or a subtype is in the set.
 boolean isEmpty()
           
 java.util.Iterator iterator()
           
 boolean remove(java.lang.Object o)
          Removes all elements s in the set such that s decends from o
 boolean removeAll(java.util.Collection c)
           
 boolean retainAll(java.util.Collection c)
           
 int size()
           
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] a)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
equals, hashCode
 

Constructor Detail

SubtypeSet

public SubtypeSet(TypeSystem ts)
Creates an empty SubtypeSet


SubtypeSet

public SubtypeSet(Type top)

SubtypeSet

public SubtypeSet(SubtypeSet s)
Creates a copy of the given SubtypeSet


SubtypeSet

public SubtypeSet(TypeSystem ts,
                  java.util.Collection c)

SubtypeSet

public SubtypeSet(Type top,
                  java.util.Collection c)
Method Detail

add

public boolean add(java.lang.Object o)
Add an element of type polyglot.types.Type to the set only if it has no supertypes already in the set. If we do add it, remove any subtypes of o

Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.Set
Parameters:
o - The element to add.

addAll

public boolean addAll(java.util.Collection c)
Adds all elements from c into this set.

Specified by:
addAll in interface java.util.Collection
Specified by:
addAll in interface java.util.Set

clear

public void clear()
Removes all elements from the set

Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.Set

contains

public boolean contains(java.lang.Object o)
Check whether object o is in the set. Because of the semantics of the subtype set, o is in the set iff it descends from (or is equal to) one of the elements in the set.

Specified by:
contains in interface java.util.Collection
Specified by:
contains in interface java.util.Set

containsSubtype

public boolean containsSubtype(Type type)
Check whether the type t or a subtype is in the set. Returns true iff it descends from, is equal to, or is a super type of one of the elements in the set.


containsAll

public boolean containsAll(java.util.Collection c)
Checks whether all elements of the collection are in the set

Specified by:
containsAll in interface java.util.Collection
Specified by:
containsAll in interface java.util.Set

isEmpty

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

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.Set

remove

public boolean remove(java.lang.Object o)
Removes all elements s in the set such that s decends from o

Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.Set
Returns:
whether or not an element was removed.

removeAll

public boolean removeAll(java.util.Collection c)
Specified by:
removeAll in interface java.util.Collection
Specified by:
removeAll in interface java.util.Set

retainAll

public boolean retainAll(java.util.Collection c)
Specified by:
retainAll in interface java.util.Collection
Specified by:
retainAll in interface java.util.Set

size

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

toArray

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

toArray

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

toString

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