## Class TList

Description

Implements interfaces:

TList class

TList implements an integer-indexed collection class.

You can access, append, insert, remove an item by using itemAt, add, insert, remove, and removeAt. To get the number of the items in the list, use getCount. TList can also be used like a regular array as follows,

     $list[]=$item;  // append at the end
      $list[$index]=$item; // $index must be between 0 and $list->Count
      unset($list[$index]); // remove the item at $index
      if(isset($list[$index])) // if the list has an item at $index
      foreach($list as $index=>$item) // traverse each item in the list

Note, count($list) will always return 1. You should use getCount() to determine the number of items in the list.

To extend TList by doing additional operations with each addition or removal operations, override insertAt(), and removeAt().

- since: 3.0
- version: $Revision: $ $Date: $
- author: Qiang Xue <qiang.xue@gmail.com>

Located in /Collections/TList.php (line 40)

    TComponent
       |
       --TList

Direct descendents

Class | Description
--- | ---
TPagedList | TPagedList class
TAuthorizationRuleCollection | TAuthorizationRuleCollection class.
THttpCookieCollection | THttpCookieCollection class.
TControlCollection | TControlCollection class
TDataGridItemCollection | TDataGridItemCollection class.
TDataGridColumnCollection | TDataGridColumnCollection class.
TDataListItemCollection | TDataListItemCollection class.
TMetaTagCollection | TMetaTagCollection class
THotSpotCollection | THotSpotCollection class.
TListItemCollection | TListItemCollection class.
TRepeaterItemCollection | TRepeaterItemCollection class.
TTableRowCollection | TTableRowCollection class.
TTableCellCollection | TTableCellCollection class.
TWizardStepCollection | TWizardStepCollection class.
TXmlElementList | TXmlElementList class.

Method Summary
TList __construct ([array|Iterator $data = null], [boolean $readOnly = false])
integer add (mixed $item)
void clear ()
boolean contains (mixed $item)
void copyFrom (mixed $data)
integer getCount ()
Iterator getIterator ()
boolean getReadOnly ()
integer indexOf (mixed $item)
void insertAt (integer $index, mixed $item)
mixed itemAt (integer $index)
void mergeWith (mixed $data)
boolean offsetExists (integer $offset)
mixed offsetGet (integer $offset)
void offsetSet (integer $offset, mixed $item)
void offsetUnset (integer $offset)
integer remove (mixed $item)
mixed removeAt (integer $index)
void setReadOnly (boolean $value)
array toArray ()
Methods
Constructor __construct (line 64)

Constructor.

Initializes the list with an array or an iterable object.

- access: public
- throws: TInvalidDataTypeException If data is not null and neither an array nor an iterator.

TList __construct ([array|Iterator $data = null], [boolean $readOnly = false])

- array|Iterator $data: the intial data. Default is null, meaning no initialization.
- boolean $readOnly: whether the list is read-only

Redefined in descendants as:

- TPagedList::__construct() : Constructor.
- THttpCookieCollection::__construct() : Constructor.
- TControlCollection::__construct() : Constructor.
- TEmptyControlCollection::__construct() : Constructor.
- TDataGridColumnCollection::__construct() : Constructor.
- TTableRowCollection::__construct() : Constructor.
- TTableCellCollection::__construct() : Constructor.
- TWizardStepCollection::__construct() : Constructor.
- TXmlElementList::__construct() : Constructor.

add (line 125)

Appends an item at the end of the list.

- return: the zero-based index at which the item is added
- access: public

integer add (mixed $item)

- mixed $item: new item

clear (line 210)

Removes all items in the list.

- access: public

void clear ()

Redefined in descendants as:

- TControlCollection::clear() : Overrides the parent implementation by invoking TControl::clearNamingContainer

contains (line 220)

- return: whether the list contains the item
- access: public

boolean contains (mixed $item)

- mixed $item: the item

copyFrom (line 251)

Copies iterable data into the list.

Note, existing data in the list will be cleared first.

- access: public
- throws: TInvalidDataTypeException If data is neither an array nor a Traversable.

void copyFrom (mixed $data)

- mixed $data: the data to be copied from, must be an array or object implementing Traversable

getCount (line 100)

- return: the number of items in the list
- access: public

integer getCount ()

Redefined in descendants as:

- TPagedList::getCount()

getIterator (line 92)

Returns an iterator for traversing the items in the list.

This method is required by the interface IteratorAggregate.

- return: an iterator for traversing the items in the list.
- access: public

Iterator getIterator ()

Redefined in descendants as:

- TPagedList::getIterator()

getReadOnly (line 74)

- return: whether this list is read-only or not. Defaults to false.
- access: public

boolean getReadOnly ()
indexOf (line 229)

- return: the index of the item in the list (0 based), -1 if not found.
- access: public

integer indexOf (mixed $item)

- mixed $item: the item

Redefined in descendants as:

- TPagedList::indexOf()

insertAt (line 140)

Inserts an item at the specified position.

Original item at the position and the next items will be moved one step towards the end.

- access: public
- throws: TInvalidDataValueException If the index specified exceeds the bound
- throws: TInvalidOperationException if the list is read-only

void insertAt (integer $index, mixed $item)

- integer $index: the speicified position.
- mixed $item: new item

Redefined in descendants as:

- TAuthorizationRuleCollection::insertAt() : Inserts an item at the specified position.
- THttpCookieCollection::insertAt() : Inserts an item at the specified position.
- TControlCollection::insertAt() : Inserts an item at the specified position.
- TViewCollection::insertAt() : Inserts an item at the specified position.
- TDataGridItemCollection::insertAt() : Inserts an item at the specified position.
- TDataGridColumnCollection::insertAt() : Inserts an item at the specified position.
- TDataListItemCollection::insertAt() : Inserts an item at the specified position.
- TMetaTagCollection::insertAt() : Inserts an item at the specified position.
- THotSpotCollection::insertAt() : Inserts an item at the specified position.
- TListItemCollection::insertAt() : Inserts an item into the collection.
- TRepeaterItemCollection::insertAt() : Inserts an item at the specified position.
- TTableRowCollection::insertAt() : Inserts an item at the specified position.
- TTableCellCollection::insertAt() : Inserts an item at the specified position.
- TWizardStepCollection::insertAt() : Inserts an item at the specified position.
- TXmlElementList::insertAt() : Inserts an item at the specified position.

itemAt (line 112)

Returns the item at the specified offset.

This method is exactly the same as offsetGet.

- return: the item at the index
- access: public
- throws: TInvalidDataValueException if the index is out of the range

mixed itemAt (integer $index)

- integer $index: the index of the item

Redefined in descendants as:

- TPagedList::itemAt() : Returns the item at the specified offset.
- THttpCookieCollection::itemAt()

mergeWith (line 270)

Merges iterable data into the map.

New data will be appended to the end of the existing data.

- access: public
- throws: TInvalidDataTypeException If data is neither an array nor an iterator.

void mergeWith (mixed $data)

- mixed $data: the data to be merged with, must be an array or object implementing Traversable

offsetExists (line 287)

Returns whether there is an item at the specified offset.

This method is required by the interface ArrayAccess.

- access: public

boolean offsetExists (integer $offset)

- integer $offset: the offset to check on

Redefined in descendants as:

- TPagedList::offsetExists() : Returns whether there is an item at the specified offset.

offsetGet (line 299)

Returns the item at the specified offset.

This method is required by the interface ArrayAccess.

- return: the item at the offset
- access: public
- throws: TInvalidDataValueException if the offset is invalid

mixed offsetGet (integer $offset)

- integer $offset: the offset to retrieve item.

Redefined in descendants as:

- TPagedList::offsetGet() : Returns the item at the specified offset.

offsetSet (line 310)

Sets the item at the specified offset.

This method is required by the interface ArrayAccess.

- access: public

void offsetSet (integer $offset, mixed $item)

- integer $offset: the offset to set item
- mixed $item: the item value

offsetUnset (line 326)

Unsets the item at the specified offset.

This method is required by the interface ArrayAccess.

- access: public

void offsetUnset (integer $offset)

- integer $offset: the offset to unset item

remove (line 166)

Removes an item from the list.

The list will first search for the item. The first item found will be removed from the list.

- return: the index at which the item is being removed
- access: public
- throws: TInvalidDataValueException If the item does not exist

integer remove (mixed $item)

- mixed $item: the item to be removed.

removeAt (line 184)

Removes an item at the specified position.

- return: the removed item.
- access: public
- throws: TInvalidDataValueException If the index specified exceeds the bound
- throws: TInvalidOperationException if the list is read-only

mixed removeAt (integer $index)

- integer $index: the index of the item to be removed.

Redefined in descendants as:

- THttpCookieCollection::removeAt() : Removes an item at the specified position.
- TControlCollection::removeAt() : Removes an item at the specified position.
- TTableRowCollection::removeAt() : Removes an item at the specified position.
- TTableCellCollection::removeAt() : Removes an item at the specified position.
- TWizardStepCollection::removeAt() : Removes an item at the specified position.
- TXmlElementList::removeAt() : Removes an item at the specified position.

setReadOnly (line 82)

- access: protected

void setReadOnly (boolean $value)

- boolean $value: whether this list is read-only or not

toArray (line 240)

- return: the list of items in array
- access: public

array toArray ()

Redefined in descendants as:

- TPagedList::toArray()

#### Inherited Methods

Inherited From TComponent

> TComponent::attachEventHandler()
> TComponent::canGetProperty()
> TComponent::canSetProperty()
> TComponent::detachEventHandler()
> TComponent::evaluateExpression()
> TComponent::evaluateStatements()
> TComponent::getEventHandlers()
> TComponent::getSubProperty()
> TComponent::hasEvent()
> TComponent::hasEventHandler()
> TComponent::hasProperty()
> TComponent::raiseEvent()
> TComponent::setSubProperty()
> TComponent::__get()
> TComponent::__set()

Documentation generated on Mon, 01 May 2006 23:03:58 -0400 by phpDocumentor 1.3.0RC4