AbstractCollection Class Reference

#include <coherence/util/AbstractCollection.hpp>

Inherits Object, and Collection.

Inherited by AbstractList, AbstractSet, and SafeHashMap::EntrySet.

List of all members.


Detailed Description

This class provides a skeletal implementation of the 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.

See also:
Collection

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.

Returns:
the number of elements in this collection

virtual bool isEmpty () const
 Determine whether this collection contains any elements.

Returns:
true if this collection has no elements

virtual bool contains (Object::View v) const
 Determine if this collection contains the specified element.

Parameters:
v the element to test for containment
Returns:
true iff this collection contains the given element

virtual
ObjectArray::Handle 
toArray () const
 Return the contents of this collection as an ObjectArray.

Returns:
a new ObjectArray containing all the elements of this collection in the same order as returned by the collection's Iterator
See also:
Iterator

virtual bool containsAll (Collection::View vc) const
 Determine if this collection contains all elements from the supplied collection.

Parameters:
vCol the collection of elements to test for containment
Returns:
true iff this collection contains all elements from the supplied collection
Exceptions:
coherence::lang::NullPointerException if the specified collection is NULL
See also:
contains()

virtual bool add (Object::Holder oh)
 Add the given element to this collection.

Parameters:
oh the element to add
Returns:
true iff this collection was modified as a result of this operation

virtual bool addAll (Collection::View vc)
 Add all elements from the supplied collection to this collection.

Parameters:
vCol the collection of elements to add
Returns:
true iff this collection was modified as a result of this operation
Exceptions:
coherence::lang::NullPointerException if the specified collection is NULL
See also:
add()

virtual bool remove (Object::View v)
 Remove the supplied element from this collection.

Parameters:
v the element to remove
Returns:
true iff this collection was modified as a result of this operation

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.

Parameters:
vCol the collection of elements to remove
Returns:
true iff this collection was modified as a result of this operation
Exceptions:
coherence::lang::NullPointerException if the specified collection is NULL
See also:
remove()

contains()


virtual bool retainAll (Collection::View vc)
 Remove all elements from this collection that are not present in the supplied collection.

Parameters:
vCol the collection of elements to retain
Returns:
true iff this collection was modified as a result of this operation.
Exceptions:
coherence::lang::NullPointerException if the specified collection is NULL
See also:
remove()

contains()


virtual void clear ()
 Remove all elements from this collection.
virtual void toStream (std::ostream &out) const
 Output a human-readable description of this Object to the given stream.

coherence::lang::operator<<(std::ostream, Object::View) is defined and will call into the toStream method, to output Objects. If a manged String object is desired, the COH_TO_STRING macro can be used to build up a String from streamable contents.

 Object::View vKey   = ...
 Object::View vValue = ...
 std::cout << vKey << " = " << vValue << std::endl;

 String::Handle hs = COH_TO_STRING(vKey << " = " << vValue);

Parameters:
out the stream used to output the description


Member Function Documentation

virtual bool containsAll ( Collection::View  vc  )  const [virtual]

Determine if this collection contains all elements from the supplied collection.

Parameters:
vCol the collection of elements to test for containment
Returns:
true iff this collection contains all elements from the supplied collection
Exceptions:
coherence::lang::NullPointerException if the specified collection is NULL
See also:
contains()

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.

Parameters:
oh the element to add
Returns:
true iff this collection was modified as a result of this operation

This implementation will throw a coherence::lang::UnsupportedOperationException

Implements Collection.

Reimplemented in LinkedList, and SubList.

virtual bool addAll ( Collection::View  vc  )  [virtual]

Add all elements from the supplied collection to this collection.

Parameters:
vCol the collection of elements to add
Returns:
true iff this collection was modified as a result of this operation
Exceptions:
coherence::lang::NullPointerException if the specified collection is NULL
See also:
add()

This implementation will throw a coherence::lang::UnsupportedOperationException unless add() is overridden (assuming the specified collection is non-empty).

Implements Collection.

Reimplemented in LinkedList, and SubList.

virtual bool remove ( Object::View  v  )  [virtual]

Remove the supplied element from this collection.

Parameters:
v the element to remove
Returns:
true iff this collection was modified as a result of this operation

This implementation will throw a coherence::lang::UnsupportedOperationException unless add() is overridden (assuming the specified collection is non-empty).

Implements Collection.

Reimplemented in LinkedList, SafeHashMap::EntrySet, and SubList.

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.

Parameters:
vCol the collection of elements to remove
Returns:
true iff this collection was modified as a result of this operation
Exceptions:
coherence::lang::NullPointerException if the specified collection is NULL
See also:
remove()

contains()

This implementation will throw a coherence::lang::UnsupportedOperationException} unless remove() is overridden (assuming the specified collection is non-empty).

Implements Collection.

Reimplemented in LinkedList.

virtual bool retainAll ( Collection::View  vc  )  [virtual]

Remove all elements from this collection that are not present in the supplied collection.

Parameters:
vCol the collection of elements to retain
Returns:
true iff this collection was modified as a result of this operation.
Exceptions:
coherence::lang::NullPointerException if the specified collection is NULL
See also:
remove()

contains()

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 LinkedList, and LinkedList::SubLinkedList.

virtual void clear (  )  [virtual]

Remove all elements from this collection.

This implementation will throw a coherence::lang::UnsupportedOperationException.

Implements Collection.

Reimplemented in LinkedList, LinkedList::SubLinkedList, and SafeHashMap::EntrySet.


The documentation for this class was generated from the following file: Copyright (c) 2000-2008 Oracle. All rights reserved.