Opus5
Class MultisetAsArray

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

public class MultisetAsArray
extends AbstractSet
implements Multiset

Multiset implemented using an array of ints.

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

Field Summary
protected  int[] array
          The array.
 
Fields inherited from class Opus5.AbstractSet
universeSize
 
Fields inherited from class Opus5.AbstractContainer
count
 
Fields inherited from interface Opus5.Multiset
copyright
 
Constructor Summary
MultisetAsArray(int n)
          Constructs a MultisetAsArray for the specified size of universal multiset.
 
Method Summary
 void accept(Visitor visitor)
          Accepts a visitor and makes it visit the elements of this multiset.
protected  int compareTo(Comparable arg)
          Compares this multiset with the specified comparable object.
 Multiset difference(Multiset set)
          Returns a multiset which is the difference between this multiset and the specified multiset.
 int getCount()
          Returns the number of elements in this multiset.
 Enumeration getEnumeration()
          Returns an enumeration that enumerates the elements of this multiset.
protected  void insert(int item)
          Inserts the specified item into this multiset.
 Multiset intersection(Multiset set)
          Returns a multiset which is the intersection of this multiset and the specified multiset.
 boolean isEQ(Multiset set)
          Tests whether this multiset is equal to the specified multiset.
protected  boolean isMember(int item)
          Tests if the specified item is a member of this multiset.
 boolean isSubset(Multiset set)
          Tests whether this multiset is a subset of the specified multiset.
 void purge()
          Purges this multiset, making it empty.
 Multiset union(Multiset set)
          Returns a multiset which is the union of this multiset and the specified multiset.
protected  void withdraw(int item)
          Withdraws the specified item from this multiset.
 
Methods inherited from class Opus5.AbstractSet
find, insert, isMember, withdraw
 
Methods inherited from class Opus5.AbstractContainer
hashCode, isEmpty, isFull, 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.Container
isEmpty, isFull
 
Methods inherited from interface Opus5.Comparable
compare, isEQ, isGE, isGT, isLE, isLT, isNE
 

Field Detail

array

protected int[] array
The array.
Constructor Detail

MultisetAsArray

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

insert

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

withdraw

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

isMember

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

purge

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

getCount

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

accept

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

union

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

intersection

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

difference

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

isSubset

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

isEQ

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

getEnumeration

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

compareTo

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