- Home
- About
- Testimonials
- Demos
- Download
- Documentation
- Blogs
- Forum
- Support

Packages:
default
System
System.Caching
System.Collections
System.Data
System.Data.ActiveRecord
System.Data.ActiveRecord.Relations
System.Data.ActiveRecord.Scaffold
System.Data.ActiveReecord.Scaffold.InputBuilder
System.Data.Commom.Sqlite
System.Data.Common
System.Data.Common.Mssql
System.Data.Common.Mysql
System.Data.Common.Oracle
System.Data.Common.Pgsql
System.Data.Common.Sqlite
System.Data.DataGateway
System.Data.SqlMap
System.Data.SqlMap.Configuration
System.Data.SqlMap.Statements
System.Exceptions
System.I18N
System.IO
System.Security
System.Util
System.Web
System.Web.Services
System.Web.UI
System.Web.UI.ActiveControls
System.Web.UI.WebControls
System.Web.UI.WebControls.assets
System.Xml
Classes:
TAttributeCollection
TDummyDataSource
TDummyDataSourceIterator
TList
TListIterator
TMap
TMapIterator
TPagedDataSource
TPagedList
TPagedListFetchDataEventParameter
TPagedListIterator
TPagedListPageChangedEventParameter
TPagedMapIterator
TQueue
TQueueIterator
TStack
TStackIterator

Keyword

# Class TList

    TComponent
       |
       --TList

#### Direct Known Sub-classes:

THotSpotCollection , TDataListItemCollection , TListItemCollection , TDataGridItemCollection , TDataGridColumnCollection , TMetaTagCollection , TWizardStepCollection , TRepeaterItemCollection , TControlCollection , THttpCookieCollection , TXmlElementList , TPagedList , TCacheDependencyList , TAuthorizationRuleCollection

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
Author: Qiang Xue <qiang.xue@gmail.com>

Constructor Summary
public | __construct Array Constructor.

Method Summary
integer | add ( mixed $item) Appends an item at the end of the list.
void | clear () Removes all items in the list.
boolean | contains ( mixed $item)
void | copyFrom ( mixed $data) Copies iterable data into the list.
integer | count () Returns the number of items in the list.
integer | getCount ()
Iterator | getIterator () Returns an iterator for traversing the items in the list.
boolean | getReadOnly ()
integer | indexOf ( mixed $item)
void | insertAt ( integer $index, mixed $item) Inserts an item at the specified position.
mixed | itemAt ( integer $index) Returns the item at the specified offset.
void | mergeWith ( mixed $data) Merges iterable data into the map.
boolean | offsetExists ( integer $offset) Returns whether there is an item at the specified offset.
mixed | offsetGet ( integer $offset) Returns the item at the specified offset.
void | offsetSet ( integer $offset, mixed $item) Sets the item at the specified offset.
void | offsetUnset ( integer $offset) Unsets the item at the specified offset.
integer | remove ( mixed $item) Removes an item from the list.
mixed | removeAt ( integer $index) Removes an item at the specified position.
protected void | setReadOnly ( boolean $value)
array | toArray ()

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

Constructor Details

## __construct

public __construct | Array

Constructor.

Initializes the list with an array or an iterable object.

Throws: TInvalidDataTypeException If data is not null and neither an array nor an iterator.

Method Details

## add

public integer add | (mixed $item )

Appends an item at the end of the list.

Input
mixed | $item | new item
Output
integer | the zero-based index at which the item is added
Exception

## clear

public void clear | ()

Removes all items in the list.

Output
Exception

## contains

public boolean contains | (mixed $item )

Input
mixed | $item | the item
Output
boolean | whether the list contains the item
Exception

## copyFrom

public void copyFrom | (mixed $data )

Copies iterable data into the list.

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

Input
mixed | $data | the data to be copied from, must be an array or object implementing Traversable
Output
Exception
throws | TInvalidDataTypeException If data is neither an array nor a Traversable.

## count

public integer count | ()

Returns the number of items in the list.

This method is required by Countable interface.

Output
integer | number of items in the list.
Exception

## getCount

public integer getCount | ()

Output
integer | the number of items in the list
Exception

## getIterator

public Iterator getIterator | ()

Returns an iterator for traversing the items in the list.

This method is required by the interface IteratorAggregate.

Output
Iterator | an iterator for traversing the items in the list.
Exception

## getReadOnly

public boolean getReadOnly | ()

Output
boolean | whether this list is read-only or not. Defaults to false.
Exception

## indexOf

public integer indexOf | (mixed $item )

Input
mixed | $item | the item
Output
integer | the index of the item in the list (0 based), -1 if not found.
Exception

## insertAt

public void insertAt | (integer $index , mixed $item )

Inserts an item at the specified position.

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

Input
integer | $index | the specified position.
mixed | $item | new item
Output
Exception
throws | TInvalidDataValueException If the index specified exceeds the bound
throws | TInvalidOperationException if the list is read-only

## itemAt

public mixed itemAt | (integer $index )

Returns the item at the specified offset.

This method is exactly the same as offsetGet.

Input
integer | $index | the index of the item
Output
mixed | the item at the index
Exception
throws | TInvalidDataValueException if the index is out of the range

## mergeWith

public void mergeWith | (mixed $data )

Merges iterable data into the map.

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

Input
mixed | $data | the data to be merged with, must be an array or object implementing Traversable
Output
Exception
throws | TInvalidDataTypeException If data is neither an array nor an iterator.

## offsetExists

public boolean offsetExists | (integer $offset )

Returns whether there is an item at the specified offset.

This method is required by the interface ArrayAccess.

Input
integer | $offset | the offset to check on
Output
Exception

## offsetGet

public mixed offsetGet | (integer $offset )

Returns the item at the specified offset.

This method is required by the interface ArrayAccess.

Input
integer | $offset | the offset to retrieve item.
Output
mixed | the item at the offset
Exception
throws | TInvalidDataValueException if the offset is invalid

## offsetSet

public void offsetSet | (integer $offset , mixed $item )

Sets the item at the specified offset.

This method is required by the interface ArrayAccess.

Input
integer | $offset | the offset to set item
mixed | $item | the item value
Output
Exception

## offsetUnset

public void offsetUnset | (integer $offset )

Unsets the item at the specified offset.

This method is required by the interface ArrayAccess.

Input
integer | $offset | the offset to unset item
Output
Exception

## remove

public integer remove | (mixed $item )

Removes an item from the list.

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

Input
mixed | $item | the item to be removed.
Output
integer | the index at which the item is being removed
Exception
throws | TInvalidDataValueException If the item does not exist

## removeAt

public mixed removeAt | (integer $index )

Removes an item at the specified position.

Input
integer | $index | the index of the item to be removed.
Output
mixed | the removed item.
Exception
throws | TInvalidDataValueException If the index specified exceeds the bound
throws | TInvalidOperationException if the list is read-only

## setReadOnly

protected void setReadOnly | (boolean $value )

Input
boolean | $value | whether this list is read-only or not
Output
Exception

## toArray

public array toArray | ()

Output
array | the list of items in array
Exception