Class CharBag

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--CharBag
All Implemented Interfaces:
Collection

public class CharBag
extends AbstractCollection

CharBag.java Created: Mon Jan 20 13:03:08 2003

A bag of characters, i.e., an unordered collection of characters, that may contain some character some number of times.

Author:
Stuart C. Shapiro

Constructor Summary
CharBag()
          Creates a new empty CharBag instance.
CharBag(StringBuffer b)
          Creates a new CharBag instance containing all the chars of b.
 
Method Summary
 boolean add(char c)
          Adds c to this bag of characters.
 boolean contains(char c)
          Tests if c is in this bag of characters.
 boolean equals(CharBag b)
          Tests whether this bag and b have the same characters the same number of times.
 boolean isEmpty()
          Tests if this bag of characters is empty
 Iterator iterator()
          Not yet implemented.
 boolean remove(char c)
          Removes char from this bag of characters.
 int size()
          Returns the number of characters in this bag of characters.
 String toString()
          Converts this bag of characters to a string.
 
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

CharBag

public CharBag()
Creates a new empty CharBag instance.


CharBag

public CharBag(StringBuffer b)
Creates a new CharBag instance containing all the chars of b.

Parameters:
b - a StringBuffer value
Method Detail

add

public boolean add(char c)
Adds c to this bag of characters.

Parameters:
c - a char value
Returns:
true

remove

public boolean remove(char c)
Removes char from this bag of characters.

post: this == this@pre->excluding(c)

Parameters:
c - a char value
Returns:
true if c was in this@pre; false otherwise

contains

public boolean contains(char c)
Tests if c is in this bag of characters.

Parameters:
c - a char value
Returns:
true if this->includes(c), else false

isEmpty

public boolean isEmpty()
Tests if this bag of characters is empty

Specified by:
isEmpty in interface Collection
Overrides:
isEmpty in class AbstractCollection
Returns:
true if this is empty, else false

size

public int size()
Returns the number of characters in this bag of characters.

Specified by:
size in interface Collection
Specified by:
size in class AbstractCollection
Returns:
the number of characters in this bag of characters.

equals

public boolean equals(CharBag b)
Tests whether this bag and b have the same characters the same number of times.

Parameters:
b - a CharBag value
Returns:
true if this bag and b have the same characters the same number of times. else false

iterator

public Iterator iterator()
Not yet implemented.

Specified by:
iterator in interface Collection
Specified by:
iterator in class AbstractCollection

toString

public String toString()
Converts this bag of characters to a string.

Overrides:
toString in class AbstractCollection
Returns:
a String representation of this bag of characters.