© 1998-2002 McGraw-Hill

structure
Class CharSet

java.lang.Object
  |
  +--structure.CharSet

public class CharSet
extends 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. This class's interface differs from the Set, java.util.Bitset, and Set interfaces, so care must be taken to invoke the proper methods.

See Also:
BitSet, java.util.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.
 Object clone()
          Construct a duplicate of the character set.
 boolean contains(char c)
          Detects whether c is a member of this set.
 Object difference(CharSet other)
          Computes the difference between this and other charset.
 boolean equals(Object other)
          Detect if two sets are equal.
 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.
 String toString()
          Compute String representation of charset.
 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, registerNatives, wait, wait, wait
 

Field Detail

s

protected BitSet s
Constructor Detail

CharSet

public CharSet()
Constructs an empty charset.
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.
Postcondition:
returns true iff c in set
Returns:
True iff c is a member of this set.

clear

public void clear()
Removes the characters of the set.
Postcondition:
removes all characters from set

clone

public Object clone()
Construct a duplicate of the character set.
Overrides:
clone in class Object
Postcondition:
constructs a copy of this set
Returns:
Returns a duplicate of this character set.

union

public Object union(CharSet other)
Constructs a charset that is the union of this and other.
Parameters:
other - The other character set.
Precondition:
other is not null
Postcondition:
returns new set with characters from this or other
Returns:
The result of the union --- contains c if in either set.

intersection

public Object intersection(CharSet other)
Computes the intersection of this charset and other.
Parameters:
other - The other character set.
Precondition:
other is not null
Postcondition:
returns new set with characters from this and other
Returns:
The intersection of this and other --- char in result if in both.

difference

public Object difference(CharSet other)
Computes the difference between this and other charset.
Parameters:
other - The other character set.
Precondition:
other is not null
Postcondition:
returns new set with characters from this but not other
Returns:
the result of difference --- chars in 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.
Postcondition:
returns true iff set is empty
Returns:
True if this charset is empty.

equals

public boolean equals(Object other)
Detect if two sets are equal.
Overrides:
equals in class Object
Parameters:
other - The other set.
Precondition:
other is not null
Postcondition:
returns true if this contains same values as other
Returns:
True if this set and other set are identical.

toString

public String toString()
Compute String representation of charset.
Overrides:
toString in class Object
Postcondition:
returns string representation of set
Returns:
String representing this charset.

© 1998-2002 McGraw-Hill