Contents

Class OrderedCollection


Inheritance:

Object  »
   Collection  »
     SequenceableCollection  »
       OrderedCollection

This is a Collection that keeps its elements in the order in which they were added. It can be understood as an array that grows automatically as needed. OrderedCollection is an often used collection.

Class OrderedCollection represents a collection of elements explicitly ordered by the sequence in which objects are added and removed. The elements of an OrderedCollection are accessible by integer indices running from 1 to the number of elements in the collection. OrderedCollections can act as stacks or queues. A stack is a sequential list for which all additions and deletions are made at one end of the list; a queue is a sequential list for which all additions are made at one end, but all deletions are made from the other end.

An OrderedCollection, like an Array, has an integer index and accepts any object as an element. An OrderedCollection goes further, however, in permitting elements to be added and removed freely. It is widely used in situations requiring that the order in which the elements were added be preserved. In addition, it is used as a stack (the last element added is the first element removed) or a queue (first in, first out). An OrderedCollection does not support sorting (see SortedCollection). An OrderedCollection is typically created by sending new to the class. In addition to its inherited abilities, an OrderedCollection knows how to:

Instance Variables:

Protocol Compatible Classes:

SortedCollection
Set
Bag
add:
(addAll:)
remove:
(removeAll:)
includes:
indexOf:
-
-

Implementation Note

The elements of an OrdredCollection are externally indexed by integers from 1 up to the size of the collection. Internally, OrderedCollection uses an index that runs from firstIndex to lastIndex. Methods that take an internal index as method argument are meant for use by OrderedCollection only, their use from outside an OrderedCollection will cause erroneous results. Here is a table of these private methods with their public counterparts:


Contents