[ Index ]
 

Code source de PRADO 3.0.6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/framework/Collections/ -> TList.php (sommaire)

TList, TListIterator classes

Author: Qiang Xue <qiang.xue@gmail.com>
Copyright: Copyright © 2005 PradoSoft
License: http://www.pradosoft.com/license/
Version: $Id: TList.php 1461 2006-10-13 00:31:09Z xue $
Poids: 430 lignes (11 kb)
Inclus ou requis: 1 fois
Référencé: 0 fois
Nécessite: 0 fichiers

Définit 2 classes

TList:: (21 méthodes):
  __construct()
  getReadOnly()
  setReadOnly()
  getIterator()
  count()
  getCount()
  itemAt()
  add()
  insertAt()
  remove()
  removeAt()
  clear()
  contains()
  indexOf()
  toArray()
  copyFrom()
  mergeWith()
  offsetExists()
  offsetGet()
  offsetSet()
  offsetUnset()

TListIterator:: (6 méthodes):
  __construct()
  rewind()
  key()
  current()
  next()
  valid()


Classe: TList  - X-Ref

TList class

TList implements an integer-indexed collection class.

You can access, append, insert, remove an item by using
{@link itemAt}, {@link add}, {@link insert}, {@link remove}, and {@link removeAt}.
To get the number of the items in the list, use {@link getCount}.
TList can also be used like a regular array as follows,
<code>
$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
</code>

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

__construct($data=null,$readOnly=false)   X-Ref
Constructor.
Initializes the list with an array or an iterable object.

param: array|Iterator the intial data. Default is null, meaning no initialization.
param: boolean whether the list is read-only

getReadOnly()   X-Ref

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

setReadOnly($value)   X-Ref

param: boolean whether this list is read-only or not

getIterator()   X-Ref
Returns an iterator for traversing the items in the list.
This method is required by the interface IteratorAggregate.

return: Iterator an iterator for traversing the items in the list.

count()   X-Ref
Returns the number of items in the list.
This method is required by Countable interface.

return: integer number of items in the list.

getCount()   X-Ref

return: integer the number of items in the list

itemAt($index)   X-Ref
Returns the item at the specified offset.
This method is exactly the same as {@link offsetGet}.

param: integer the index of the item
return: mixed the item at the index

add($item)   X-Ref
Appends an item at the end of the list.

param: mixed new item
return: integer the zero-based index at which the item is added

insertAt($index,$item)   X-Ref
Inserts an item at the specified position.
Original item at the position and the next items
will be moved one step towards the end.

param: integer the speicified position.
param: mixed new item

remove($item)   X-Ref
Removes an item from the list.
The list will first search for the item.
The first item found will be removed from the list.

param: mixed the item to be removed.
return: integer the index at which the item is being removed

removeAt($index)   X-Ref
Removes an item at the specified position.

param: integer the index of the item to be removed.
return: mixed the removed item.

clear()   X-Ref
Removes all items in the list.


contains($item)   X-Ref

param: mixed the item
return: boolean whether the list contains the item

indexOf($item)   X-Ref

param: mixed the item
return: integer the index of the item in the list (0 based), -1 if not found.

toArray()   X-Ref

return: array the list of items in array

copyFrom($data)   X-Ref
Copies iterable data into the list.
Note, existing data in the list will be cleared first.

param: mixed the data to be copied from, must be an array or object implementing Traversable

mergeWith($data)   X-Ref
Merges iterable data into the map.
New data will be appended to the end of the existing data.

param: mixed the data to be merged with, must be an array or object implementing Traversable

offsetExists($offset)   X-Ref
Returns whether there is an item at the specified offset.
This method is required by the interface ArrayAccess.

param: integer the offset to check on
return: boolean

offsetGet($offset)   X-Ref
Returns the item at the specified offset.
This method is required by the interface ArrayAccess.

param: integer the offset to retrieve item.
return: mixed the item at the offset

offsetSet($offset,$item)   X-Ref
Sets the item at the specified offset.
This method is required by the interface ArrayAccess.

param: integer the offset to set item
param: mixed the item value

offsetUnset($offset)   X-Ref
Unsets the item at the specified offset.
This method is required by the interface ArrayAccess.

param: integer the offset to unset item

Classe: TListIterator  - X-Ref

TListIterator class

TListIterator implements Iterator interface.

TListIterator is used by TList. It allows TList to return a new iterator
for traversing the items in the list.

__construct(&$data)   X-Ref
Constructor.

param: array the data to be iterated through

rewind()   X-Ref
Rewinds internal array pointer.
This method is required by the interface Iterator.


key()   X-Ref
Returns the key of the current array item.
This method is required by the interface Iterator.

return: integer the key of the current array item

current()   X-Ref
Returns the current array item.
This method is required by the interface Iterator.

return: mixed the current array item

next()   X-Ref
Moves the internal pointer to the next array item.
This method is required by the interface Iterator.


valid()   X-Ref
Returns whether there is an item at current position.
This method is required by the interface Iterator.

return: boolean



Généré le : Sun Feb 25 21:07:04 2007 par Balluche grâce à PHPXref 0.7