Defines a collection that counts the number of times an object appears in the collection.
Suppose you have a Bag that contains {a, a, b, c}
. Calling {@link #getCount(Object)} on a
would return 2, whilecalling {@link #uniqueSet()} would return {a, b, c}
.
NOTE: This interface violates the {@link Collection} contract.The behavior specified in many of these methods is not the same as the behavior specified by Collection
. The noncompliant methods are clearly marked with "(Violation)". Exercise caution when using a bag as a Collection
.
This violation resulted from the original specification of this interface. In an ideal world, the interface would be changed to fix the problems, however it has been decided to maintain backwards compatibility instead.
@param < E> the type held in the bag
@since 2.0
@version $Id: Bag.java 1477779 2013-04-30 18:55:24Z tn $