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.
-
Bag()
- Creates an empty bag with default capacity.
-
Bag(int)
- Creates an empty bag with a given initial capacity.
-
clear()
- Removes all items from the collection
-
clone()
- Returns a clone of this bag.
-
contains(Object)
- Checks the bag for an element that compares equal to
the given item.
-
elements()
- Returns an Enumeration object, which can be used to visit
each element of the collection in turn.
-
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.
-
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.
-
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.
-
occurrencesOf(Object)
- Returns the number of elements in the collection equal to
to the given item.
-
remove(Object)
- Decrements the tally of the element in the bag equal to
the given item.
-
removeAll(Object)
- Removes from the collection all elements that are equal to the given
item.
-
toString()
- Converts this bag into a string of the form:
"[<elem1 | tally1>, <elem2 | tally2>, ..., <elemN | tallyN>]"
Bag
public Bag()
- Creates an empty bag with default capacity.
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
clear
public synchronized void clear()
- Removes all items from the collection
- Overrides:
- clear in class CollectionBase
clone
public synchronized Object clone()
- Returns a clone of this bag. Note that the elements
themselves are not cloned.
- Overrides:
- clone in class Object
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
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
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
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
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
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
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
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
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