Class CharBagI

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

public class CharBagI
extends AbstractCollection

CharBagI.java Created: Thur Jan 30 2003

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

Author:
Stuart C. Shapiro

Constructor Summary
CharBagI()
          Creates a new empty CharBagI instance.
CharBagI(StringBuffer b)
          Creates a new CharBagI 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(CharBagI 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()
          Creates and returns a new iterator for this CharBagI.
static void main(String[] args)
           
 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

CharBagI

public CharBagI()
Creates a new empty CharBagI instance.


CharBagI

public CharBagI(StringBuffer b)
Creates a new CharBagI 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(CharBagI b)
Tests whether this bag and b have the same characters the same number of times.

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

iterator

public Iterator iterator()
Creates and returns a new iterator for this CharBagI.

Specified by:
iterator in interface Collection
Specified by:
iterator in class AbstractCollection
Returns:
An iterator for this CharBagI.

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.

main

public static void main(String[] args)