UC Berkeley Group for User Interface Research
Updated November 17, 2000

edu.berkeley.guir.lib.collection
Class HashBag

java.lang.Object
  |
  +--edu.berkeley.guir.lib.collection.HashBag

public class HashBag
extends Object

A bag collection backed by a HashMap.

This software is distributed under the Berkeley Software License.

 Revisions:  - GUIRLib-v1.0-1.0.0, Dec 07 1999, JH
               Created class
             - GUIRLib-v1.2-1.0.0, Jun 22 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.3-1.0.0, Aug 11 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.4-1.0.0, Aug 31 2000, JH
               Touched for GUIRLib release
 

Since:
JDK 1.3beta
Version:
GUIRLib-v1.4-1.0.0, Aug 31 2000
Author:
(jasonh@cs.berkeley.edu)

Constructor Summary
HashBag()
           
 
Method Summary
 int add(Object obj)
           
 void clear()
          Clear out all elements in the bag.
 boolean contains(Object obj)
          See if the bag contains the specified object.
 boolean isEmpty()
          See if the bag is empty.
 boolean isEmpty(Object obj)
          See if the bag contains any of this object.
 Iterator iterator()
          Iterate over everything in the bag.
 Set keySet()
          Get the set of elements.
 int remove(Object obj)
          Remove an object from the bag.
 int size()
          Get the total number of objects in the bag.
 int size(Object obj)
          Get the number of instances of this object contained in the bag.
 int sizeKeySet()
          Get the number of unique objects in the bag.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HashBag

public HashBag()
Method Detail

add

public int add(Object obj)
Returns:
the current number of items of the item passed in.

clear

public void clear()
Clear out all elements in the bag.

contains

public boolean contains(Object obj)
See if the bag contains the specified object.

isEmpty

public boolean isEmpty()
See if the bag is empty.

isEmpty

public boolean isEmpty(Object obj)
See if the bag contains any of this object.

iterator

public Iterator iterator()
Iterate over everything in the bag. If an element is in here multiple times, it gets returned multiple times. If you only want unique elements, call keySet() and get the iterator from that.

This implementation gives a deferred ConcurrentModification exception if you modify the bag while iterating. That is, it won't throw the exception until you get to the next bunch of elements. For example, if you were iterating over the bag {'A'=4, 'B'=3}, modifying the bag won't throw an exception until you go from 'A' to 'B'.


keySet

public Set keySet()
Get the set of elements.

remove

public int remove(Object obj)
Remove an object from the bag.

size

public int size()
Get the total number of objects in the bag.

sizeKeySet

public int sizeKeySet()
Get the number of unique objects in the bag.

size

public int size(Object obj)
Get the number of instances of this object contained in the bag.

toString

public String toString()
Overrides:
toString in class Object

Copyright Information