Class UnmodifiableMultiSet<E>
- java.lang.Object
-
- org.apache.commons.collections4.collection.AbstractCollectionDecorator<E>
-
- org.apache.commons.collections4.multiset.AbstractMultiSetDecorator<E>
-
- org.apache.commons.collections4.multiset.UnmodifiableMultiSet<E>
-
- Type Parameters:
E- the type held in the multiset
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<E>,java.util.Collection<E>,MultiSet<E>,Unmodifiable
public final class UnmodifiableMultiSet<E> extends AbstractMultiSetDecorator<E> implements Unmodifiable
Decorates anotherMultiSetto ensure it can't be altered.Attempts to modify it will result in an UnsupportedOperationException.
- Since:
- 4.1
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.commons.collections4.MultiSet
MultiSet.Entry<E>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E object)Adds one copy of the specified object to the MultiSet.intadd(E object, int count)Adds a number of occurrences of the specified object to the MultiSet.booleanaddAll(java.util.Collection<? extends E> coll)voidclear()java.util.Set<MultiSet.Entry<E>>entrySet()Returns aSetof all entries contained in the MultiSet.java.util.Iterator<E>iterator()Returns anIteratorover the entire set of members, including copies due to cardinality.booleanremove(java.lang.Object object)Removes one occurrence of the given object from the MultiSet.intremove(java.lang.Object object, int count)Removes a number of occurrences of the specified object from the MultiSet.booleanremoveAll(java.util.Collection<?> coll)Remove all occurrences of all elements from this MultiSet represented in the given collection.booleanremoveIf(java.util.function.Predicate<? super E> filter)booleanretainAll(java.util.Collection<?> coll)Remove any elements of this MultiSet that are not contained in the given collection.intsetCount(E object, int count)Sets the number of occurrences of the specified object in the MultiSet to the given count.java.util.Set<E>uniqueSet()Returns aSetof 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
equals, getCount, hashCode
-
Methods inherited from class org.apache.commons.collections4.collection.AbstractCollectionDecorator
contains, containsAll, isEmpty, size, toArray, toArray, toString
-
Methods inherited from interface java.util.Collection
contains, isEmpty, parallelStream, spliterator, stream, toArray, toArray, toArray
-
Methods inherited from interface org.apache.commons.collections4.MultiSet
containsAll, size
-
-
-
-
Method Detail
-
unmodifiableMultiSet
public static <E> MultiSet<E> unmodifiableMultiSet(MultiSet<? extends E> multiset)
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:
java.lang.NullPointerException- if multiset is null
-
iterator
public java.util.Iterator<E> iterator()
Description copied from interface:MultiSetReturns anIteratorover the entire set of members, including copies due to cardinality. This iterator is fail-fast and will not tolerate concurrent modifications.
-
add
public boolean add(E object)
Description copied from interface:MultiSetAdds 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.
-
addAll
public boolean addAll(java.util.Collection<? extends E> coll)
- Specified by:
addAllin interfacejava.util.Collection<E>- Overrides:
addAllin classAbstractCollectionDecorator<E>
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection<E>- Overrides:
clearin classAbstractCollectionDecorator<E>
-
remove
public boolean remove(java.lang.Object object)
Description copied from interface:MultiSetRemoves one occurrence of the given object from the MultiSet.If the number of occurrences after this operations is reduced to zero, the object will be removed from the
MultiSet.uniqueSet().
-
removeIf
public boolean removeIf(java.util.function.Predicate<? super E> filter)
- Specified by:
removeIfin interfacejava.util.Collection<E>- Overrides:
removeIfin classAbstractCollectionDecorator<E>- Since:
- 4.4
-
removeAll
public boolean removeAll(java.util.Collection<?> coll)
Description copied from interface:MultiSetRemove all occurrences of all elements from this MultiSet represented in the given collection.
-
retainAll
public boolean retainAll(java.util.Collection<?> coll)
Description copied from interface:MultiSetRemove any elements of this MultiSet that are not contained in the given collection.
-
setCount
public int setCount(E object, int count)
Description copied from interface:MultiSetSets 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:
setCountin interfaceMultiSet<E>- Overrides:
setCountin 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
-
add
public int add(E object, int count)
Description copied from interface:MultiSetAdds 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:
addin interfaceMultiSet<E>- Overrides:
addin 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
-
remove
public int remove(java.lang.Object object, int count)Description copied from interface:MultiSetRemoves 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:
removein interfaceMultiSet<E>- Overrides:
removein 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
-
uniqueSet
public java.util.Set<E> uniqueSet()
Description copied from interface:MultiSetReturns aSetof 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.
-
entrySet
public java.util.Set<MultiSet.Entry<E>> entrySet()
Description copied from interface:MultiSetReturns aSetof 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.
-
-