public class SingleSetAsBag<E> extends java.lang.Object implements Bag<E>
Set
as a Bag
. If the set's Collection.contains(Object)
operation is fast then so will be this bag's contains(Object)
operation.
According to the specification of Bag
, all modifying operations throw an
UnsupportedOperationException
.
The underlying Set
, however, can be obtained using getWrappedSet()
and
modified. As the iterator()
on this bag is obtained from the underlying set,
modifications to the set while iterating over this bag will cause a
ConcurrentModificationException
.
Constructor and Description |
---|
SingleSetAsBag(java.util.Set<E> set) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E o) |
boolean |
addAll(java.util.Collection<? extends E> c) |
void |
clear() |
boolean |
contains(java.lang.Object o) |
boolean |
containsAll(java.util.Collection<?> c) |
int |
count(java.lang.Object o)
Queries how many times the specified object occurs in me.
|
java.util.Set<E> |
getWrappedSet() |
boolean |
isEmpty() |
java.util.Iterator<E> |
iterator() |
boolean |
remove(java.lang.Object o) |
boolean |
removeAll(java.util.Collection<?> c) |
boolean |
retainAll(java.util.Collection<?> c) |
int |
size() |
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
public SingleSetAsBag(java.util.Set<E> set)
set
- must not be null
, or else, a NullPointerException
will be thrown.public java.util.Set<E> getWrappedSet()
public int size()
size
in interface java.util.Collection<E>
public boolean isEmpty()
isEmpty
in interface java.util.Collection<E>
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection<E>
public java.util.Iterator<E> iterator()
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<E>
public <T> T[] toArray(T[] a)
toArray
in interface java.util.Collection<E>
public boolean remove(java.lang.Object o)
remove
in interface java.util.Collection<E>
public boolean containsAll(java.util.Collection<?> c)
containsAll
in interface java.util.Collection<E>
public boolean addAll(java.util.Collection<? extends E> c)
addAll
in interface java.util.Collection<E>
public boolean removeAll(java.util.Collection<?> c)
removeAll
in interface java.util.Collection<E>
public boolean retainAll(java.util.Collection<?> c)
retainAll
in interface java.util.Collection<E>
public void clear()
clear
in interface java.util.Collection<E>
public int count(java.lang.Object o)
Bag