#include <coherence/util/AbstractCollection.hpp>
Inherits Object, and Collection.
Inherited by AbstractList, AbstractSet, SafeHashMap::EntrySet, and SortedBag.
Collection
interface, to minimize the effort required to implement this interface.
To implement an unmodifiable collection, the programmer needs only to extend this class and provide implementations for the size
and iterator
methods.
To implement a modifiable collection, the programmer must additionally override this class's add
, remove
, removeAll
, retainAll
and clear
methods (which otherwise throw an UnsupportedOperationException
).
The programmer should generally provide a void (no argument) and Collection
constructor, as per the recommendation in the Collection
interface specification.
Public Types | |||||||
typedef spec::Handle | Handle | ||||||
AbstractCollection Handle definition. | |||||||
typedef spec::View | View | ||||||
AbstractCollection View definition. | |||||||
typedef spec::Holder | Holder | ||||||
AbstractCollection Holder definition. | |||||||
Public Member Functions | |||||||
virtual size32_t | size () const =0 | ||||||
Return the number of elements in this collection.
| |||||||
virtual bool | isEmpty () const | ||||||
Determine whether this collection contains any elements.
| |||||||
virtual bool | contains (Object::View v) const | ||||||
Determine if this collection contains the specified element.
| |||||||
virtual ObjectArray::Handle | toArray (ObjectArray::Handle hao=NULL) const | ||||||
Return the contents of this collection as an ObjectArray. If the collection fits in the specified array, it is returned, otherwise, a new array is allocated that is the size of this collection. If this collection fits in the array with additional room then the element in the array immediately following the end of the collection is set to NULL. This can be useful in determining the length of this collection if the caller knows that the collection does not contain any NULL elements.
| |||||||
virtual bool | containsAll (Collection::View vc) const | ||||||
Determine if this collection contains all elements from the supplied collection.
| |||||||
virtual bool | add (Object::Holder oh) | ||||||
Add the given element to this collection.
| |||||||
virtual bool | addAll (Collection::View vc) | ||||||
Add all elements from the supplied collection to this collection.
| |||||||
virtual bool | remove (Object::View v) | ||||||
Remove the supplied element from this collection.
| |||||||
virtual bool | removeAll (Collection::View vc) | ||||||
Remove all instances of the elements in the supplied collection from this collection. Upon completion, contains() on this collection will return false for all elements in the supplied collection.
| |||||||
virtual bool | retainAll (Collection::View vc) | ||||||
Remove all elements from this collection that are not present in the supplied collection.
| |||||||
virtual void | clear () | ||||||
Remove all elements from this collection. | |||||||
virtual TypedHandle < const String > | toString () const | ||||||
Output a human-readable description of this Object to the given stream. Note that when overriding this method the return type must be TypedHandle<const String> rather then String::View. These two types are assignment compatible but not equivalent and declaring the override with String::View will not be a compatible override. coherence::lang::operator<<(std::ostream, Object::View) is defined and will call into the toString method, to output Objects. If a managed String object is desired, the COH_TO_STRING macro can be used to build up a String from streamable contents and is generally how toString() will be implemented.
Object::View vKey = ... Object::View vValue = ... std::cout << vKey << " = " << vValue << std::endl; String::View vs = COH_TO_STRING(vKey << " = " << vValue); The COH_TO_STRING macro is also the most common way to implement the toString method. For example:
virtual TypedHandle<const String> Person::toString() const { return COH_TO_STRING("Name: " << f_sName << " SSN: " << f_nSSN); }
|
virtual bool containsAll | ( | Collection::View | vc | ) | const [virtual] |
Determine if this collection contains all elements from the supplied collection.
vCol | the collection of elements to test for containment |
coherence::lang::NullPointerException | if the specified collection is NULL |
This implementation iterates over the specified collection, checking each element returned by the iterator in turn to see if it's contained in this collection. If all elements are so contained true
is returned, otherwise false
.
Implements Collection.
virtual bool add | ( | Object::Holder | oh | ) | [virtual] |
Add the given element to this collection.
oh | the element to add |
This implementation will throw a coherence::lang::UnsupportedOperationException
Implements Collection.
Reimplemented in CircularArrayList, DeltaSet, LinkedList, LiteSet, SortedBag, SortedBag::ViewBag, SubList, and SubSet.
virtual bool addAll | ( | Collection::View | vc | ) | [virtual] |
Add all elements from the supplied collection to this collection.
vCol | the collection of elements to add |
coherence::lang::NullPointerException | if the specified collection is NULL |
This implementation will throw a coherence::lang::UnsupportedOperationException unless add() is overridden (assuming the specified collection is non-empty).
Implements Collection.
Reimplemented in CircularArrayList, LinkedList, LiteSet, SubList, and SubSet.
virtual bool remove | ( | Object::View | v | ) | [virtual] |
Remove the supplied element from this collection.
v | the element to remove |
This implementation will throw a coherence::lang::UnsupportedOperationException unless add() is overridden (assuming the specified collection is non-empty).
Implements Collection.
Reimplemented in CircularArrayList, DeltaSet, LinkedList, LiteSet, SafeHashMap::EntrySet, SortedBag, SubList, and SubSet.
virtual bool removeAll | ( | Collection::View | vc | ) | [virtual] |
Remove all instances of the elements in the supplied collection from this collection.
Upon completion, contains() on this collection will return false for all elements in the supplied collection.
vCol | the collection of elements to remove |
coherence::lang::NullPointerException | if the specified collection is NULL |
This implementation will throw a coherence::lang::UnsupportedOperationException} unless remove() is overridden (assuming the specified collection is non-empty).
Implements Collection.
Reimplemented in CircularArrayList, LinkedList, LiteSet, and SubSet.
virtual bool retainAll | ( | Collection::View | vc | ) | [virtual] |
Remove all elements from this collection that are not present in the supplied collection.
vCol | the collection of elements to retain |
coherence::lang::NullPointerException | if the specified collection is NULL |
This implementation will throw a coherence::lang::UnsupportedOperationException unless remove() is overridden (assuming there are items to be removed by the operation).
Implements Collection.
Reimplemented in CircularArrayList, CircularArrayList::SubCircularArrayList, LinkedList, LinkedList::SubLinkedList, LiteSet, and SubSet.
virtual void clear | ( | ) | [virtual] |
Remove all elements from this collection.
This implementation will throw a coherence::lang::UnsupportedOperationException.
Implements Collection.
Reimplemented in CircularArrayList, CircularArrayList::SubCircularArrayList, DeltaSet, LinkedList, LinkedList::SubLinkedList, LiteSet, SafeHashMap::EntrySet, and SubSet.