Class UnmodifiableSortedBag
- All Implemented Interfaces:
Serializable,Iterable,Collection,Bag,SortedBag,Unmodifiable
SortedBag to ensure it can't be altered.
This class is Serializable from Commons Collections 3.1.
- Since:
- Commons Collections 3.0
- Version:
- $Revision: 646777 $ $Date: 2008-04-10 14:33:15 +0200 (Thu, 10 Apr 2008) $
- Author:
- Stephen Colebourne
- See Also:
-
Field Summary
Fields inherited from class org.apache.commons.collections.collection.AbstractCollectionDecorator
collection -
Method Summary
Modifier and TypeMethodDescriptionboolean(Violation) Adds one copy the specified object to the Bag.booleanAddsnCopiescopies of the specified object to the Bag.booleanaddAll(Collection coll) voidclear()static SortedBagFactory method to create an unmodifiable bag.iterator()Returns anIteratorover the entire set of members, including copies due to cardinality.boolean(Violation) Removes all occurrences of the given object from the bag.booleanRemovesnCopiescopies of the specified object from the Bag.booleanremoveAll(Collection coll) (Violation) Remove all elements represented in the given collection, respecting cardinality.booleanretainAll(Collection coll) (Violation) Remove any members of the bag that are not in the given collection, respecting cardinality.Returns aSetof unique elements in the Bag.Methods inherited from class org.apache.commons.collections.bag.AbstractSortedBagDecorator
comparator, first, getSortedBag, lastMethods inherited from class org.apache.commons.collections.bag.AbstractBagDecorator
getBag, getCountMethods inherited from class org.apache.commons.collections.collection.AbstractCollectionDecorator
contains, containsAll, equals, getCollection, hashCode, isEmpty, size, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.commons.collections.Bag
containsAll, getCount, sizeMethods inherited from interface java.util.Collection
contains, equals, hashCode, isEmpty, parallelStream, removeIf, spliterator, stream, toArray, toArray, toArray
-
Method Details
-
decorate
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
-
iterator
Description copied from interface:BagReturns anIteratorover the entire set of members, including copies due to cardinality. This iterator is fail-fast and will not tolerate concurrent modifications.- Specified by:
iteratorin interfaceBag- Specified by:
iteratorin interfaceCollection- Specified by:
iteratorin interfaceIterable- Overrides:
iteratorin classAbstractCollectionDecorator- Returns:
- iterator over all elements in the Bag
-
add
Description copied from interface:Bag(Violation) Adds one copy the specified object to the Bag.If the object is already in the
Bag.uniqueSet()then increment its count as reported byBag.getCount(Object). Otherwise add it to theBag.uniqueSet()and report its count as 1.Since this method always increases the size of the bag, according to the
Collection.add(Object)contract, it should always returntrue. Since it sometimes returnsfalse, this method violates the contract.- Specified by:
addin interfaceBag- Specified by:
addin interfaceCollection- Overrides:
addin classAbstractCollectionDecorator- Parameters:
object- the object to add- Returns:
trueif the object was not already in theuniqueSet
-
addAll
- Specified by:
addAllin interfaceCollection- Overrides:
addAllin classAbstractCollectionDecorator
-
clear
public void clear()- Specified by:
clearin interfaceCollection- Overrides:
clearin classAbstractCollectionDecorator
-
remove
Description copied from interface:Bag(Violation) Removes all occurrences of the given object from the bag.This will also remove the object from the
Bag.uniqueSet().According to the
Collection.remove(Object)method, this method should only remove the first occurrence of the given object, not all occurrences.- Specified by:
removein interfaceBag- Specified by:
removein interfaceCollection- Overrides:
removein classAbstractCollectionDecorator- Returns:
trueif this call changed the collection
-
removeAll
Description copied from interface:Bag(Violation) Remove all elements represented in the given collection, respecting cardinality. That is, if the given collectioncollcontainsncopies of a given object, the bag will havenfewer copies, assuming the bag had at leastncopies to begin with.The
Collection.removeAll(Collection)method specifies that cardinality should not be respected; this method should remove all occurrences of every object contained in the given collection.- Specified by:
removeAllin interfaceBag- Specified by:
removeAllin interfaceCollection- Overrides:
removeAllin classAbstractCollectionDecorator- Parameters:
coll- the collection to remove- Returns:
trueif this call changed the collection
-
retainAll
Description copied from interface:Bag(Violation) Remove any members of the bag that are not in the given collection, respecting cardinality. That is, if the given collectioncollcontainsncopies of a given object and the bag hasm > ncopies, then deletem - ncopies from the bag. In addition, ifeis an object in the bag but!coll.contains(e), then removeeand any of its copies.The
Collection.retainAll(Collection)method specifies that cardinality should not be respected; this method should keep all occurrences of every object contained in the given collection.- Specified by:
retainAllin interfaceBag- Specified by:
retainAllin interfaceCollection- Overrides:
retainAllin classAbstractCollectionDecorator- Parameters:
coll- the collection to retain- Returns:
trueif this call changed the collection
-
add
Description copied from interface:BagAddsnCopiescopies of the specified object to the Bag.If the object is already in the
Bag.uniqueSet()then increment its count as reported byBag.getCount(Object). Otherwise add it to theBag.uniqueSet()and report its count asnCopies.- Specified by:
addin interfaceBag- Overrides:
addin classAbstractBagDecorator- Parameters:
object- the object to addcount- the number of copies to add- Returns:
trueif the object was not already in theuniqueSet
-
remove
Description copied from interface:BagRemovesnCopiescopies 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.
- Specified by:
removein interfaceBag- Overrides:
removein classAbstractBagDecorator- Parameters:
object- the object to removecount- the number of copies to remove- Returns:
trueif this call changed the collection
-
uniqueSet
Description copied from interface:Bag- Specified by:
uniqueSetin interfaceBag- Overrides:
uniqueSetin classAbstractBagDecorator- Returns:
- the Set of unique Bag elements
-