## 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
      $n=count($list); // returns the number of items in the list

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

- since: 3.0
- version: $Id: TList.php 1464 2006-10-18 01:38:47Z xue $
- author: Qiang Xue <qiang.xue@gmail.com>

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

    TComponent
       |
       --TList

Direct descendents

Class | Description
--- | ---
TCacheDependencyList | TCacheDependencyList class.
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.
TWizardStepCollection | TWizardStepCollection class.
TRssFeedItemList | TRssFeedItemList 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 count ()
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 63)

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.
- TSqlMapPagedList::__construct() : Create a new SqlMap paged list.
- THttpCookieCollection::__construct() : Constructor.
- TControlCollection::__construct() : Constructor.
- TEmptyControlCollection::__construct() : Constructor.
- TDataGridColumnCollection::__construct() : Constructor.
- TWizardStepCollection::__construct() : Constructor.
- TXmlElementList::__construct() : Constructor.

add (line 134)

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 219)

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 229)

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

boolean contains (mixed $item)

- mixed $item: the item

copyFrom (line 260)

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

count (line 101)

Returns the number of items in the list.

This method is required by Countable interface.

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

integer count ()
getCount (line 109)

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

integer getCount ()

Redefined in descendants as:

- TPagedList::getCount()

getIterator (line 91)

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 73)

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

boolean getReadOnly ()
indexOf (line 238)

- 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 149)

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:

- TCacheDependencyList::insertAt() : Inserts an item at the specified position.
- 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.
- TEmptyControlCollection::insertAt() : Inserts an item at the specified position.
- TViewCollection::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.
- 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.
- TActiveListItemCollection::insertAt() : Inserts an item into the collection.
- TRepeaterItemCollection::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 121)

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 279)

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 296)

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 308)

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 319)

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 335)

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 175)

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 193)

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.
- TActiveListItemCollection::removeAt() : Removes an item from at specified index.
- TWizardStepCollection::removeAt() : Removes an item at the specified position.
- TXmlElementList::removeAt() : Removes an item at the specified position.

setReadOnly (line 81)

- access: protected

void setReadOnly (boolean $value)

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

toArray (line 249)

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

array toArray ()

Redefined in descendants as:

- TPagedList::toArray()

#### Inherited Methods

Inherited From TComponent

> TComponent::addParsedObject()
> TComponent::attachEventHandler()
> TComponent::canGetProperty()
> TComponent::canSetProperty()
> TComponent::createdOnTemplate()
> 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 Sun, 14 Jan 2007 21:43:05 -0500 by phpDocumentor 1.3.0RC4