structure
Class AbstractSet<ELTTYPE>

java.lang.Object
  extended by structure.AbstractStructure<ELTTYPE>
      extended by structure.AbstractSet<ELTTYPE>
All Implemented Interfaces:
java.lang.Iterable<ELTTYPE>, Set<ELTTYPE>, Structure<ELTTYPE>
Direct Known Subclasses:
SetList, SetVector

public abstract class AbstractSet<ELTTYPE>
extends AbstractStructure<ELTTYPE>
implements Set<ELTTYPE>

Methods common to an Implementation of a set of elements irrespective of the underlying storage mechanism. As with the mathematical object, the elements of the set are not duplicated. No order is implied or enforced in this structure, but simple set operations such as intersection, union, difference, and subset are provided.

Example Usage: Given a list of students who completed a computer science thesis in the 2001-2002 academic year at Williams College and a list of graduating computer science majors who are continuing on to graduate school, we could determine which thesis students are planning to attend graduate school as follows:

 public static void main(String[] argv){
        //thesis students in the class of '02
        String[] thesis = new String[]{"Doug", "Evan", "Feng"};
        
        //students continuing on to grad school
        String[] grad = new String[]{"Doug", "Feng", "Lida"};

        //instantiate our sets
        Set thesisSet = new SetVector.SetVector(), 
            gradSet = new SetVector.SetVector();
                
        //build sets up
        for(int i = 0; i < thesis.length; i++) thesisSet.add(thesis[i]);
        for(int i = 0; i < grad.length; i++) gradSet.add(grad[i]);
        
        //calculate the intersection of the two sets
        thesisSet.retainAll(gradSet);
        System.out.println(thesisSet);
 }
 


Constructor Summary
AbstractSet()
           
 
Method Summary
 void addAll(Structure<ELTTYPE> other)
          Union other set into this set.
 boolean containsAll(Structure<ELTTYPE> other)
          Check to see if this set is contained in the other structure.
 void removeAll(Structure<ELTTYPE> other)
          Computes the difference between this set and the other structure
 void retainAll(Structure<ELTTYPE> other)
          Computes the intersection between this set and the other structure.
 
Methods inherited from class structure.AbstractStructure
contains, elements, hashCode, isEmpty, values
 
Methods inherited from class java.lang.Object
equals, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface structure.Structure
add, clear, contains, elements, isEmpty, iterator, remove, size, values
 

Constructor Detail

AbstractSet

public AbstractSet()
Method Detail

addAll

public void addAll(Structure<ELTTYPE> other)
Union other set into this set.

Specified by:
addAll in interface Set<ELTTYPE>
Pre:
other is non-null
Post:
values from other are added into this set

containsAll

public boolean containsAll(Structure<ELTTYPE> other)
Check to see if this set is contained in the other structure.

Specified by:
containsAll in interface Set<ELTTYPE>
Pre:
other is non-null
Post:
returns true if every value in this set is contained in the other

removeAll

public void removeAll(Structure<ELTTYPE> other)
Computes the difference between this set and the other structure

Specified by:
removeAll in interface Set<ELTTYPE>
Pre:
other is non-null
Post:
values of this set contained in other are removed

retainAll

public void retainAll(Structure<ELTTYPE> other)
Computes the intersection between this set and the other structure.

Specified by:
retainAll in interface Set<ELTTYPE>
Pre:
other is non-null
Post:
values not appearing in the other structure are removed