Class CollectionSortedBag<E>
- Type Parameters:
- E- the type of elements in this bag
- All Implemented Interfaces:
- Serializable,- Iterable<E>,- Collection<E>,- Bag<E>,- SortedBag<E>
SortedBag to comply with the Collection contract.- Since:
- 4.0
- See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionboolean(Violation) Adds one copy of the specified object to the Bag.booleanAddsnCopiescopies of the specified object to the Bag.booleanaddAll(Collection<? extends E> coll) static <E> SortedBag<E> collectionSortedBag(SortedBag<E> bag) Factory method to create a sorted bag that complies to the Collection contract.booleancontainsAll(Collection<?> coll) (Violation) Returnstrueif the bag contains all elements in the given collection, respecting cardinality.boolean(Violation) Removes all occurrences of the given 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.Methods inherited from class org.apache.commons.collections4.bag.AbstractSortedBagDecoratorcomparator, decorated, first, lastMethods inherited from class org.apache.commons.collections4.bag.AbstractBagDecoratorequals, getCount, hashCode, remove, uniqueSetMethods inherited from class org.apache.commons.collections4.collection.AbstractCollectionDecoratorclear, contains, isEmpty, iterator, removeIf, setCollection, size, toArray, toArray, toStringMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.commons.collections4.BaggetCount, iterator, remove, size, uniqueSetMethods inherited from interface java.util.Collectionclear, contains, equals, hashCode, isEmpty, parallelStream, removeIf, spliterator, stream, toArray, toArray
- 
Constructor Details- 
CollectionSortedBagConstructor that wraps (not copies).- Parameters:
- bag- the sorted bag to decorate, must not be null
- Throws:
- NullPointerException- if bag is null
 
 
- 
- 
Method Details- 
collectionSortedBagFactory method to create a sorted bag that complies to the Collection contract.- Type Parameters:
- E- the type of the elements in the bag
- Parameters:
- bag- the sorted bag to decorate, must not be null
- Returns:
- a SortedBag that complies to the Collection contract
- Throws:
- NullPointerException- if bag is null
 
- 
addDescription copied from interface:Bag(Violation) Adds one copy 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 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 interface- Bag<E>
- Specified by:
- addin interface- Collection<E>
- Overrides:
- addin class- AbstractCollectionDecorator<E>
- Parameters:
- object- the object to add
- Returns:
- trueif the object was not already in the- uniqueSet
 
- 
addDescription 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.
- 
addAll- Specified by:
- addAllin interface- Collection<E>
- Overrides:
- addAllin class- AbstractCollectionDecorator<E>
 
- 
containsAllDescription copied from interface:Bag(Violation) Returnstrueif the bag contains all elements in the given collection, respecting cardinality. That is, if the given collectioncollcontainsncopies of a given object, callingBag.getCount(Object)on that object must be>= nfor allnincoll.The Collection.containsAll(Collection)method specifies that cardinality should not be respected; this method should return true if the bag contains at least one of every object contained in the given collection.- Specified by:
- containsAllin interface- Bag<E>
- Specified by:
- containsAllin interface- Collection<E>
- Overrides:
- containsAllin class- AbstractCollectionDecorator<E>
- Parameters:
- coll- the collection to check against
- Returns:
- trueif the Bag contains all the collection
 
- 
removeDescription 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 interface- Bag<E>
- Specified by:
- removein interface- Collection<E>
- Overrides:
- removein class- AbstractCollectionDecorator<E>
- Parameters:
- object- the object to remove
- Returns:
- trueif this call changed the collection
 
- 
removeAllDescription 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 interface- Bag<E>
- Specified by:
- removeAllin interface- Collection<E>
- Overrides:
- removeAllin class- AbstractCollectionDecorator<E>
- Parameters:
- coll- the collection to remove
- Returns:
- trueif this call changed the collection
 
- 
retainAllDescription 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 interface- Bag<E>
- Specified by:
- retainAllin interface- Collection<E>
- Overrides:
- retainAllin class- AbstractCollectionDecorator<E>
- Parameters:
- coll- the collection to retain
- Returns:
- trueif this call changed the collection
 
 
-