Class MathSet

java.lang.Object
  |
  +--MathSet
Direct Known Subclasses:
State

public class MathSet
extends Object

This class implements a set of strings. Besides adding and removing elements, this class also provides set operations such as union, set-difference, and intersection.


Constructor Summary
MathSet()
          Constructs an empty set.
MathSet(String s)
          Constructs a set containing the specified string.
MathSet(String name, MathSet supset)
          Constructs a set whose elements belong to the given set and begin with the given string followed by a parentesis.
MathSet(Vector v)
          Wraps a MathSet around an existing Vector instance.
 
Method Summary
 void add(String s)
          Adds an element to the set.
 MathSet diff(MathSet b)
          Returns the set difference between the current set and another MathSet.
 MathSet diff(Vector b)
          Returns the set difference between the current set and a Vector.
 String get(int i)
          Returns the ith element of the set.
 MathSet intersect(MathSet b)
          Returns the intersection between the current set and another MathSet.
 MathSet intersect(Vector b)
          Returns the intersection between the current set and a Vector.
 void list()
          Writes the contents of the set to System.out, putting one element per line and prefixing the element with its index.
 boolean remove(String s)
          Removes one element from the set
 int size()
          Returns the number of elements in the set.
 String toString()
          Returns a string representing the set.
 Vector toVector()
          Returns a Vector containing the elements of this set.
 MathSet union(MathSet b)
          Returns the union between the current set and another MathSet.
 MathSet union(Vector b)
          Returns the union between the current set and a Vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MathSet

public MathSet()
Constructs an empty set.

MathSet

public MathSet(String s)
Constructs a set containing the specified string.
Parameters:
s - the string to be added to the set

MathSet

public MathSet(Vector v)
Wraps a MathSet around an existing Vector instance.
Parameters:
v - the vector that will be access through the MathSet

MathSet

public MathSet(String name,
               MathSet supset)
Constructs a set whose elements belong to the given set and begin with the given string followed by a parentesis.

This constructor is useful to build the set of ground instances of a given fluent, e.g.

     MathSet x = new MathSet("position",Set_of_All_Fluents);
 
will construct a set x containing all the ground instances of fluent "position".
Parameters:
supset - the set from which elements are extracted
name - the string that the elements must begin with
Method Detail

toVector

public Vector toVector()
Returns a Vector containing the elements of this set.
Returns:
a Vector instance containing the elements of the set

size

public int size()
Returns the number of elements in the set.
Returns:
the number of elements in the set

add

public void add(String s)
Adds an element to the set.
Parameters:
s - the string to be added to the set

remove

public boolean remove(String s)
Removes one element from the set
Parameters:
s - the string to be removed from the set
Returns:
true if the string occurred in the set; false otherwise

get

public String get(int i)
Returns the ith element of the set.
Parameters:
i - the index of the element to be retrieved (0 is the first element)
Returns:
the element that was requested

union

public MathSet union(MathSet b)
Returns the union between the current set and another MathSet.
Parameters:
b - the MathSet to be used to compute the union
Returns:
a new MathSet consisting of the union of the current set and another MathSet

union

public MathSet union(Vector b)
Returns the union between the current set and a Vector.
Parameters:
b - the Vector to be used to compute the union
Returns:
a new MathSet consisting of the union of the current set and a Vector

diff

public MathSet diff(MathSet b)
Returns the set difference between the current set and another MathSet.
Parameters:
b - the MathSet to be used to compute the difference
Returns:
a new MathSet consisting of the set difference of the current set and another MathSet

diff

public MathSet diff(Vector b)
Returns the set difference between the current set and a Vector.
Parameters:
b - the MathSet to be used to compute the difference
Returns:
a new MathSet consisting of the set difference of the current set and a Vector

intersect

public MathSet intersect(MathSet b)
Returns the intersection between the current set and another MathSet.
Parameters:
b - the MathSet to be used to compute the intersection
Returns:
a new MathSet consisting of the set intersection of the current set and another MathSet

intersect

public MathSet intersect(Vector b)
Returns the intersection between the current set and a Vector.
Parameters:
b - the MathSet to be used to compute the intersection
Returns:
a new MathSet consisting of the set intersection of the current set and a Vector

toString

public String toString()
Returns a string representing the set. "{" and "}" mark the beginning and the end of the set, and elements are comma-separated.
Overrides:
toString in class Object
Returns:
a string representing the set

list

public void list()
Writes the contents of the set to System.out, putting one element per line and prefixing the element with its index.