Opus5
Class SetAsArray

java.lang.Object
  |
  +--Opus5.AbstractObject
        |
        +--Opus5.AbstractContainer
              |
              +--Opus5.AbstractSearchableContainer
                    |
                    +--Opus5.AbstractSet
                          |
                          +--Opus5.SetAsArray
All Implemented Interfaces:
Comparable, Container, SearchableContainer, Set

public class SetAsArray
extends AbstractSet
implements Set

Set implemented using an array of booleans.

Version:
$Id: SetAsArray.java,v 3.3 1998/07/28 02:49:09 brpreiss Exp $
Author:
Bruno R. Preiss, P.Eng.

Field Summary
protected  boolean[] array
          The array.
 
Fields inherited from class Opus5.AbstractSet
universeSize
 
Fields inherited from class Opus5.AbstractContainer
count
 
Fields inherited from interface Opus5.Set
copyright
 
Constructor Summary
SetAsArray(int n)
          Constructs a SetAsArray for the specified size of universal set.
 
Method Summary
 void accept(Visitor visitor)
          Accepts a visitor and makes it visit the elements of this set.
protected  int compareTo(Comparable arg)
          Compares this set with the specified comparable object.
 Set difference(Set set)
          Returns a set which is the difference between this set and the specified set.
 int getCount()
          Returns the number of elements in this set.
 Enumeration getEnumeration()
          Returns an enumeration that enumerates the elements of this set.
protected  void insert(int item)
          Inserts the specified item into this set.
 Set intersection(Set set)
          Returns a set which is the intersection of this set and the specified set.
 boolean isEmpty()
          Tests whether this set is empty.
 boolean isEQ(Set set)
          Tests whether this set is equal to the specified set.
 boolean isFull()
          Tests whether this set is full.
protected  boolean isMember(int item)
          Tests if the specified item is a member of this set.
 boolean isSubset(Set set)
          Tests whether this set is a subset of the specified set.
 void purge()
          Purges this set, making it empty.
 Set union(Set set)
          Returns a set which is the union of this set and the specified set.
protected  void withdraw(int item)
          Withdraws the specified item from this set.
 
Methods inherited from class Opus5.AbstractSet
find, insert, isMember, withdraw
 
Methods inherited from class Opus5.AbstractContainer
hashCode, toString
 
Methods inherited from class Opus5.AbstractObject
compare, equals, isEQ, isGE, isGT, isLE, isLT, isNE
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface Opus5.SearchableContainer
find, insert, isMember, withdraw
 
Methods inherited from interface Opus5.Comparable
compare, isEQ, isGE, isGT, isLE, isLT, isNE
 

Field Detail

array

protected boolean[] array
The array.
Constructor Detail

SetAsArray

public SetAsArray(int n)
Constructs a SetAsArray for the specified size of universal set.
Parameters:
n - The number of elements in the universal set.
Method Detail

insert

protected void insert(int item)
Inserts the specified item into this set.
Overrides:
insert in class AbstractSet
Parameters:
item - The item to insert.

isMember

protected boolean isMember(int item)
Tests if the specified item is a member of this set.
Overrides:
isMember in class AbstractSet
Parameters:
item - The item for which to look.
Returns:
True if the item is a member of this set; false otherwise.

withdraw

protected void withdraw(int item)
Withdraws the specified item from this set.
Overrides:
withdraw in class AbstractSet
Parameters:
item - The item to be withdrawn.

isEmpty

public boolean isEmpty()
Tests whether this set is empty.
Specified by:
isEmpty in interface Container
Overrides:
isEmpty in class AbstractContainer
Returns:
True if this set is empty; false otherwise.

isFull

public boolean isFull()
Tests whether this set is full.
Specified by:
isFull in interface Container
Overrides:
isFull in class AbstractContainer
Returns:
True if this set is full; false otherwise.

purge

public void purge()
Purges this set, making it empty.
Specified by:
purge in interface Container

accept

public void accept(Visitor visitor)
Accepts a visitor and makes it visit the elements of this set.
Specified by:
accept in interface Container
Overrides:
accept in class AbstractContainer
Parameters:
visitor - The visitor to accept.

getCount

public int getCount()
Returns the number of elements in this set.
Specified by:
getCount in interface Container
Overrides:
getCount in class AbstractContainer
Returns:
The number of elements in this set.

union

public Set union(Set set)
Returns a set which is the union of this set and the specified set. It is assumed that the specified set is an instance of the SetAsArray class.
Specified by:
union in interface Set
Parameters:
set - The set to join with this set.
Returns:
The union of this set with the specified set.
Throws:
java.lang.IllegalArgumentException - If the sizes of the universal sets differ.

intersection

public Set intersection(Set set)
Returns a set which is the intersection of this set and the specified set. It is assumed that the specified set is an instance of the SetAsArray class.
Specified by:
intersection in interface Set
Parameters:
set - The set to intersect with this set.
Returns:
The intersection of this set with the specified set.
Throws:
java.lang.IllegalArgumentException - If the sizes of the universal sets differ.

difference

public Set difference(Set set)
Returns a set which is the difference between this set and the specified set. It is assumed that the specified set is an instance of the SetAsArray class.
Specified by:
difference in interface Set
Parameters:
set - The set to subtract from this set.
Returns:
The difference between this set and the specified set.
Throws:
java.lang.IllegalArgumentException - If the sizes of the universal sets differ.

isEQ

public boolean isEQ(Set set)
Tests whether this set is equal to the specified set. It is assumed that the specified set is an instance of the SetAsArray class.
Specified by:
isEQ in interface Set
Parameters:
set - The set to compare with this set.
Returns:
True if the sets are equal; false otherwise.
Throws:
java.lang.IllegalArgumentException - If the sizes of the universal sets differ.

isSubset

public boolean isSubset(Set set)
Tests whether this set is a subset of the specified set. It is assumed that the specified set is an instance of the SetAsArray class.
Specified by:
isSubset in interface Set
Parameters:
set - The set to compare with this set.
Returns:
True if the this set is a subset of the specified set; false otherwise.
Throws:
java.lang.IllegalArgumentException - If the sizes of the universal sets differ.

getEnumeration

public Enumeration getEnumeration()
Returns an enumeration that enumerates the elements of this set.
Specified by:
getEnumeration in interface Container
Returns:
An enumeration that enumerates the elements of this set.

compareTo

protected int compareTo(Comparable arg)
Compares this set with the specified comparable object. This method is not implemented.
Overrides:
compareTo in class AbstractObject
Parameters:
arg - The comparable object to compare with this set.
Throws:
MethodNotImplemented - Alwys.