public final class

UnmodifiableSortedBag

extends AbstractSortedBagDecorator
implements Serializable Unmodifiable
java.lang.Object
   ↳ org.apache.commons.collections.collection.AbstractCollectionDecorator
     ↳ org.apache.commons.collections.bag.AbstractBagDecorator
       ↳ org.apache.commons.collections.bag.AbstractSortedBagDecorator
         ↳ org.apache.commons.collections.bag.UnmodifiableSortedBag

Class Overview

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

This class is Serializable from Commons Collections 3.1.

Summary

[Expand]
Inherited Fields
From class org.apache.commons.collections.collection.AbstractCollectionDecorator
Public Methods
boolean add(Object object, int count)
Adds nCopies copies of the specified object to the Bag.
boolean add(Object object)
boolean addAll(Collection coll)
void clear()
static SortedBag decorate(SortedBag bag)
Factory method to create an unmodifiable bag.
Iterator iterator()
boolean remove(Object object)
boolean remove(Object object, int count)
Removes nCopies copies of the specified object from the Bag.
boolean removeAll(Collection coll)
boolean retainAll(Collection coll)
Set uniqueSet()
Returns a Set of unique elements in the Bag.
[Expand]
Inherited Methods
From class org.apache.commons.collections.bag.AbstractSortedBagDecorator
From class org.apache.commons.collections.bag.AbstractBagDecorator
From class org.apache.commons.collections.collection.AbstractCollectionDecorator
From class java.lang.Object
From interface java.lang.Iterable
From interface java.util.Collection
From interface org.apache.commons.collections.Bag
From interface org.apache.commons.collections.SortedBag

Public Methods

public boolean add (Object object, int count)

Adds nCopies copies of the specified object to the Bag.

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 nCopies.

Parameters
object the object to add
count the number of copies to add
Returns
  • true if the object was not already in the uniqueSet

public boolean add (Object object)

public boolean addAll (Collection coll)

public void clear ()

public static SortedBag decorate (SortedBag bag)

Factory method to create an unmodifiable bag.

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

Parameters
bag the bag to decorate, must not be null
Returns
  • an unmodifiable SortedBag
Throws
IllegalArgumentException if bag is null

public Iterator iterator ()

public boolean remove (Object object)

public boolean remove (Object object, int count)

Removes nCopies copies of the specified object from the Bag.

If the number of copies to remove is greater than the actual number of copies in the Bag, no error is thrown.

Parameters
object the object to remove
count the number of copies to remove
Returns
  • true if this call changed the collection

public boolean removeAll (Collection coll)

public boolean retainAll (Collection coll)

public Set uniqueSet ()

Returns a Set of unique elements in the Bag.

Uniqueness constraints are the same as those in Set.

Returns
  • the Set of unique Bag elements