Package org.apache.commons.collections4.multiset

# 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:
  `Serializable`, `Iterable<E>`, `Collection<E>`, `MultiSet<E>`, `Unmodifiable`

public final class UnmodifiableMultiSet<E> extends AbstractMultiSetDecorator<E> implements Unmodifiable
Decorates another `MultiSet` to 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

  Modifier and Type
  Method
  Description
  `boolean`
  `add(E object)`
  Always throws `UnsupportedOperationException`.
  `int`
  `add(E object, int count)`
  Always throws `UnsupportedOperationException`.
  `boolean`
  `addAll(Collection<? extends E> coll)`
  Always throws `UnsupportedOperationException`.
  `void`
  `clear()`
  Always throws `UnsupportedOperationException`.
  `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)`
  Always throws `UnsupportedOperationException`.
  `int`
  `remove(Object object, int count)`
  Always throws `UnsupportedOperationException`.
  `boolean`
  `removeAll(Collection<?> coll)`
  Always throws `UnsupportedOperationException`.
  `boolean`
  `removeIf(Predicate<? super E> filter)`
  Always throws `UnsupportedOperationException`.
  `boolean`
  `retainAll(Collection<?> coll)`
  Always throws `UnsupportedOperationException`.
  `int`
  `setCount(E object, int count)`
  Always throws `UnsupportedOperationException`.
  `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.

  ### 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 java.lang.Iterable

  `forEach`

  ### Methods inherited from interface org.apache.commons.collections4.MultiSet

  `containsAll, size`

- ## Method Details

  - ### 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:
      `NullPointerException` - if multiset is null

  - ### add

    public boolean add(E object)
    Always throws `UnsupportedOperationException`.
    Specified by:
      `add` in interface `Collection<E>`
    Specified by:
      `add` in interface `MultiSet<E>`
    Overrides:
      `add` in class `AbstractCollectionDecorator<E>`
    Parameters:
      `object` - Ignored.
    Returns:
      `true` always, as the size of the MultiSet is increased in any case.
    Throws:
      `UnsupportedOperationException` - Always thrown.

  - ### add

    public int add(E object, int count)
    Always throws `UnsupportedOperationException`.
    Specified by:
      `add` in interface `MultiSet<E>`
    Overrides:
      `add` in class `AbstractMultiSetDecorator<E>`
    Parameters:
      `object` - Ignored.
      `count` - Ignored.
    Returns:
      The number of occurrences of the object in the multiset before this operation; possibly zero.
    Throws:
      `UnsupportedOperationException` - Always thrown.

  - ### addAll

    public boolean addAll(Collection<? extends E> coll)
    Always throws `UnsupportedOperationException`.
    Specified by:
      `addAll` in interface `Collection<E>`
    Overrides:
      `addAll` in class `AbstractCollectionDecorator<E>`
    Parameters:
      `coll` - Ignored.
    Throws:
      `UnsupportedOperationException` - Always thrown.

  - ### clear

    public void clear()
    Always throws `UnsupportedOperationException`.
    Specified by:
      `clear` in interface `Collection<E>`
    Overrides:
      `clear` in class `AbstractCollectionDecorator<E>`
    Throws:
      `UnsupportedOperationException` - Always thrown.

  - ### entrySet

    public Set<MultiSet.Entry<E>> entrySet()
    Description copied from interface: `MultiSet`
    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.

    Specified by:
      `entrySet` in interface `MultiSet<E>`
    Overrides:
      `entrySet` in class `AbstractMultiSetDecorator<E>`
    Returns:
      The Set of MultiSet entries.

  - ### iterator

    public Iterator<E> iterator()
    Description copied from interface: `MultiSet`
    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.
    Specified by:
      `iterator` in interface `Collection<E>`
    Specified by:
      `iterator` in interface `Iterable<E>`
    Specified by:
      `iterator` in interface `MultiSet<E>`
    Overrides:
      `iterator` in class `AbstractCollectionDecorator<E>`
    Returns:
      iterator over all elements in the MultiSet.

  - ### remove

    public boolean remove(Object object)
    Always throws `UnsupportedOperationException`.
    Specified by:
      `remove` in interface `Collection<E>`
    Specified by:
      `remove` in interface `MultiSet<E>`
    Overrides:
      `remove` in class `AbstractCollectionDecorator<E>`
    Parameters:
      `object` - Ignored.
    Returns:
      `true` if this call changed the collection.
    Throws:
      `UnsupportedOperationException` - Always thrown.

  - ### remove

    public int remove(Object object, int count)
    Always throws `UnsupportedOperationException`.
    Specified by:
      `remove` in interface `MultiSet<E>`
    Overrides:
      `remove` in class `AbstractMultiSetDecorator<E>`
    Parameters:
      `object` - Ignored.
      `count` - Ignored.
    Returns:
      The number of occurrences of the object in the multiset before the operation; possibly zero.
    Throws:
      `UnsupportedOperationException` - Always thrown.

  - ### removeAll

    public boolean removeAll(Collection<?> coll)
    Always throws `UnsupportedOperationException`.
    Specified by:
      `removeAll` in interface `Collection<E>`
    Specified by:
      `removeAll` in interface `MultiSet<E>`
    Overrides:
      `removeAll` in class `AbstractCollectionDecorator<E>`
    Parameters:
      `coll` - Ignored.
    Returns:
      `true` if this call changed the multiset.
    Throws:
      `UnsupportedOperationException` - Always thrown.

  - ### removeIf

    public boolean removeIf(Predicate<? super E> filter)
    Always throws `UnsupportedOperationException`.
    Specified by:
      `removeIf` in interface `Collection<E>`
    Overrides:
      `removeIf` in class `AbstractCollectionDecorator<E>`
    Parameters:
      `filter` - Ignored.
    Throws:
      `UnsupportedOperationException` - Always thrown.
    Since:
      4.4

  - ### retainAll

    public boolean retainAll(Collection<?> coll)
    Always throws `UnsupportedOperationException`.
    Specified by:
      `retainAll` in interface `Collection<E>`
    Specified by:
      `retainAll` in interface `MultiSet<E>`
    Overrides:
      `retainAll` in class `AbstractCollectionDecorator<E>`
    Parameters:
      `coll` - Ignored.
    Returns:
      `true` if this call changed the multiset.
    Throws:
      `UnsupportedOperationException` - Always thrown.

  - ### setCount

    public int setCount(E object, int count)
    Always throws `UnsupportedOperationException`.
    Specified by:
      `setCount` in interface `MultiSet<E>`
    Overrides:
      `setCount` in class `AbstractMultiSetDecorator<E>`
    Parameters:
      `object` - Ignored.
      `count` - Ignored.
    Returns:
      The number of occurrences of the object before this operation, zero if the object was not contained in the multiset.
    Throws:
      `UnsupportedOperationException` - Always thrown.

  - ### uniqueSet

    public Set<E> uniqueSet()
    Description copied from interface: `MultiSet`
    Returns a `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.

    Specified by:
      `uniqueSet` in interface `MultiSet<E>`
    Overrides:
      `uniqueSet` in class `AbstractMultiSetDecorator<E>`
    Returns:
      The Set of unique MultiSet elements.