Class 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().
Constructor Summary |
public |
Constructor.
|
Method Summary |
integer
|
Appends an item at the end of the list.
|
void
|
Removes all items in the list.
|
boolean
|
|
void
|
Copies iterable data into the list.
|
integer
|
Returns the number of items in the list.
|
integer
|
|
Iterator
|
Returns an iterator for traversing the items in the list.
|
boolean
|
|
integer
|
|
void
|
Inserts an item at the specified position.
|
mixed
|
Returns the item at the specified offset.
|
void
|
Merges iterable data into the map.
|
boolean
|
Returns whether there is an item at the specified offset.
|
mixed
|
Returns the item at the specified offset.
|
void
|
Sets the item at the specified offset.
|
void
|
Unsets the item at the specified offset.
|
integer
|
Removes an item from the list.
|
mixed
|
Removes an item at the specified position.
|
protected
void
|
|
array
|
|
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
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
Removes all items in the list.
|
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
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
Output |
array
| the list of items in array |
Exception |
|
|