All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.roguewave.tools.v2-0.Bag

java.lang.Object
   |
   +----com.roguewave.tools.v2-0.CollectionBase
           |
           +----com.roguewave.tools.v2-0.Bag

public class Bag
extends CollectionBase
implements Cloneable, Serializable
Class Bag represents a group of unordered elements. Although duplicate entries are allowed, the implementation holds only a single reference for each group of objects that compare equal to each other. With each reference, the implementation maintains a tally of the number of such elements that have been inserted into the Bag. Thus this collection is an efficient way to store large numbers of objects of which only some smaller number are unique.

Equality of objects is determined by using the hashCode() and equals(Object) methods inherited or overridden from class Object.


Constructor Index

 o Bag()
Creates an empty bag with default capacity.
 o Bag(int)
Creates an empty bag with a given initial capacity.

Method Index

 o clear()
Removes all items from the collection
 o clone()
Returns a clone of this bag.
 o contains(Object)
Checks the bag for an element that compares equal to the given item.
 o elements()
Returns an Enumeration object, which can be used to visit each element of the collection in turn.
 o find(Object)
Returns the original element equal to the given item that was inserted into the bag, or null if no such element is found.
 o insert(Object)
Increments the tally of the element equal to the given item, or adds the item to the bag with a tally of 1 if no such element is found.
 o insertWithOccurrences(Object, int)
Adds a given count to the tally of the element equal to the given item, or adds the item to the bag with that count if no such element is found.
 o occurrencesOf(Object)
Returns the number of elements in the collection equal to to the given item.
 o remove(Object)
Decrements the tally of the element in the bag equal to the given item.
 o removeAll(Object)
Removes from the collection all elements that are equal to the given item.
 o toString()
Converts this bag into a string of the form:
   "[<elem1 | tally1>, <elem2 | tally2>, ..., <elemN | tallyN>]"
 

Constructors

 o Bag
 public Bag()
Creates an empty bag with default capacity.

 o Bag
 public Bag(int n)
Creates an empty bag with a given initial capacity.

Parameters:
n - The initial capacity of the underlying Hashtable, which will contain one entry for each unique element of the bag

Methods

 o clear
 public synchronized void clear()
Removes all items from the collection

Overrides:
clear in class CollectionBase
 o clone
 public synchronized Object clone()
Returns a clone of this bag. Note that the elements themselves are not cloned.

Overrides:
clone in class Object
 o contains
 public boolean contains(Object item)
Checks the bag for an element that compares equal to the given item.

Returns:
true if such an element is found, false otherwise
Overrides:
contains in class CollectionBase
 o find
 public Object find(Object item)
Returns the original element equal to the given item that was inserted into the bag, or null if no such element is found.

Overrides:
find in class CollectionBase
 o insert
 public synchronized Object insert(Object item)
Increments the tally of the element equal to the given item, or adds the item to the bag with a tally of 1 if no such element is found.

Returns:
The element that was added.
Overrides:
insert in class CollectionBase
 o insertWithOccurrences
 public synchronized Object insertWithOccurrences(Object item,
                                                  int n)
Adds a given count to the tally of the element equal to the given item, or adds the item to the bag with that count if no such element is found.

Returns:
The element that was added or had its tally incremented
 o elements
 public synchronized Enumeration elements()
Returns an Enumeration object, which can be used to visit each element of the collection in turn. Note that an element with a tally of k will be visited k times.

Overrides:
elements in class CollectionBase
 o occurrencesOf
 public int occurrencesOf(Object item)
Returns the number of elements in the collection equal to to the given item. That is, the tally of the element in the bag that is equal to item, or 0 if no such element is found.

Overrides:
occurrencesOf in class CollectionBase
 o remove
 public synchronized Object remove(Object item)
Decrements the tally of the element in the bag equal to the given item. The element will be removed completely if the tally becomes zero. The method does nothing if no such element is found.

Returns:
The element whose count is decremented, or null if no such element is found.
Overrides:
remove in class CollectionBase
 o removeAll
 public synchronized int removeAll(Object item)
Removes from the collection all elements that are equal to the given item. That is, an element in the bag that is equal to item will be removed completely, regardless of its tally. The method does nothing if no such element if found.

Returns:
The number of elements removed
Overrides:
removeAll in class CollectionBase
 o toString
 public synchronized String toString()
Converts this bag into a string of the form:
   "[<elem1 | tally1>, <elem2 | tally2>, ..., <elemN | tallyN>]"
 

Overrides:
toString in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index