Top Description Fields Constructors Methods
org.apache.commons.collections4.multiset

public final Class UnmodifiableMultiSet<E>

extends AbstractMultiSetDecorator<E>
implements Unmodifiable
Class Inheritance
All Implemented Interfaces
org.apache.commons.collections4.Unmodifiable
Type Parameters
<E>
the type held in the multiset
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, java.util.Collection, .Iterator, .Set, java.util.function.Predicate, org.apache.commons.collections4.MultiSet, .Unmodifiable, org.apache.commons.collections4.iterators.UnmodifiableIterator, org.apache.commons.collections4.set.UnmodifiableSet

Decorates another MultiSet to ensure it can't be altered.

Attempts to modify it will result in an UnsupportedOperationException.

Since
4.1

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
private
UnmodifiableMultiSet(final MultiSet<? extends E>
the multiset to decorate, may not be null
multiset
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
public boolean
add(final E
the object to add
object
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.add.

Implements org.apache.commons.collections4.MultiSet.add, java.util.Collection.add.

Adds one copy of the specified object to the MultiSet.
public int
add(final E
the object to add
object
,
final int
the number of occurrences to add, may be zero, in which case no change is made to the multiset
count
)

Overrides org.apache.commons.collections4.multiset.AbstractMultiSetDecorator.add.

Implements org.apache.commons.collections4.MultiSet.add.

Adds a number of occurrences of the specified object to the MultiSet.
public boolean
addAll(final Collection<? extends E>
collection containing elements to be added to this collection
coll
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.addAll.

Implements java.util.Collection.addAll.

Adds all of the elements in the specified collection to this collection (optional operation).
public void
clear()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.clear.

Implements java.util.Collection.clear.

Removes all of the elements from this collection (optional operation).
public Set<MultiSet.Entry<E>>
public Iterator<E>
private void
readObject(final ObjectInputStream
the input stream
in
)

Read the collection in using a custom routine.

public boolean
remove(final Object
the object to remove
object
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.remove.

Implements org.apache.commons.collections4.MultiSet.remove, java.util.Collection.remove.

Removes one occurrence of the given object from the MultiSet.
public int
remove(final Object
the object to remove
object
,
final int
the number of occurrences to remove, may be zero, in which case no change is made to the multiset
count
)

Overrides org.apache.commons.collections4.multiset.AbstractMultiSetDecorator.remove.

Implements org.apache.commons.collections4.MultiSet.remove.

Removes a number of occurrences of the specified object from the MultiSet.
public boolean
removeAll(final Collection<?>
the collection of elements to remove
coll
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.removeAll.

Implements org.apache.commons.collections4.MultiSet.removeAll, java.util.Collection.removeAll.

Remove all occurrences of all elements from this MultiSet represented in the given collection.
public boolean
removeIf(Predicate<? super E>
a predicate which returns true for elements to be removed
filter
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.removeIf.

Overrides default java.util.Collection.removeIf.

Removes all of the elements of this collection that satisfy the given predicate.
public boolean
retainAll(final Collection<?>
the collection of elements to retain
coll
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.retainAll.

Implements org.apache.commons.collections4.MultiSet.retainAll, java.util.Collection.retainAll.

Remove any elements of this MultiSet that are not contained in the given collection.
public int
setCount(final E
the object to update
object
,
final int
the number of occurrences of the object
count
)

Overrides org.apache.commons.collections4.multiset.AbstractMultiSetDecorator.setCount.

Implements org.apache.commons.collections4.MultiSet.setCount.

Sets the number of occurrences of the specified object in the MultiSet to the given count.
public Set<E>
public static <
the type of the elements in the multiset
E
>
MultiSet<E>

Returns:

an unmodifiable MultiSet
unmodifiableMultiSet
(final MultiSet<? extends E>
the multiset to decorate, may not be null
multiset
)

Factory method to create an unmodifiable multiset.

private void
writeObject(final ObjectOutputStream
the output stream
out
)

Write the collection out using a custom routine.

Inherited from org.apache.commons.collections4.multiset.AbstractMultiSetDecorator:
decoratedequalsgetCounthashCode

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.collections4.multiset.AbstractMultiSetDecorator.serialVersionUID.

Serialization version

Constructor Detail

UnmodifiableMultiSetback to summary
private UnmodifiableMultiSet(final MultiSet<? extends E> multiset)

Constructor that wraps (not copies).

Parameters
multiset:MultiSet<? extends E>

the multiset to decorate, may not be null

Annotations
@SuppressWarnings:unchecked
Exceptions
NullPointerException:
if multiset is null

Method Detail

addback to summary
public boolean add(final E object)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.add.

Implements org.apache.commons.collections4.MultiSet.add, java.util.Collection.add.

Doc from org.apache.commons.collections4.MultiSet.add.

Adds one copy of the specified object to the MultiSet.

If the object is already in the uniqueSet() then increment its count as reported by getCount(Object). Otherwise add it to the uniqueSet() and report its count as 1.

Parameters
object:E

the object to add

Returns:boolean

true always, as the size of the MultiSet is increased in any case

Annotations
@Override
addback to summary
public int add(final E object, final int count)

Overrides org.apache.commons.collections4.multiset.AbstractMultiSetDecorator.add.

Implements org.apache.commons.collections4.MultiSet.add.

Doc from org.apache.commons.collections4.MultiSet.add.

Adds a number of occurrences of the specified object to the MultiSet.

If the object is already in the uniqueSet() then increment its count as reported by getCount(Object). Otherwise add it to the uniqueSet() and report its count as occurrences.

Parameters
object:E

the object to add

count:int

the number of occurrences to add, may be zero, in which case no change is made to the multiset

Returns:int

the number of occurrences of the object in the multiset before this operation; possibly zero

Annotations
@Override
addAllback to summary
public boolean addAll(final Collection<? extends E> coll)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.addAll.

Implements java.util.Collection.addAll.

Doc from java.util.Collection.addAll.

Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.) If the specified collection has a defined encounter order, processing of its elements generally occurs in that order.

Parameters
coll:Collection<? extends E>

collection containing elements to be added to this collection

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
clearback to summary
public void clear()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.clear.

Implements java.util.Collection.clear.

Doc from java.util.Collection.clear.

Removes all of the elements from this collection (optional operation). The collection will be empty after this method returns.

Annotations
@Override
entrySetback to summary
public Set<MultiSet.Entry<E>> entrySet()

Overrides org.apache.commons.collections4.multiset.AbstractMultiSetDecorator.entrySet.

Implements org.apache.commons.collections4.MultiSet.entrySet.

Doc from org.apache.commons.collections4.MultiSet.entrySet.

Returns a Set 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.

Returns:Set<MultiSet.Entry<E>>

the Set of MultiSet entries

Annotations
@Override
iteratorback to summary
public Iterator<E> iterator()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.iterator.

Implements org.apache.commons.collections4.MultiSet.iterator, java.util.Collection.iterator.

Doc from org.apache.commons.collections4.MultiSet.iterator.

Returns an Iterator over the entire set of members, including copies due to cardinality. This iterator is fail-fast and will not tolerate concurrent modifications.

Returns:Iterator<E>

iterator over all elements in the MultiSet

Annotations
@Override
readObjectback to summary
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException

Read the collection in using a custom routine.

Parameters
in:ObjectInputStream

the input stream

Annotations
@SuppressWarnings:unchecked
Exceptions
IOException:
if an error occurs while reading from the stream
ClassNotFoundException:
if an object read from the stream can not be loaded
ClassCastException:
if deserialised object has wrong type
removeback to summary
public boolean remove(final Object object)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.remove.

Implements org.apache.commons.collections4.MultiSet.remove, java.util.Collection.remove.

Doc from org.apache.commons.collections4.MultiSet.remove.

Removes 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 uniqueSet().

Parameters
object:Object

the object to remove

Returns:boolean

true if this call changed the collection

Annotations
@Override
removeback to summary
public int remove(final Object object, final int count)

Overrides org.apache.commons.collections4.multiset.AbstractMultiSetDecorator.remove.

Implements org.apache.commons.collections4.MultiSet.remove.

Doc from org.apache.commons.collections4.MultiSet.remove.

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.

Parameters
object:Object

the object to remove

count:int

the number of occurrences to remove, may be zero, in which case no change is made to the multiset

Returns:int

the number of occurrences of the object in the multiset before the operation; possibly zero

Annotations
@Override
removeAllback to summary
public boolean removeAll(final Collection<?> coll)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.removeAll.

Implements org.apache.commons.collections4.MultiSet.removeAll, java.util.Collection.removeAll.

Doc from org.apache.commons.collections4.MultiSet.removeAll.

Remove all occurrences of all elements from this MultiSet represented in the given collection.

Parameters
coll:Collection<?>

the collection of elements to remove

Returns:boolean

true if this call changed the multiset

Annotations
@Override
removeIfback to summary
public boolean removeIf(Predicate<? super E> filter)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.removeIf.

Overrides default java.util.Collection.removeIf.

Doc from java.util.Collection.removeIf.

Removes all of the elements of this collection that satisfy the given predicate. Errors or runtime exceptions thrown during iteration or by the predicate are relayed to the caller.

Parameters
filter:Predicate<? super E>

a predicate which returns true for elements to be removed

Returns:boolean

true if any elements were removed

Annotations
@Override
Since
4.4
retainAllback to summary
public boolean retainAll(final Collection<?> coll)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.retainAll.

Implements org.apache.commons.collections4.MultiSet.retainAll, java.util.Collection.retainAll.

Doc from org.apache.commons.collections4.MultiSet.retainAll.

Remove any elements of this MultiSet that are not contained in the given collection.

Parameters
coll:Collection<?>

the collection of elements to retain

Returns:boolean

true if this call changed the multiset

Annotations
@Override
setCountback to summary
public int setCount(final E object, final int count)

Overrides org.apache.commons.collections4.multiset.AbstractMultiSetDecorator.setCount.

Implements org.apache.commons.collections4.MultiSet.setCount.

Doc from org.apache.commons.collections4.MultiSet.setCount.

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 uniqueSet().

Parameters
object:E

the object to update

count:int

the number of occurrences of the object

Returns:int

the number of occurrences of the object before this operation, zero if the object was not contained in the multiset

Annotations
@Override
uniqueSetback to summary
public Set<E> uniqueSet()

Overrides org.apache.commons.collections4.multiset.AbstractMultiSetDecorator.uniqueSet.

Implements org.apache.commons.collections4.MultiSet.uniqueSet.

Doc from org.apache.commons.collections4.MultiSet.uniqueSet.

Returns a Set of unique elements in the MultiSet.

Uniqueness constraints are the same as those in java.util.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.

Returns:Set<E>

the Set of unique MultiSet elements

Annotations
@Override
unmodifiableMultiSetback to summary
public static <E> MultiSet<E> unmodifiableMultiSet(final MultiSet<? extends E> multiset)

Factory method to create an unmodifiable multiset.

If the multiset passed in is already unmodifiable, it is returned.

Parameters
<E>
the type of the elements in the multiset
multiset:MultiSet<? extends E>

the multiset to decorate, may not be null

Returns:MultiSet<E>

an unmodifiable MultiSet

Exceptions
NullPointerException:
if multiset is null
writeObjectback to summary
private void writeObject(final ObjectOutputStream out) throws IOException

Write the collection out using a custom routine.

Parameters
out:ObjectOutputStream

the output stream

Exceptions
IOException:
if an error occurs while writing to the stream