com.ideanest.util
Class CountingBag
java.lang.Object
|
+--java.util.AbstractCollection
|
+--com.ideanest.util.CountingBag
- All Implemented Interfaces:
- java.lang.Cloneable, java.util.Collection, java.io.Serializable
- public class CountingBag
- extends java.util.AbstractCollection
- implements java.lang.Cloneable, java.io.Serializable
A bag implemented using a map of elements to quantities. If multiple
equal objects are added, any one instance will be retained; the rest
will be merely counted. When iterating, the instance retained will be
returned multiple times, according to the count.
- Version:
- 1.1, 2002-03-10
- Author:
- Piotr Kaminski (piotr@ideanest.com)
- See Also:
- Serialized Form
Method Summary |
boolean |
add(java.lang.Object o)
|
boolean |
add(java.lang.Object o,
int n)
|
void |
clear()
|
java.lang.Object |
clone()
|
boolean |
contains(java.lang.Object o)
|
int |
count(java.lang.Object o)
|
java.util.Iterator |
iterator()
|
boolean |
remove(java.lang.Object o)
|
int |
remove(java.lang.Object o,
int n)
|
boolean |
removeAll(java.util.Collection c)
|
boolean |
retainAll(java.util.Collection c)
|
int |
size()
|
java.util.Set |
toSet()
|
Methods inherited from class java.util.AbstractCollection |
addAll, containsAll, isEmpty, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Collection |
equals, hashCode |
CountingBag
public CountingBag()
CountingBag
public CountingBag(java.util.Collection c)
CountingBag
public CountingBag(java.util.Map base)
add
public boolean add(java.lang.Object o)
- Specified by:
add in interface java.util.Collection - Overrides:
add in class java.util.AbstractCollection
add
public boolean add(java.lang.Object o,
int n)
clear
public void clear()
- Specified by:
clear in interface java.util.Collection - Overrides:
clear in class java.util.AbstractCollection
clone
public java.lang.Object clone()
- Overrides:
clone in class java.lang.Object
contains
public boolean contains(java.lang.Object o)
- Specified by:
contains in interface java.util.Collection - Overrides:
contains in class java.util.AbstractCollection
count
public int count(java.lang.Object o)
iterator
public java.util.Iterator iterator()
- Specified by:
iterator in interface java.util.Collection - Specified by:
iterator in class java.util.AbstractCollection
remove
public boolean remove(java.lang.Object o)
- Specified by:
remove in interface java.util.Collection - Overrides:
remove in class java.util.AbstractCollection
remove
public int remove(java.lang.Object o,
int n)
removeAll
public boolean removeAll(java.util.Collection c)
- Specified by:
removeAll in interface java.util.Collection - Overrides:
removeAll in class java.util.AbstractCollection
retainAll
public boolean retainAll(java.util.Collection c)
- Specified by:
retainAll in interface java.util.Collection - Overrides:
retainAll in class java.util.AbstractCollection
size
public int size()
- Specified by:
size in interface java.util.Collection - Specified by:
size in class java.util.AbstractCollection
toSet
public java.util.Set toSet()
|