Index: src/java/org/apache/commons/collections/AbstractBag.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/collections/src/java/org/apache/commons/collections/AbstractBag.java,v
retrieving revision 1.1
diff -u -r1.1 AbstractBag.java
--- src/java/org/apache/commons/collections/AbstractBag.java	29 Aug 2001 15:28:07 -0000	1.1
+++ src/java/org/apache/commons/collections/AbstractBag.java	10 Feb 2002 05:16:58 -0000
@@ -63,6 +63,7 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.ConcurrentModificationException;
 import java.util.Iterator;
 import java.util.List;
@@ -73,8 +74,12 @@
 /**
  * This class provides a skeletal implementation of the {@link Bag}
  * interface to minimize the effort required for target implementations.
+ * Subclasses need only to call {@link #setMap(Map)} in their constructor 
+ * specifying a map instance that will be used to store the contents of 
+ * the bag. 
  *
  * @author Chuck Burdick
+ * @author <a href="michael@iammichael.org">Michael Smith</a>
  **/
 public abstract class AbstractBag implements Bag {
    private Map _map = null;
@@ -91,7 +96,7 @@
          int count = (i + getCount(o));
          _map.put(o, new Integer(count));
          _total += i;
-         return (getCount(o) == i);
+         return (count == i);
       } else {
          return false;
       }
@@ -139,13 +144,9 @@
    }
 
    public boolean equals(Object o) {
-      boolean result = false;
-      if (o instanceof AbstractBag) {
-         result = _map.equals(((AbstractBag)o).getMap());
-      } else if (o instanceof Map) {
-         result = _map.equals((Map)o);
-      }
-      return result;
+      return (o == this || 
+              (o != null && o.getClass().equals(this.getClass()) &&
+               ((AbstractBag)o)._map.equals(this._map)));
    }
 
    public int hashCode() {
@@ -203,12 +204,15 @@
       _mods++;
       boolean result = false;
       int count = getCount(o);
-      if (count > i) {
+      if (i <= 0) {
+         result = false;
+      } else if (count > i) {
          _map.put(o, new Integer(count - i));
          result = true;
          _total -= i;
-      } else {
-         result = uniqueSet().remove(o);
+      } else { // count > 0 && count <= i  
+         // need to remove all
+         result = (_map.remove(o) != null);
          _total -= count;
       }
       return result;
@@ -274,7 +278,7 @@
    }
 
    public Set uniqueSet() {
-      return _map.keySet();
+      return Collections.unmodifiableSet(_map.keySet());
    }
 
    public int size() {
@@ -316,7 +320,7 @@
       Iterator i = uniqueSet().iterator();
       while (i.hasNext()) {
          Object current = i.next();
-         for (int index = 0; index < getCount(current); index++) {
+         for (int index = getCount(current); index > 0; index--) {
             result.add(current);
          }
       }

