E
- the type held in the multisetpublic final class UnmodifiableMultiSet<E> extends AbstractMultiSetDecorator<E> implements Unmodifiable
MultiSet
to ensure it can't be altered.
Attempts to modify it will result in an UnsupportedOperationException.
MultiSet.Entry<E>
Modifier and Type | Method and Description |
---|---|
boolean |
add(E object)
Adds one copy of the specified object to the MultiSet.
|
int |
add(E object,
int count)
Adds a number of occurrences of the specified object to the MultiSet.
|
boolean |
addAll(Collection<? extends E> coll) |
void |
clear() |
Set<MultiSet.Entry<E>> |
entrySet()
Returns a
Set of all entries contained in the MultiSet. |
Iterator<E> |
iterator()
Returns an
Iterator over the entire set of members,
including copies due to cardinality. |
boolean |
remove(Object object)
Removes one occurrence of the given object from the MultiSet.
|
int |
remove(Object object,
int count)
Removes a number of occurrences of the specified object from the MultiSet.
|
boolean |
removeAll(Collection<?> coll)
Remove all occurrences of all elements from this MultiSet represented
in the given collection.
|
boolean |
retainAll(Collection<?> coll)
Remove any elements of this MultiSet that are not contained in the
given collection.
|
int |
setCount(E object,
int count)
Sets the number of occurrences of the specified object in the MultiSet
to the given count.
|
Set<E> |
uniqueSet()
Returns a
Set of unique elements in the MultiSet. |
static <E> MultiSet<E> |
unmodifiableMultiSet(MultiSet<? extends E> multiset)
Factory method to create an unmodifiable multiset.
|
decorated, equals, getCount, hashCode
contains, containsAll, isEmpty, setCollection, size, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
containsAll, size
contains, isEmpty, parallelStream, removeIf, spliterator, stream, toArray, toArray
public static <E> MultiSet<E> unmodifiableMultiSet(MultiSet<? extends E> multiset)
If the multiset passed in is already unmodifiable, it is returned.
E
- the type of the elements in the multisetmultiset
- the multiset to decorate, may not be nullNullPointerException
- if multiset is nullpublic Iterator<E> iterator()
MultiSet
Iterator
over the entire set of members,
including copies due to cardinality. This iterator is fail-fast
and will not tolerate concurrent modifications.public boolean add(E object)
MultiSet
If the object is already in the MultiSet.uniqueSet()
then increment its
count as reported by MultiSet.getCount(Object)
. Otherwise add it to the
MultiSet.uniqueSet()
and report its count as 1.
add
in interface Collection<E>
add
in interface MultiSet<E>
add
in class AbstractCollectionDecorator<E>
object
- the object to addtrue
always, as the size of the MultiSet is increased
in any casepublic boolean addAll(Collection<? extends E> coll)
addAll
in interface Collection<E>
addAll
in class AbstractCollectionDecorator<E>
public void clear()
clear
in interface Collection<E>
clear
in class AbstractCollectionDecorator<E>
public boolean remove(Object object)
MultiSet
If the number of occurrences after this operations is reduced
to zero, the object will be removed from the MultiSet.uniqueSet()
.
remove
in interface Collection<E>
remove
in interface MultiSet<E>
remove
in class AbstractCollectionDecorator<E>
object
- the object to removetrue
if this call changed the collectionpublic boolean removeAll(Collection<?> coll)
MultiSet
removeAll
in interface Collection<E>
removeAll
in interface MultiSet<E>
removeAll
in class AbstractCollectionDecorator<E>
coll
- the collection of elements to removetrue
if this call changed the multisetpublic boolean retainAll(Collection<?> coll)
MultiSet
retainAll
in interface Collection<E>
retainAll
in interface MultiSet<E>
retainAll
in class AbstractCollectionDecorator<E>
coll
- the collection of elements to retaintrue
if this call changed the multisetpublic int setCount(E object, int count)
MultiSet
If the provided count is zero, the object will be removed from the
MultiSet.uniqueSet()
.
setCount
in interface MultiSet<E>
setCount
in class AbstractMultiSetDecorator<E>
object
- the object to updatecount
- the number of occurrences of the objectpublic int add(E object, int count)
MultiSet
If the object is already in the MultiSet.uniqueSet()
then increment its
count as reported by MultiSet.getCount(Object)
. Otherwise add it to the
MultiSet.uniqueSet()
and report its count as occurrences
.
add
in interface MultiSet<E>
add
in class AbstractMultiSetDecorator<E>
object
- the object to addcount
- the number of occurrences to add, may be zero,
in which case no change is made to the multisetpublic int remove(Object object, int count)
MultiSet
If the number of occurrences to remove is greater than the actual number of occurrences in the multiset, the object will be removed from the multiset.
remove
in interface MultiSet<E>
remove
in class AbstractMultiSetDecorator<E>
object
- the object to removecount
- the number of occurrences to remove, may be zero,
in which case no change is made to the multisetpublic Set<E> uniqueSet()
MultiSet
Set
of unique elements in the MultiSet.
Uniqueness constraints are the same as those in Set
.
The returned set is backed by this multiset, so any change to either is immediately reflected in the other. Only removal operations are supported, in which case all occurrences of the element are removed from the backing multiset.
Copyright © 2001–2018 The Apache Software Foundation. All rights reserved.