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:
Keyword

Class TList

TComponent
   |
   --TList

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,

  1. $list[]=$item; // append at the end
  2. $list[$index]=$item; // $index must be between 0 and $list->Count
  3. unset($list[$index]); // remove the item at $index
  4. if(isset($list[$index])) // if the list has an item at $index
  5. foreach($list as $index=>$item) // traverse each item in the list
  6. $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
Iterator
Returns an iterator for traversing the items in the list.
boolean
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$itemnew 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$itemthe 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$datathe data to be copied from, must be an array or object implementing Traversable
Output
Exception
throwsTInvalidDataTypeException 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$itemthe 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$indexthe specified position.
mixed$itemnew item
Output
Exception
throwsTInvalidDataValueException If the index specified exceeds the bound
throwsTInvalidOperationException 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$indexthe index of the item
Output
mixed the item at the index
Exception
throwsTInvalidDataValueException 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$datathe data to be merged with, must be an array or object implementing Traversable
Output
Exception
throwsTInvalidDataTypeException 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$offsetthe 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$offsetthe offset to retrieve item.
Output
mixed the item at the offset
Exception
throwsTInvalidDataValueException 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$offsetthe offset to set item
mixed$itemthe 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$offsetthe 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$itemthe item to be removed.
Output
integer the index at which the item is being removed
Exception
throwsTInvalidDataValueException If the item does not exist

removeAt

public mixed removeAt (integer $index )

Removes an item at the specified position.

Input
integer$indexthe index of the item to be removed.
Output
mixed the removed item.
Exception
throwsTInvalidDataValueException If the index specified exceeds the bound
throwsTInvalidOperationException if the list is read-only

setReadOnly

protected void setReadOnly (boolean $value )

Input
boolean$valuewhether this list is read-only or not
Output
Exception

toArray

public array toArray ()

Output
array the list of items in array
Exception