//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Example 5.8 on page 101
//  Testing the add() method for the Bag class

  public boolean equals(Object object)
  { // returns true iff the given object is a Bag
    // and has the same content as this bag
    if (object == this) return true;
    if (object.getClass() != this.getClass()) return false;
    if (object.hashCode() != this.hashCode()) return false;
    Collection collection = (Collection)object;
    if (collection.size() != this.size()) return false;
    if (!collection.containsAll(this)) return false;
    if (!this.containsAll(collection)) return false;
    for (int i=0; i<size; i++)
    { Object x = objects[i];
      if (frequency(collection,x) != frequency(this,x))
        return false;
    }
    return true;
  }
  