Class TList

Description

Implements interfaces:

  • IteratorAggregate (internal interface)
  • ArrayAccess (internal interface)
  • Countable (internal interface)

TList class

TList implements an integer-indexed collection class.

You can access, append, insert, remove an item by using itemAt, add, insertAt, 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().

  • author: Qiang Xue <qiang.xue@gmail.com>
  • version: $Id: TList.php 2996 2011-06-20 15:24:57Z ctrlaltca@gmail.com $
  • since: 3.0

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

TComponent
   |
   --TList
Direct descendents
Class Description
TCacheDependencyList TCacheDependencyList class.
TListItemCollection TListItemCollection class.
TPagedList TPagedList class
TPriorityList TPriorityList 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.
TRepeaterItemCollection TRepeaterItemCollection 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 count ()
integer getCount ()
Iterator getIterator ()
boolean getReadOnly ()
integer indexOf (mixed $item)
int insertAfter (mixed $baseitem, mixed $item)
void insertAt (integer $index, mixed $item)
int insertBefore (mixed $baseitem, 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.

  • throws: TInvalidDataTypeException If data is not null and neither an array nor an iterator.
  • access: public
TList __construct ([array|Iterator $data = null], [boolean $readOnly = false])
  • array|Iterator $data: the initial data. Default is null, meaning no initialization.
  • boolean $readOnly: whether the list is read-only

Redefined in descendants as:
add (line 135)

Appends an item at the end of the list.

  • return: the zero-based index at which the item is added
  • throws: TInvalidOperationException if the list is read-only
  • access: public
integer add (mixed $item)
  • mixed $item: new item

Redefined in descendants as:
  • TPriorityList::add() : Appends an item into the list at the end of the specified priority. The position of the added item may not be at the end of the list.
clear (line 227)

Removes all items in the list.

  • throws: TInvalidOperationException if the list is read-only
  • access: public
void clear ()

Redefined in descendants as:
contains (line 237)
  • return: whether the list contains the item
  • access: public
boolean contains (mixed $item)
  • mixed $item: the item

Redefined in descendants as:
copyFrom (line 316)

Copies iterable data into the list.

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

  • throws: TInvalidDataTypeException If data is neither an array nor a Traversable.
  • access: public
void copyFrom (mixed $data)
  • mixed $data: the data to be copied from, must be an array or object implementing Traversable

Redefined in descendants as:
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 ()

Implementation of:
Countable::count

Redefined in descendants as:
getCount (line 109)
  • return: the number of items in the list
  • access: public
integer getCount ()

Redefined in descendants as:
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 ()

Implementation of:
IteratorAggregate::getIterator

Redefined in descendants as:
getReadOnly (line 73)
  • return: whether this list is read-only or not. Defaults to false.
  • access: public
boolean getReadOnly ()
indexOf (line 246)
  • 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:
insertAfter (line 287)

Finds the base item. If found, the item is inserted after it.

  • return: the index where the item is inserted
  • since: 3.2a
  • throws: TInvalidDataValueException if the base item is not within this list
  • throws: TInvalidOperationException if the list is read-only
  • access: public
int insertAfter (mixed $baseitem, mixed $item)
  • mixed $baseitem: the base item which comes before the second parameter when added to the list
  • mixed $item: the item

Redefined in descendants as:
  • TPriorityList::insertAfter() : This inserts an item after another item within the list. It uses the same priority as the found index item and places the new item after it.
insertAt (line 150)

Inserts an item at the specified position.

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

  • throws: TInvalidOperationException if the list is read-only
  • throws: TInvalidDataValueException If the index specified exceeds the bound
  • access: public
void insertAt (integer $index, mixed $item)
  • integer $index: the specified position.
  • mixed $item: new item

Redefined in descendants as:
insertBefore (line 263)

Finds the base item. If found, the item is inserted before it.

  • return: the index where the item is inserted
  • since: 3.2a
  • throws: TInvalidDataValueException if the base item is not within this list
  • throws: TInvalidOperationException if the list is read-only
  • access: public
int insertBefore (mixed $baseitem, mixed $item)
  • mixed $baseitem: the base item which will be pushed back by the second parameter
  • mixed $item: the item

Redefined in descendants as:
  • TPriorityList::insertBefore() : This inserts an item before another item within the list. It uses the same priority as the found index item and places the new item before it.
itemAt (line 121)

Returns the item at the specified offset.

This method is exactly the same as offsetGet.

  • return: the item at the index
  • throws: TInvalidDataValueException if the index is out of the range
  • access: public
mixed itemAt (integer $index)
  • integer $index: the index of the item

Redefined in descendants as:
mergeWith (line 335)

Merges iterable data into the map.

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

  • throws: TInvalidDataTypeException If data is neither an array nor an iterator.
  • access: public
void mergeWith (mixed $data)
  • mixed $data: the data to be merged with, must be an array or object implementing Traversable

Redefined in descendants as:
offsetExists (line 352)

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

Implementation of:
ArrayAccess::offsetExists

Redefined in descendants as:
offsetGet (line 364)

Returns the item at the specified offset.

This method is required by the interface ArrayAccess.

  • return: the item at the offset
  • throws: TInvalidDataValueException if the offset is invalid
  • access: public
mixed offsetGet (integer $offset)
  • integer $offset: the offset to retrieve item.

Implementation of:
ArrayAccess::offsetGet

Redefined in descendants as:
offsetSet (line 375)

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

Implementation of:
ArrayAccess::offsetSet

Redefined in descendants as:
offsetUnset (line 391)

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

Implementation of:
ArrayAccess::offsetUnset

Redefined in descendants as:
remove (line 177)

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
  • throws: TInvalidOperationException if the list is read-only
  • throws: TInvalidDataValueException If the item does not exist
  • access: public
integer remove (mixed $item)
  • mixed $item: the item to be removed.

Redefined in descendants as:
removeAt (line 200)

Removes an item at the specified position.

  • return: the removed item.
  • throws: TInvalidOperationException if the list is read-only
  • throws: TInvalidDataValueException If the index specified exceeds the bound
  • access: public
mixed removeAt (integer $index)
  • integer $index: the index of the item to be removed.

Redefined in descendants as:
setReadOnly (line 81)
  • access: protected
void setReadOnly (boolean $value)
  • boolean $value: whether this list is read-only or not
toArray (line 305)
  • return: the list of items in array
  • access: public
array toArray ()

Redefined in descendants as:

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::__call()
TComponent::__get()
TComponent::__set()
TComponent::__sleep()
TComponent::__wakeup()

Documentation generated on Mon, 25 Jun 2012 14:38:34 +0200 by phpDocumentor 1.4.3