Top Description Fields Constructors Methods
org.apache.commons.collections4.bag

public final Class CollectionSortedBag<E>

extends AbstractSortedBagDecorator<E>
Class Inheritance
Type Parameters
<E>
the type of elements in this bag
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, java.util.Collection, .Iterator, org.apache.commons.collections4.SortedBag

Decorates another SortedBag to comply with the Collection contract.
Since
4.0

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
public
CollectionSortedBag(final SortedBag<E>
the sorted bag to decorate, must not be null
bag
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
public boolean
add(final E
the object to add
object
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.add.

Implements org.apache.commons.collections4.Bag.add, java.util.Collection.add.

(Violation) Adds one copy of the specified object to the Bag.
public boolean
add(final E
the object to add
object
,
final int
the number of copies to add
count
)

Overrides org.apache.commons.collections4.bag.AbstractBagDecorator.add.

Implements org.apache.commons.collections4.Bag.add.

Adds nCopies copies of the specified object to the Bag.
public boolean
addAll(final Collection<? extends E>
collection containing elements to be added to this collection
coll
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.addAll.

Implements java.util.Collection.addAll.

Adds all of the elements in the specified collection to this collection (optional operation).
public static <
the type of the elements in the bag
E
>
SortedBag<E>

Returns:

a SortedBag that complies to the Collection contract
collectionSortedBag
(final SortedBag<E>
the sorted bag to decorate, must not be null
bag
)

Factory method to create a sorted bag that complies to the Collection contract.

public boolean
containsAll(final Collection<?>
the collection to check against
coll
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.containsAll.

Implements org.apache.commons.collections4.Bag.containsAll, java.util.Collection.containsAll.

(Violation) Returns true if the bag contains all elements in the given collection, respecting cardinality.
private void
readObject(final ObjectInputStream
the input stream
in
)

Read the collection in using a custom routine.

public boolean
remove(final Object
the object to remove
object
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.remove.

Implements org.apache.commons.collections4.Bag.remove, java.util.Collection.remove.

(Violation) Removes all occurrences of the given object from the bag.
public boolean
removeAll(final Collection<?>
the collection to remove
coll
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.removeAll.

Implements org.apache.commons.collections4.Bag.removeAll, java.util.Collection.removeAll.

(Violation) Remove all elements represented in the given collection, respecting cardinality.
public boolean
retainAll(final Collection<?>
the collection to retain
coll
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.retainAll.

Implements org.apache.commons.collections4.Bag.retainAll, java.util.Collection.retainAll.

(Violation) Remove any members of the bag that are not in the given collection, respecting cardinality.
private void
writeObject(final ObjectOutputStream
the output stream
out
)

Write the collection out using a custom routine.

Inherited from org.apache.commons.collections4.bag.AbstractSortedBagDecorator:
comparatordecoratedfirstlast

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.collections4.bag.AbstractSortedBagDecorator.serialVersionUID.

Serialization version

Constructor Detail

CollectionSortedBagback to summary
public CollectionSortedBag(final SortedBag<E> bag)

Constructor that wraps (not copies).

Parameters
bag:SortedBag<E>

the sorted bag to decorate, must not be null

Exceptions
NullPointerException:
if bag is null

Method Detail

addback to summary
public boolean add(final E object)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.add.

Implements org.apache.commons.collections4.Bag.add, java.util.Collection.add.

Doc from org.apache.commons.collections4.Bag.add.

(Violation) Adds one copy 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 1.

Since this method always increases the size of the bag, according to the Collection#add(Object) contract, it should always return true. Since it sometimes returns false, this method violates the contract.

Parameters
object:E

the object to add

Returns:boolean

true if the object was not already in the uniqueSet

Annotations
@Override
addback to summary
public boolean add(final E object, final int count)

Overrides org.apache.commons.collections4.bag.AbstractBagDecorator.add.

Implements org.apache.commons.collections4.Bag.add.

Doc from org.apache.commons.collections4.Bag.add.

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:E

the object to add

count:int

the number of copies to add

Returns:boolean

true if the object was not already in the uniqueSet

Annotations
@Override
addAllback to summary
public boolean addAll(final Collection<? extends E> coll)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.addAll.

Implements java.util.Collection.addAll.

Doc from java.util.Collection.addAll.

Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.) If the specified collection has a defined encounter order, processing of its elements generally occurs in that order.

Parameters
coll:Collection<? extends E>

collection containing elements to be added to this collection

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
collectionSortedBagback to summary
public static <E> SortedBag<E> collectionSortedBag(final SortedBag<E> bag)

Factory method to create a sorted bag that complies to the Collection contract.

Parameters
<E>
the type of the elements in the bag
bag:SortedBag<E>

the sorted bag to decorate, must not be null

Returns:SortedBag<E>

a SortedBag that complies to the Collection contract

Exceptions
NullPointerException:
if bag is null
containsAllback to summary
public boolean containsAll(final Collection<?> coll)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.containsAll.

Implements org.apache.commons.collections4.Bag.containsAll, java.util.Collection.containsAll.

Doc from org.apache.commons.collections4.Bag.containsAll.

(Violation) Returns true if the bag contains all elements in the given collection, respecting cardinality. That is, if the given collection coll contains n copies of a given object, calling getCount(Object) on that object must be >= n for all n in coll.

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.

Parameters
coll:Collection<?>

the collection to check against

Returns:boolean

true if the Bag contains all the collection

Annotations
@Override
readObjectback to summary
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException

Read the collection in using a custom routine.

Parameters
in:ObjectInputStream

the input stream

Annotations
@SuppressWarnings:unchecked
Exceptions
IOException:
if an error occurs while reading from the stream
ClassNotFoundException:
if an object read from the stream can not be loaded
ClassCastException:
if deserialised object has wrong type
removeback to summary
public boolean remove(final Object object)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.remove.

Implements org.apache.commons.collections4.Bag.remove, java.util.Collection.remove.

Doc from org.apache.commons.collections4.Bag.remove.

(Violation) Removes all occurrences of the given object from the bag.

This will also remove the object from the uniqueSet().

According to the Collection#remove(Object) method, this method should only remove the first occurrence of the given object, not all occurrences.

Parameters
object:Object

the object to remove

Returns:boolean

true if this call changed the collection

Annotations
@Override
removeAllback to summary
public boolean removeAll(final Collection<?> coll)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.removeAll.

Implements org.apache.commons.collections4.Bag.removeAll, java.util.Collection.removeAll.

Doc from org.apache.commons.collections4.Bag.removeAll.

(Violation) Remove all elements represented in the given collection, respecting cardinality. That is, if the given collection coll contains n copies of a given object, the bag will have n fewer copies, assuming the bag had at least n copies 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.

Parameters
coll:Collection<?>

the collection to remove

Returns:boolean

true if this call changed the collection

Annotations
@Override
retainAllback to summary
public boolean retainAll(final Collection<?> coll)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.retainAll.

Implements org.apache.commons.collections4.Bag.retainAll, java.util.Collection.retainAll.

Doc from org.apache.commons.collections4.Bag.retainAll.

(Violation) Remove any members of the bag that are not in the given collection, respecting cardinality. That is, if the given collection coll contains n copies of a given object and the bag has m > n copies, then delete m - n copies from the bag. In addition, if e is an object in the bag but !coll.contains(e), then remove e and 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.

Parameters
coll:Collection<?>

the collection to retain

Returns:boolean

true if this call changed the collection

Annotations
@Override
writeObjectback to summary
private void writeObject(final ObjectOutputStream out) throws IOException

Write the collection out using a custom routine.

Parameters
out:ObjectOutputStream

the output stream

Exceptions
IOException:
if an error occurs while writing to the stream