Class UnmodifiableMultiSet<E>
- Type Parameters:
E
- the type held in the multiset
- All Implemented Interfaces:
Serializable
,Iterable<E>
,Collection<E>
,MultiSet<E>
,Unmodifiable
MultiSet
to ensure it can't be altered.
Attempts to modify it will result in an UnsupportedOperationException.
- Since:
- 4.1
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.commons.collections4.MultiSet
MultiSet.Entry<E>
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds one copy of the specified object to the MultiSet.int
Adds a number of occurrences of the specified object to the MultiSet.boolean
addAll
(Collection<? extends E> coll) void
clear()
entrySet()
Returns aSet
of all entries contained in the MultiSet.iterator()
Returns anIterator
over the entire set of members, including copies due to cardinality.boolean
Removes one occurrence of the given object from the MultiSet.int
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
boolean
retainAll
(Collection<?> coll) Remove any elements of this MultiSet that are not contained in the given collection.int
Sets the number of occurrences of the specified object in the MultiSet to the given count.Returns aSet
of unique elements in the MultiSet.static <E> MultiSet
<E> unmodifiableMultiSet
(MultiSet<? extends E> multiset) Factory method to create an unmodifiable multiset.Methods inherited from class org.apache.commons.collections4.multiset.AbstractMultiSetDecorator
decorated, equals, getCount, hashCode
Methods inherited from class org.apache.commons.collections4.collection.AbstractCollectionDecorator
contains, containsAll, isEmpty, setCollection, size, toArray, toArray, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
contains, isEmpty, parallelStream, spliterator, stream, toArray, toArray
Methods inherited from interface org.apache.commons.collections4.MultiSet
containsAll, size
-
Method Details
-
unmodifiableMultiSet
Factory method to create an unmodifiable multiset.If the multiset passed in is already unmodifiable, it is returned.
- Type Parameters:
E
- the type of the elements in the multiset- Parameters:
multiset
- the multiset to decorate, may not be null- Returns:
- an unmodifiable MultiSet
- Throws:
NullPointerException
- if multiset is null
-
add
Description copied from interface:MultiSet
Adds one copy of the specified object to the MultiSet.If the object is already in the
MultiSet.uniqueSet()
then increment its count as reported byMultiSet.getCount(Object)
. Otherwise, add it to theMultiSet.uniqueSet()
and report its count as 1.- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceMultiSet<E>
- Overrides:
add
in classAbstractCollectionDecorator<E>
- Parameters:
object
- the object to add- Returns:
true
always, as the size of the MultiSet is increased in any case
-
add
Description copied from interface:MultiSet
Adds a number of occurrences of the specified object to the MultiSet.If the object is already in the
MultiSet.uniqueSet()
then increment its count as reported byMultiSet.getCount(Object)
. Otherwise, add it to theMultiSet.uniqueSet()
and report its count asoccurrences
.- Specified by:
add
in interfaceMultiSet<E>
- Overrides:
add
in classAbstractMultiSetDecorator<E>
- Parameters:
object
- the object to addcount
- the number of occurrences to add, may be zero, in which case no change is made to the multiset- Returns:
- the number of occurrences of the object in the multiset before this operation; possibly zero
-
addAll
- Specified by:
addAll
in interfaceCollection<E>
- Overrides:
addAll
in classAbstractCollectionDecorator<E>
-
clear
- Specified by:
clear
in interfaceCollection<E>
- Overrides:
clear
in classAbstractCollectionDecorator<E>
-
entrySet
Description copied from interface:MultiSet
Returns aSet
of all entries contained in the MultiSet.The returned set is backed by this multiset, so any change to either is immediately reflected in the other.
-
iterator
Description copied from interface:MultiSet
Returns anIterator
over the entire set of members, including copies due to cardinality. This iterator is fail-fast and will not tolerate concurrent modifications. -
remove
Description copied from interface:MultiSet
Removes one occurrence of the given object from the MultiSet.If the number of occurrences after this operation is reduced to zero, the object will be removed from the
MultiSet.uniqueSet()
.- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceMultiSet<E>
- Overrides:
remove
in classAbstractCollectionDecorator<E>
- Parameters:
object
- the object to remove- Returns:
true
if this call changed the collection
-
remove
Description copied from interface:MultiSet
Removes a number of occurrences of the specified object from the 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.
- Specified by:
remove
in interfaceMultiSet<E>
- Overrides:
remove
in classAbstractMultiSetDecorator<E>
- Parameters:
object
- the object to removecount
- the number of occurrences to remove, may be zero, in which case no change is made to the multiset- Returns:
- the number of occurrences of the object in the multiset before the operation; possibly zero
-
removeAll
Description copied from interface:MultiSet
Remove all occurrences of all elements from this MultiSet represented in the given collection.- Specified by:
removeAll
in interfaceCollection<E>
- Specified by:
removeAll
in interfaceMultiSet<E>
- Overrides:
removeAll
in classAbstractCollectionDecorator<E>
- Parameters:
coll
- the collection of elements to remove- Returns:
true
if this call changed the multiset
-
removeIf
- Specified by:
removeIf
in interfaceCollection<E>
- Overrides:
removeIf
in classAbstractCollectionDecorator<E>
- Since:
- 4.4
-
retainAll
Description copied from interface:MultiSet
Remove any elements of this MultiSet that are not contained in the given collection.- Specified by:
retainAll
in interfaceCollection<E>
- Specified by:
retainAll
in interfaceMultiSet<E>
- Overrides:
retainAll
in classAbstractCollectionDecorator<E>
- Parameters:
coll
- the collection of elements to retain- Returns:
true
if this call changed the multiset
-
setCount
Description copied from interface:MultiSet
Sets the number of occurrences of the specified object in the MultiSet to the given count.If the provided count is zero, the object will be removed from the
MultiSet.uniqueSet()
.- Specified by:
setCount
in interfaceMultiSet<E>
- Overrides:
setCount
in classAbstractMultiSetDecorator<E>
- Parameters:
object
- the object to updatecount
- the number of occurrences of the object- Returns:
- the number of occurrences of the object before this operation, zero if the object was not contained in the multiset
-
uniqueSet
Description copied from interface:MultiSet
Returns aSet
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.
-