![]() |
The Simons
|
#include <Collection.h>
Inheritance diagram for Collection:
The Collection class is the root of the collections hierarchy, which includes the Sequence, Unordered and Sorted collections. It defines the interface for adding, counting and visiting the elements of a Collection. The semantics of adding an element varies in each subclass, and may be position-sensitive, value-sensitive or disregard duplicates. Counting returns the size of the Collection. Elements may be visited in one pass, by iterating over the Collection using an index in the range 0..n-1 where n is the size of the Collection. Element membership is tested in a single pass, by default, but this is reimplemented more efficiently in descendant classes. Comparison of two Collections and hashing on a Collection are abstract, defined in subclasses. These operations expect to return a result based on the values, and possibly also the ordering, of elements. All the elements of one Collection may be added to another, according to the semantics of adding.
Public Member Functions | |
Collection () | |
Create an empty Collection. | |
virtual | ~Collection () |
Release a Collection. | |
virtual Void | readOn (ReaderID) |
Read this Collection on a Reader stream. | |
virtual Void | writeOn (WriterID) const |
Write this Object on a Writer stream. | |
virtual Natural | size () const |
Return the size of this Collection. | |
Boolean | empty () const |
Test if this Collection is empty. | |
virtual Boolean | has (ObjectID) const |
Test if this Collection contains a particular Object. | |
virtual ObjectID | item (Integer) const |
Select an Object contained in this Collection. | |
virtual Void | add (ObjectID) |
Add an Object to this Collection. | |
virtual Void | addAll (CollectionID) |
Add all the elements of another Collection to this Collection. | |
Protected Member Functions | |
Collection (const Collection &) | |
Copy another Collection. | |
Void | rangeExceeded (StringID, Integer) const |
Signal that this Collection has no element at this index. | |
Void | hasNoElements (StringID) const |
Signal that this Collection has no elements. | |
Void | hasNoElements (StringID, OutOfRangeID) const |
Signal that this Collection has no elements, after an out-of-range access. |
|
Copy another Collection. This secret copy constructor is provided to ensure that copying a Collection faithfully copies the parent Object.
|
|
Create an empty Collection.
|
|
Release a Collection.
|
|
Add an Object to this Collection. All Collections support the addition of elements. Collections of unique elements will only permit an element to be inserted once. Elements may be inserted in sequential order, or in random order, according to the semantics of the Collection. This method is abstract in Collection, since different Collections add their elements in different ways.
|
|
Add all the elements of another Collection to this Collection. All Collections support the inclusion of the elements of another Collection. Depending on the semantics of add(), this is equivalent to set union, bag union, sequence concatenation, or map union with override. By default, iterates over the other Collection using item(), up to the limit size() and uses add() to insert elements into this Collection. A subtype need only reimplement add() to alter the semantics of how elements are added to this Collection. This method allows a Collection of one type to add all the elements of another type of Collection, so is useful for converting between different types of Collection. It is safe to add all the elements of a Collection to itself.
Reimplemented in String. |
|
Test if this Collection is empty. Tests whether the size() of this Collection is zero, using suitable subclass implementations of size().
|
|
Test if this Collection contains a particular Object. Searches this Collection for an element that is EQUAL to the object, under compare(). By default, iterates over this Collection in linear time using item(), up to the limit size(), returning as soon as the object is found. This method should be reimplemented in subtypes that support fast searching.
|
|
Signal that this Collection has no elements, after an out-of-range access. Provided for convenience, to chain the two exceptions.
|
|
Signal that this Collection has no elements. Provided for convenience, this method is inherited by all Collections and may be used to raise a NoElements exception to signal that an attempt was made to return an element from an empty Collection.
|
|
Select an Object contained in this Collection. All Collections support access to their elements, in some order, via an index. This is achieved efficiently, either through providing direct random access, or through internal memos that record positions inside Collections. Repeated access to the same element is guaranteed to be in constant time. Forward iteration using an incrementing index is also very efficient. This method is abstract in Collection, since different Collections access their elements in different ways.
|
|
Signal that this Collection has no element at this index. Provided for convenience, this method is inherited by all Collections and may be used to raise an OutOfRange exception to signal that an attempt was made to access an element in this Collection at an out-of-range index.
|
|
Read this Collection on a Reader stream. The size of a Collection is encoded in the header processed by the Reader. This Collection determines its size from the Reader, then iterates for this number of times, using getField("item", anItem) to read each item, which it inserts using add(). Any subclass which expects to read its elements as a single block should reimplement this method.
Reimplemented from Object. Reimplemented in String. |
|
Return the size of this Collection. Counts the number of Object elements held in this Collection. This method is abstract in Collection, since different subclasses store their elements in different ways.
|
|
Write this Object on a Writer stream. The size of a Collection is encoded in the header by the Writer. This Collection expects the Writer to write out its size, then iterates for this number of times, using putField("item", item(i)) to write each item individually. Any subclass which expects to write its elements as a single block should reimplement this method.
Reimplemented from Object. Reimplemented in String. |