Package org.apache.commons.collections4.bag

# Class UnmodifiableBag<E>

java.lang.Object
org.apache.commons.collections4.collection.AbstractCollectionDecorator<E>
org.apache.commons.collections4.bag.AbstractBagDecorator<E>
org.apache.commons.collections4.bag.UnmodifiableBag<E>

Type Parameters:
  `E` - The type of elements in this bag

All Implemented Interfaces:
  `Serializable`, `Iterable<E>`, `Collection<E>`, `Bag<E>`, `Unmodifiable`

@Deprecated public final class UnmodifiableBag<E> extends AbstractBagDecorator<E> implements Unmodifiable
Deprecated.
Since 4.6.0, use `UnmodifiableMultiSet` instead.
Decorates another `Bag` to ensure it can't be altered.

This class is Serializable from Commons Collections 3.1.

Attempts to modify it will result in an UnsupportedOperationException.

Since:
  3.0
See Also:
  - Serialized Form

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `add(E object)`
  Deprecated.
  Always throws `UnsupportedOperationException`.
  `boolean`
  `add(E object, int count)`
  Deprecated.
  Always throws `UnsupportedOperationException`.
  `boolean`
  `addAll(Collection<? extends E> coll)`
  Deprecated.
  Always throws `UnsupportedOperationException`.
  `void`
  `clear()`
  Deprecated.
  Always throws `UnsupportedOperationException`.
  `Iterator<E>`
  `iterator()`
  Deprecated.
  Returns an `Iterator` over the entire set of members, including copies due to cardinality.
  `boolean`
  `remove(Object object)`
  Deprecated.
  Always throws `UnsupportedOperationException`.
  `boolean`
  `remove(Object object, int count)`
  Deprecated.
  Always throws `UnsupportedOperationException`.
  `boolean`
  `removeAll(Collection<?> coll)`
  Deprecated.
  Always throws `UnsupportedOperationException`.
  `boolean`
  `removeIf(Predicate<? super E> filter)`
  Deprecated.
  Always throws `UnsupportedOperationException`.
  `boolean`
  `retainAll(Collection<?> coll)`
  Deprecated.
  Always throws `UnsupportedOperationException`.
  `Set<E>`
  `uniqueSet()`
  Deprecated.
  Returns a `Set` of unique elements in the Bag.
  `static <E> Bag<E>`
  `unmodifiableBag(Bag<? extends E> bag)`
  Deprecated.
  Factory method to create an unmodifiable bag.

  ### Methods inherited from class org.apache.commons.collections4.bag.AbstractBagDecorator

  `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 org.apache.commons.collections4.Bag

  `containsAll, size`

  ### Methods inherited from interface java.util.Collection

  `contains, isEmpty, parallelStream, spliterator, stream, toArray, toArray`

  ### Methods inherited from interface java.lang.Iterable

  `forEach`

- ## Method Details

  - ### unmodifiableBag

    public static <E> Bag<E> unmodifiableBag(Bag<? extends E> bag)
    Deprecated.
    Factory method to create an unmodifiable bag.

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

    Type Parameters:
      `E` - The type of the elements in the bag
    Parameters:
      `bag` - The bag to decorate, must not be null
    Returns:
      An unmodifiable Bag
    Throws:
      `NullPointerException` - if bag is null
    Since:
      4.0

  - ### add

    public boolean add(E object)
    Deprecated.
    Always throws `UnsupportedOperationException`.
    Specified by:
      `add` in interface `Bag<E>`
    Specified by:
      `add` in interface `Collection<E>`
    Overrides:
      `add` in class `AbstractCollectionDecorator<E>`
    Parameters:
      `object` - Ignored.
    Returns:
      `true` if the object was not already in the `uniqueSet`.
    Throws:
      `UnsupportedOperationException` - Always thrown.

  - ### add

    public boolean add(E object, int count)
    Deprecated.
    Always throws `UnsupportedOperationException`.
    Specified by:
      `add` in interface `Bag<E>`
    Overrides:
      `add` in class `AbstractBagDecorator<E>`
    Parameters:
      `object` - Ignored.
      `count` - Ignored.
    Returns:
      `true` if the object was not already in the `uniqueSet`.
    Throws:
      `UnsupportedOperationException` - Always thrown.

  - ### addAll

    public boolean addAll(Collection<? extends E> coll)
    Deprecated.
    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()
    Deprecated.
    Always throws `UnsupportedOperationException`.
    Specified by:
      `clear` in interface `Collection<E>`
    Overrides:
      `clear` in class `AbstractCollectionDecorator<E>`
    Throws:
      `UnsupportedOperationException` - Always thrown.

  - ### iterator

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

  - ### remove

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

  - ### remove

    public boolean remove(Object object, int count)
    Deprecated.
    Always throws `UnsupportedOperationException`.
    Specified by:
      `remove` in interface `Bag<E>`
    Overrides:
      `remove` in class `AbstractBagDecorator<E>`
    Parameters:
      `object` - Ignored.
      `count` - Ignored.
    Returns:
      `true` if this call changed the collection.
    Throws:
      `UnsupportedOperationException` - Always thrown.

  - ### removeAll

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

  - ### removeIf

    public boolean removeIf(Predicate<? super E> filter)
    Deprecated.
    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)
    Deprecated.
    Always throws `UnsupportedOperationException`.
    Specified by:
      `retainAll` in interface `Bag<E>`
    Specified by:
      `retainAll` in interface `Collection<E>`
    Overrides:
      `retainAll` in class `AbstractCollectionDecorator<E>`
    Parameters:
      `coll` - Ignored.
    Returns:
      `true` if this call changed the collection.
    Throws:
      `UnsupportedOperationException` - Always thrown.

  - ### uniqueSet

    public Set<E> uniqueSet()
    Deprecated.
    Description copied from interface: `Bag`
    Returns a `Set` of unique elements in the Bag.

    Uniqueness constraints are the same as those in `Set`.

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