#include <coherence/util/SortedBag.hpp>
Inherits AbstractCollection.
Inherited by TopNAggregator::PartialResult, and SortedBag::ViewBag.
This implementation is not thread-safe and does not support NULL elements.
Public Types | ||||
typedef spec::Handle | Handle | |||
SortedBag Handle definition. | ||||
typedef spec::View | View | |||
SortedBag View definition. | ||||
typedef spec::Holder | Holder | |||
SortedBag Holder definition. | ||||
typedef this_spec::Handle | Handle | |||
AbstractCollection Handle definition. | ||||
typedef this_spec::View | View | |||
AbstractCollection View definition. | ||||
typedef this_spec::Holder | Holder | |||
AbstractCollection Holder definition. | ||||
Public Member Functions | ||||
virtual size32_t | size () const | |||
Return the number of elements in this collection.
| ||||
virtual bool | isEmpty () const | |||
Determine whether this collection contains any elements.
| ||||
virtual bool | contains (Object::View vo) const | |||
Determine if this collection contains the specified element.
| ||||
virtual Iterator::Handle | iterator () const | |||
Return an Iterator over this collection.
| ||||
virtual Muterator::Handle | iterator () | |||
Return an Iterator over this collection.
| ||||
virtual bool | add (Object::Holder oh) | |||
Add the given element to this collection.
This implementation will throw a coherence::lang::UnsupportedOperationException | ||||
virtual bool | remove (Object::View v) | |||
Remove the supplied element from this collection.
This implementation will throw a coherence::lang::UnsupportedOperationException unless add() is overridden (assuming the specified collection is non-empty). | ||||
virtual SortedBag::Handle | subBag (Object::View vFrom, Object::View vTo) | |||
Returns a view of the portion of this bag whose elements range from vFrom , inclusive, to vTo , exclusive. | ||||
virtual SortedBag::Handle | headBag (Object::View vTo) | |||
Returns a view of the portion of this bag whose elements are strictly less than vTo . | ||||
virtual SortedBag::Handle | tailBag (Object::View vFrom) | |||
Returns a view of the portion of this bag whose elements are greater than or equal to vFrom . | ||||
virtual Object::Holder | first () const | |||
Returns the first (lowest) element currently in this bag. | ||||
virtual Object::Holder | last () const | |||
Returns the last (highest) element currently in this bag. | ||||
virtual Object::Holder | removeFirst () | |||
Remove and return the least element in this bag, or NULL if empty. | ||||
virtual Object::Holder | removeLast () | |||
Remove and return the greatest element in this bag, or NULL if empty. | ||||
virtual Object::Holder | unwrap (Object::View v) const | |||
Unwrap the specified element (which could be a wrapped or an "actual") element. | ||||
Protected Member Functions | ||||
SortedBag () | ||||
Default constructor. | ||||
SortedBag (Comparator::View vComparator) | ||||
Construct a SortedBag whose elements are to be ordered by the specified comparator. | ||||
virtual NavigableMap::Handle | getInternalMap () const | |||
Return the internal navigable map holding the bag contents. | ||||
virtual Comparator::View | getComparator () const | |||
Return the Comparator used to order the bag contents. | ||||
virtual AtomicCounter::Handle | getNonceCounter () | |||
Return the nonce counter used to assign unique element ids. | ||||
virtual NavigableMap::Handle | instantiateInternalMap (Comparator::View vComparator) | |||
Factory for the navigable internal map to use to hold the bag elements. | ||||
virtual UniqueElement::View | wrap (Object::Holder oh) | |||
Wrap the specified element to ensure uniqueness. | ||||
Protected Attributes | ||||
MemberHandle < AtomicCounter > | m_hAtomicNonce | |||
The nonce used to increment the unique element ids. | ||||
MemberView< Comparator > | m_vComparator | |||
The comparator used to compare logical elements. | ||||
MemberHandle < NavigableMap > | m_hMap | |||
The internal navigable map holding the bag contents. | ||||
Classes | ||||
class | UniqueElement | |||
UniqueElement represents a unique instance of a logical element in the bag. More... | ||||
class | ViewBag | |||
A range-limited view of the SortedBag. More... | ||||
class | WrapperComparator | |||
WrapperComparator is a Comparator implementation that is aware of UniqueElement wrappers and will delegate the comparison of the elements in both forms to the wrapped comparator. More... |
SortedBag | ( | Comparator::View | vComparator | ) | [protected] |
Construct a SortedBag whose elements are to be ordered by the specified comparator.
vComparator | the comparator to use to order the elements |
virtual NavigableMap::Handle getInternalMap | ( | ) | const [protected, virtual] |
Return the internal navigable map holding the bag contents.
virtual Comparator::View getComparator | ( | ) | const [protected, virtual] |
Return the Comparator used to order the bag contents.
virtual AtomicCounter::Handle getNonceCounter | ( | ) | [protected, virtual] |
Return the nonce counter used to assign unique element ids.
virtual SortedBag::Handle subBag | ( | Object::View | vFrom, | |
Object::View | vTo | |||
) | [virtual] |
Returns a view of the portion of this bag whose elements range from vFrom
, inclusive, to vTo
, exclusive.
(If vFrom
and vTo
are equal, the returned bag is empty.) The returned bag is backed by this bag, so changes in the returned bag are reflected in this bag, and vice-versa. The returned bag supports all optional bag operations that this bag supports.
The returned bag will throw an IllegalArgumentException
on an attempt to insert an element outside its range.
vFrom | low endpoint (inclusive) of the returned bag | |
vTo | high endpoint (exclusive) of the returned bag |
vFrom
, inclusive, to vTo
, exclusiveClassCastException | if vFrom and vTo cannot be compared to one another using this bag's comparator (or, if the bag has no comparator, using natural ordering). Implementations may, but are not required to, throw this exception if vFrom or vTo cannot be compared to elements currently in the bag. | |
NullPointerException | if vFrom or vTo is NULL and this bag does not permit NULL elements | |
IllegalArgumentException | if vFrom is greater than vTo ; or if this bag itself has a restricted range, and vFrom or vTo lies outside the bounds of the range |
Reimplemented in SortedBag::ViewBag.
virtual SortedBag::Handle headBag | ( | Object::View | vTo | ) | [virtual] |
Returns a view of the portion of this bag whose elements are strictly less than vTo
.
The returned bag is backed by this bag, so changes in the returned bag are reflected in this bag, and vice-versa. The returned bag supports all optional bag operations that this bag supports.
The returned bag will throw an IllegalArgumentException
on an attempt to insert an element outside its range.
vTo | high endpoint (exclusive) of the returned bag |
vTo
ClassCastException | if vTo is not compatible with this bag's comparator (or, if the bag has no comparator, if vTo does not implement Comparable). Implementations may, but are not required to, throw this exception if vTo cannot be compared to elements currently in the bag. | |
NullPointerException | if vTo is NULL and this bag does not permit NULL elements | |
IllegalArgumentException | if this bag itself has a restricted range, and vTo lies outside the bounds of the range |
Reimplemented in SortedBag::ViewBag.
virtual SortedBag::Handle tailBag | ( | Object::View | vFrom | ) | [virtual] |
Returns a view of the portion of this bag whose elements are greater than or equal to vFrom
.
The returned bag is backed by this bag, so changes in the returned bag are reflected in this bag, and vice-versa. The returned bag supports all optional bag operations that this bag supports.
The returned bag will throw an IllegalArgumentException
on an attempt to insert an element outside its range.
vFrom | low endpoint (inclusive) of the returned bag |
vFrom
ClassCastException | if vFrom is not compatible with this bag's comparator (or, if the bag has no comparator, if vFrom does not implement Comparable). Implementations may, but are not required to, throw this exception if vFrom cannot be compared to elements currently in the bag. | |
NullPointerException | if vFrom is NULL and this bag does not permit NULL elements | |
IllegalArgumentException | if this bag itself has a restricted range, and vFrom lies outside the bounds of the range |
Reimplemented in SortedBag::ViewBag.
virtual Object::Holder first | ( | ) | const [virtual] |
Returns the first (lowest) element currently in this bag.
NoSuchElementException | if this bag is empty |
virtual Object::Holder last | ( | ) | const [virtual] |
Returns the last (highest) element currently in this bag.
NoSuchElementException | if this bag is empty |
virtual Object::Holder removeFirst | ( | ) | [virtual] |
Remove and return the least element in this bag, or NULL if empty.
virtual Object::Holder removeLast | ( | ) | [virtual] |
Remove and return the greatest element in this bag, or NULL if empty.
virtual Object::Holder unwrap | ( | Object::View | v | ) | const [virtual] |
Unwrap the specified element (which could be a wrapped or an "actual") element.
o | the element to unwrap |
virtual NavigableMap::Handle instantiateInternalMap | ( | Comparator::View | vComparator | ) | [protected, virtual] |
Factory for the navigable internal map to use to hold the bag elements.
comparator | the comparator to use to sort the bag elements |
virtual UniqueElement::View wrap | ( | Object::Holder | oh | ) | [protected, virtual] |
Wrap the specified element to ensure uniqueness.
oh | the element to wrap |