structure
Class CharSet

java.lang.Object
  extended by structure.CharSet

public class CharSet
extends java.lang.Object

Implementation of a set of characters whose ASCII values are between 0 and 255, inclusive. This set is specialized for use with characters. It is implemented using the BitSet class.

See Also:
BitSet

Field Summary
protected  BitSet s
           
 
Constructor Summary
CharSet()
          Constructs an empty charset.
 
Method Summary
 void add(char c)
          Adds character c to set if not already there.
 void clear()
          Removes the characters of the set.
 java.lang.Object clone()
          Construct a duplicate of the character set.
 boolean contains(char c)
          Detects whether c is a member of this set.
 java.lang.Object difference(CharSet other)
          Computes the difference between this and other charset.
 boolean equals(java.lang.Object other)
          Detect if two sets are equal.
 java.lang.Object intersection(CharSet other)
          Computes the intersection of this charset and other.
 boolean isEmpty()
          Detect an empty charset.
 void remove(char c)
          Removes a character from set.
 boolean subset(CharSet other)
          Detects if this set within the other.
 java.lang.String toString()
          Compute String representation of charset.
 java.lang.Object union(CharSet other)
          Constructs a charset that is the union of this and other.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

s

protected BitSet s
Constructor Detail

CharSet

public CharSet()
Constructs an empty charset.

Postcondition:
constructs an empty set of characters
Method Detail

add

public void add(char c)
Adds character c to set if not already there.

Parameters:
c - The character to be added to set.
Postcondition:
adds c to set

remove

public void remove(char c)
Removes a character from set. Does nothing if char not in set.

Parameters:
c - The character to be removed.
Postcondition:
removes c from set, if present

contains

public boolean contains(char c)
Detects whether c is a member of this set.

Parameters:
c - The char sought.
Returns:
True iff c is a member of this set.
Postcondition:
returns true iff c in set

clear

public void clear()
Removes the characters of the set.

Postcondition:
removes all characters from set

clone

public java.lang.Object clone()
Construct a duplicate of the character set.

Overrides:
clone in class java.lang.Object
Returns:
Returns a duplicate of this character set.
Postcondition:
constructs a copy of this set

union

public java.lang.Object union(CharSet other)
Constructs a charset that is the union of this and other.

Parameters:
other - The other character set.
Returns:
The result of the union --- contains c if in either set.
Precondition:
other is not null
Postcondition:
returns new set with characters from this or other

intersection

public java.lang.Object intersection(CharSet other)
Computes the intersection of this charset and other.

Parameters:
other - The other character set.
Returns:
The intersection of this and other --- char in result if in both.
Precondition:
other is not null
Postcondition:
returns new set with characters from this and other

difference

public java.lang.Object difference(CharSet other)
Computes the difference between this and other charset.

Parameters:
other - The other character set.
Returns:
the result of difference --- chars in this but not other.
Precondition:
other is not null
Postcondition:
returns new set with characters from this but not other

subset

public boolean subset(CharSet other)
Detects if this set within the other.

Parameters:
other - The potential superset.
Precondition:
other is not null
Postcondition:
returns true if this is a subset of other

isEmpty

public boolean isEmpty()
Detect an empty charset.

Returns:
True if this charset is empty.
Postcondition:
returns true iff set is empty

equals

public boolean equals(java.lang.Object other)
Detect if two sets are equal.

Overrides:
equals in class java.lang.Object
Parameters:
other - The other set.
Returns:
True if this set and other set are identical.
Precondition:
other is not null
Postcondition:
returns true if this contains same values as other

toString

public java.lang.String toString()
Compute String representation of charset.

Overrides:
toString in class java.lang.Object
Returns:
String representing this charset.
Postcondition:
returns string representation of set