From 169950e09cad0e69a7dcbcdabe7ef86086766483 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Tue, 20 Jan 2015 19:22:34 +0100 Subject: One class per file: framework/Collections/ --- framework/Collections/TDummyDataSource.php | 80 +-------- framework/Collections/TDummyDataSourceIterator.php | 87 ++++++++++ framework/Collections/TList.php | 92 +---------- framework/Collections/TListIterator.php | 99 ++++++++++++ framework/Collections/TMap.php | 89 +--------- framework/Collections/TMapIterator.php | 97 +++++++++++ framework/Collections/TPagedDataSource.php | 179 +-------------------- framework/Collections/TPagedList.php | 111 +------------ .../TPagedListFetchDataEventParameter.php | 86 ++++++++++ framework/Collections/TPagedListIterator.php | 97 +++++++++++ .../TPagedListPageChangedEventParameter.php | 42 +++++ framework/Collections/TPagedMapIterator.php | 99 ++++++++++++ framework/Collections/TQueue.php | 91 +---------- framework/Collections/TQueueIterator.php | 99 ++++++++++++ framework/Collections/TStack.php | 91 +---------- framework/Collections/TStackIterator.php | 98 +++++++++++ 16 files changed, 811 insertions(+), 726 deletions(-) create mode 100644 framework/Collections/TDummyDataSourceIterator.php create mode 100644 framework/Collections/TListIterator.php create mode 100644 framework/Collections/TMapIterator.php create mode 100644 framework/Collections/TPagedListFetchDataEventParameter.php create mode 100644 framework/Collections/TPagedListIterator.php create mode 100644 framework/Collections/TPagedListPageChangedEventParameter.php create mode 100644 framework/Collections/TPagedMapIterator.php create mode 100644 framework/Collections/TQueueIterator.php create mode 100644 framework/Collections/TStackIterator.php (limited to 'framework/Collections') diff --git a/framework/Collections/TDummyDataSource.php b/framework/Collections/TDummyDataSource.php index 7345982a..a0578ead 100644 --- a/framework/Collections/TDummyDataSource.php +++ b/framework/Collections/TDummyDataSource.php @@ -62,82 +62,4 @@ class TDummyDataSource extends TComponent implements IteratorAggregate, Countabl { return $this->getCount(); } -} - -/** - * TDummyDataSourceIterator class - * - * TDummyDataSourceIterator implements Iterator interface. - * - * TDummyDataSourceIterator is used by {@link TDummyDataSource}. - * It allows TDummyDataSource to return a new iterator - * for traversing its dummy items. - * - * @author Qiang Xue - * @package System.Collections - * @since 3.0 - */ -class TDummyDataSourceIterator implements Iterator -{ - private $_index; - private $_count; - - /** - * Constructor. - * @param integer number of (virtual) items in the data source. - */ - public function __construct($count) - { - $this->_count=$count; - $this->_index=0; - } - - /** - * Rewinds internal array pointer. - * This method is required by the interface Iterator. - */ - public function rewind() - { - $this->_index=0; - } - - /** - * 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 - */ - public function key() - { - return $this->_index; - } - - /** - * Returns the current array item. - * This method is required by the interface Iterator. - * @return mixed the current array item - */ - public function current() - { - return null; - } - - /** - * Moves the internal pointer to the next array item. - * This method is required by the interface Iterator. - */ - public function next() - { - $this->_index++; - } - - /** - * Returns whether there is an item at current position. - * This method is required by the interface Iterator. - * @return boolean - */ - public function valid() - { - return $this->_index<$this->_count; - } -} - +} \ No newline at end of file diff --git a/framework/Collections/TDummyDataSourceIterator.php b/framework/Collections/TDummyDataSourceIterator.php new file mode 100644 index 00000000..d9829a55 --- /dev/null +++ b/framework/Collections/TDummyDataSourceIterator.php @@ -0,0 +1,87 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Collections + */ + +/** + * TDummyDataSourceIterator class + * + * TDummyDataSourceIterator implements Iterator interface. + * + * TDummyDataSourceIterator is used by {@link TDummyDataSource}. + * It allows TDummyDataSource to return a new iterator + * for traversing its dummy items. + * + * @author Qiang Xue + * @package System.Collections + * @since 3.0 + */ +class TDummyDataSourceIterator implements Iterator +{ + private $_index; + private $_count; + + /** + * Constructor. + * @param integer number of (virtual) items in the data source. + */ + public function __construct($count) + { + $this->_count=$count; + $this->_index=0; + } + + /** + * Rewinds internal array pointer. + * This method is required by the interface Iterator. + */ + public function rewind() + { + $this->_index=0; + } + + /** + * 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 + */ + public function key() + { + return $this->_index; + } + + /** + * Returns the current array item. + * This method is required by the interface Iterator. + * @return mixed the current array item + */ + public function current() + { + return null; + } + + /** + * Moves the internal pointer to the next array item. + * This method is required by the interface Iterator. + */ + public function next() + { + $this->_index++; + } + + /** + * Returns whether there is an item at current position. + * This method is required by the interface Iterator. + * @return boolean + */ + public function valid() + { + return $this->_index<$this->_count; + } +} \ No newline at end of file diff --git a/framework/Collections/TList.php b/framework/Collections/TList.php index 765fa2ce..f4b83036 100644 --- a/framework/Collections/TList.php +++ b/framework/Collections/TList.php @@ -390,94 +390,4 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess,Countabl { $this->removeAt($offset); } -} - - -/** - * 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. - * - * @deprecated Issue 264 : ArrayIterator should be used instead - * @author Qiang Xue - * @package System.Collections - * @since 3.0 - */ -class TListIterator implements Iterator -{ - /** - * @var array the data to be iterated through - */ - private $_d; - /** - * @var integer index of the current item - */ - private $_i; - /** - * @var integer count of the data items - */ - private $_c; - - /** - * Constructor. - * @param array the data to be iterated through - */ - public function __construct(&$data) - { - $this->_d=&$data; - $this->_i=0; - $this->_c=count($this->_d); - } - - /** - * Rewinds internal array pointer. - * This method is required by the interface Iterator. - */ - public function rewind() - { - $this->_i=0; - } - - /** - * 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 - */ - public function key() - { - return $this->_i; - } - - /** - * Returns the current array item. - * This method is required by the interface Iterator. - * @return mixed the current array item - */ - public function current() - { - return $this->_d[$this->_i]; - } - - /** - * Moves the internal pointer to the next array item. - * This method is required by the interface Iterator. - */ - public function next() - { - $this->_i++; - } - - /** - * Returns whether there is an item at current position. - * This method is required by the interface Iterator. - * @return boolean - */ - public function valid() - { - return $this->_i<$this->_c; - } -} - +} \ No newline at end of file diff --git a/framework/Collections/TListIterator.php b/framework/Collections/TListIterator.php new file mode 100644 index 00000000..3234d1ac --- /dev/null +++ b/framework/Collections/TListIterator.php @@ -0,0 +1,99 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Collections + */ + + +/** + * 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. + * + * @deprecated Issue 264 : ArrayIterator should be used instead + * @author Qiang Xue + * @package System.Collections + * @since 3.0 + */ +class TListIterator implements Iterator +{ + /** + * @var array the data to be iterated through + */ + private $_d; + /** + * @var integer index of the current item + */ + private $_i; + /** + * @var integer count of the data items + */ + private $_c; + + /** + * Constructor. + * @param array the data to be iterated through + */ + public function __construct(&$data) + { + $this->_d=&$data; + $this->_i=0; + $this->_c=count($this->_d); + } + + /** + * Rewinds internal array pointer. + * This method is required by the interface Iterator. + */ + public function rewind() + { + $this->_i=0; + } + + /** + * 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 + */ + public function key() + { + return $this->_i; + } + + /** + * Returns the current array item. + * This method is required by the interface Iterator. + * @return mixed the current array item + */ + public function current() + { + return $this->_d[$this->_i]; + } + + /** + * Moves the internal pointer to the next array item. + * This method is required by the interface Iterator. + */ + public function next() + { + $this->_i++; + } + + /** + * Returns whether there is an item at current position. + * This method is required by the interface Iterator. + * @return boolean + */ + public function valid() + { + return $this->_i<$this->_c; + } +} \ No newline at end of file diff --git a/framework/Collections/TMap.php b/framework/Collections/TMap.php index a0ae8d5b..fe30b932 100644 --- a/framework/Collections/TMap.php +++ b/framework/Collections/TMap.php @@ -260,91 +260,4 @@ class TMap extends TComponent implements IteratorAggregate,ArrayAccess,Countable { $this->remove($offset); } -} - -/** - * TMapIterator class - * - * TMapIterator implements Iterator interface. - * - * TMapIterator is used by TMap. It allows TMap to return a new iterator - * for traversing the items in the map. - * - * @deprecated Issue 264 : ArrayIterator should be used instead - * @author Qiang Xue - * @package System.Collections - * @since 3.0 - */ -class TMapIterator implements Iterator -{ - /** - * @var array the data to be iterated through - */ - private $_d; - /** - * @var array list of keys in the map - */ - private $_keys; - /** - * @var mixed current key - */ - private $_key; - - /** - * Constructor. - * @param array the data to be iterated through - */ - public function __construct(&$data) - { - $this->_d=&$data; - $this->_keys=array_keys($data); - } - - /** - * Rewinds internal array pointer. - * This method is required by the interface Iterator. - */ - public function rewind() - { - $this->_key=reset($this->_keys); - } - - /** - * Returns the key of the current array element. - * This method is required by the interface Iterator. - * @return mixed the key of the current array element - */ - public function key() - { - return $this->_key; - } - - /** - * Returns the current array element. - * This method is required by the interface Iterator. - * @return mixed the current array element - */ - public function current() - { - return $this->_d[$this->_key]; - } - - /** - * Moves the internal pointer to the next array element. - * This method is required by the interface Iterator. - */ - public function next() - { - $this->_key=next($this->_keys); - } - - /** - * Returns whether there is an element at current position. - * This method is required by the interface Iterator. - * @return boolean - */ - public function valid() - { - return $this->_key!==false; - } -} +} \ No newline at end of file diff --git a/framework/Collections/TMapIterator.php b/framework/Collections/TMapIterator.php new file mode 100644 index 00000000..238441a3 --- /dev/null +++ b/framework/Collections/TMapIterator.php @@ -0,0 +1,97 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Collections + */ + +/** + * TMapIterator class + * + * TMapIterator implements Iterator interface. + * + * TMapIterator is used by TMap. It allows TMap to return a new iterator + * for traversing the items in the map. + * + * @deprecated Issue 264 : ArrayIterator should be used instead + * @author Qiang Xue + * @package System.Collections + * @since 3.0 + */ +class TMapIterator implements Iterator +{ + /** + * @var array the data to be iterated through + */ + private $_d; + /** + * @var array list of keys in the map + */ + private $_keys; + /** + * @var mixed current key + */ + private $_key; + + /** + * Constructor. + * @param array the data to be iterated through + */ + public function __construct(&$data) + { + $this->_d=&$data; + $this->_keys=array_keys($data); + } + + /** + * Rewinds internal array pointer. + * This method is required by the interface Iterator. + */ + public function rewind() + { + $this->_key=reset($this->_keys); + } + + /** + * Returns the key of the current array element. + * This method is required by the interface Iterator. + * @return mixed the key of the current array element + */ + public function key() + { + return $this->_key; + } + + /** + * Returns the current array element. + * This method is required by the interface Iterator. + * @return mixed the current array element + */ + public function current() + { + return $this->_d[$this->_key]; + } + + /** + * Moves the internal pointer to the next array element. + * This method is required by the interface Iterator. + */ + public function next() + { + $this->_key=next($this->_keys); + } + + /** + * Returns whether there is an element at current position. + * This method is required by the interface Iterator. + * @return boolean + */ + public function valid() + { + return $this->_key!==false; + } +} \ No newline at end of file diff --git a/framework/Collections/TPagedDataSource.php b/framework/Collections/TPagedDataSource.php index 745fc052..b888348e 100644 --- a/framework/Collections/TPagedDataSource.php +++ b/framework/Collections/TPagedDataSource.php @@ -262,181 +262,4 @@ class TPagedDataSource extends TComponent implements IteratorAggregate,Countable else return null; } -} - - - -/** - * TPagedListIterator class - * - * TPagedListIterator implements Iterator interface. - * - * TPagedListIterator is used by {@link TPagedDataSource}. It allows TPagedDataSource - * to return a new iterator for traversing the items in a {@link TList} object. - * - * @author Qiang Xue - * @package System.Collections - * @since 3.0 - */ -class TPagedListIterator implements Iterator -{ - private $_list; - private $_startIndex; - private $_count; - private $_index; - - /** - * Constructor. - * @param TList the data to be iterated through - * @param integer start index - * @param integer number of items to be iterated through - */ - public function __construct(TList $list,$startIndex,$count) - { - $this->_list=$list; - $this->_index=0; - $this->_startIndex=$startIndex; - if($startIndex+$count>$list->getCount()) - $this->_count=$list->getCount()-$startIndex; - else - $this->_count=$count; - } - - /** - * Rewinds internal array pointer. - * This method is required by the interface Iterator. - */ - public function rewind() - { - $this->_index=0; - } - - /** - * 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 - */ - public function key() - { - return $this->_index; - } - - /** - * Returns the current array item. - * This method is required by the interface Iterator. - * @return mixed the current array item - */ - public function current() - { - return $this->_list->itemAt($this->_startIndex+$this->_index); - } - - /** - * Moves the internal pointer to the next array item. - * This method is required by the interface Iterator. - */ - public function next() - { - $this->_index++; - } - - /** - * Returns whether there is an item at current position. - * This method is required by the interface Iterator. - * @return boolean - */ - public function valid() - { - return $this->_index<$this->_count; - } -} - -/** - * TPagedMapIterator class - * - * TPagedMapIterator implements Iterator interface. - * - * TPagedMapIterator is used by {@link TPagedDataSource}. It allows TPagedDataSource - * to return a new iterator for traversing the items in a {@link TMap} object. - * - * @author Qiang Xue - * @package System.Collections - * @since 3.0 - */ -class TPagedMapIterator implements Iterator -{ - private $_map; - private $_startIndex; - private $_count; - private $_index; - private $_iterator; - - /** - * Constructor. - * @param array the data to be iterated through - */ - public function __construct(TMap $map,$startIndex,$count) - { - $this->_map=$map; - $this->_index=0; - $this->_startIndex=$startIndex; - if($startIndex+$count>$map->getCount()) - $this->_count=$map->getCount()-$startIndex; - else - $this->_count=$count; - $this->_iterator=$map->getIterator(); - } - - /** - * Rewinds internal array pointer. - * This method is required by the interface Iterator. - */ - public function rewind() - { - $this->_iterator->rewind(); - for($i=0;$i<$this->_startIndex;++$i) - $this->_iterator->next(); - $this->_index=0; - } - - /** - * 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 - */ - public function key() - { - return $this->_iterator->key(); - } - - /** - * Returns the current array item. - * This method is required by the interface Iterator. - * @return mixed the current array item - */ - public function current() - { - return $this->_iterator->current(); - } - - /** - * Moves the internal pointer to the next array item. - * This method is required by the interface Iterator. - */ - public function next() - { - $this->_index++; - $this->_iterator->next(); - } - - /** - * Returns whether there is an item at current position. - * This method is required by the interface Iterator. - * @return boolean - */ - public function valid() - { - return $this->_index<$this->_count; - } -} - +} \ No newline at end of file diff --git a/framework/Collections/TPagedList.php b/framework/Collections/TPagedList.php index 57e567e0..2b349413 100644 --- a/framework/Collections/TPagedList.php +++ b/framework/Collections/TPagedList.php @@ -361,113 +361,4 @@ class TPagedList extends TList $array[$i]=$this->itemAt($i); return $array; } -} - -/** - * TPagedListPageChangedEventParameter class. - * TPagedListPageChangedEventParameter is used as the parameter for - * {@link TPagedList::onPageChanged OnPageChanged} event. - * To obtain the page index before it was changed, use {@link getOldPageIndex OldPageIndex}. - * - * @author Qiang Xue - * @package System.Collections - * @since 3.0 - */ -class TPagedListPageChangedEventParameter extends TEventParameter -{ - private $_oldPage; - - /** - * Constructor. - * @param integer old page index - */ - public function __construct($oldPage) - { - $this->_oldPage=$oldPage; - } - - /** - * @return integer the index of the page before the list changed to the new page - */ - public function getOldPageIndex() - { - return $this->_oldPage; - } -} - -/** - * TPagedListFetchDataEventParameter class. - * - * TPagedListFetchDataEventParameter is used as the parameter for - * {@link TPagedList::onFetchData OnFetchData} event. - * To obtain the new page index, use {@link getNewPageIndex NewPageIndex}. - * The {@link getOffset Offset} property refers to the index - * of the first item in the new page, while {@link getLimit Limit} - * specifies how many items are requested for the page. - * Newly fetched data should be saved in {@link setData Data} property. - * - * @author Qiang Xue - * @package System.Collections - * @since 3.0 - */ -class TPagedListFetchDataEventParameter extends TEventParameter -{ - private $_pageIndex; - private $_offset; - private $_limit; - private $_data=null; - - /** - * Constructor. - * @param integer new page index - * @param integer offset of the first item in the new page - * @param integer number of items in the new page desired - */ - public function __construct($pageIndex,$offset,$limit) - { - $this->_pageIndex=$pageIndex; - $this->_offset=$offset; - $this->_limit=$limit; - } - - /** - * @return integer the zero-based index of the new page - */ - public function getNewPageIndex() - { - return $this->_pageIndex; - } - - /** - * @return integer offset of the first item in the new page - */ - public function getOffset() - { - return $this->_offset; - } - - /** - * @return integer number of items in the new page - */ - public function getLimit() - { - return $this->_limit; - } - - /** - * @return mixed new page data - */ - public function getData() - { - return $this->_data; - } - - /** - * @param mixed new page data - */ - public function setData($value) - { - $this->_data=$value; - } -} - +} \ No newline at end of file diff --git a/framework/Collections/TPagedListFetchDataEventParameter.php b/framework/Collections/TPagedListFetchDataEventParameter.php new file mode 100644 index 00000000..ea91f775 --- /dev/null +++ b/framework/Collections/TPagedListFetchDataEventParameter.php @@ -0,0 +1,86 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Collections + */ + +/** + * TPagedListFetchDataEventParameter class. + * + * TPagedListFetchDataEventParameter is used as the parameter for + * {@link TPagedList::onFetchData OnFetchData} event. + * To obtain the new page index, use {@link getNewPageIndex NewPageIndex}. + * The {@link getOffset Offset} property refers to the index + * of the first item in the new page, while {@link getLimit Limit} + * specifies how many items are requested for the page. + * Newly fetched data should be saved in {@link setData Data} property. + * + * @author Qiang Xue + * @package System.Collections + * @since 3.0 + */ +class TPagedListFetchDataEventParameter extends TEventParameter +{ + private $_pageIndex; + private $_offset; + private $_limit; + private $_data=null; + + /** + * Constructor. + * @param integer new page index + * @param integer offset of the first item in the new page + * @param integer number of items in the new page desired + */ + public function __construct($pageIndex,$offset,$limit) + { + $this->_pageIndex=$pageIndex; + $this->_offset=$offset; + $this->_limit=$limit; + } + + /** + * @return integer the zero-based index of the new page + */ + public function getNewPageIndex() + { + return $this->_pageIndex; + } + + /** + * @return integer offset of the first item in the new page + */ + public function getOffset() + { + return $this->_offset; + } + + /** + * @return integer number of items in the new page + */ + public function getLimit() + { + return $this->_limit; + } + + /** + * @return mixed new page data + */ + public function getData() + { + return $this->_data; + } + + /** + * @param mixed new page data + */ + public function setData($value) + { + $this->_data=$value; + } +} \ No newline at end of file diff --git a/framework/Collections/TPagedListIterator.php b/framework/Collections/TPagedListIterator.php new file mode 100644 index 00000000..8a2166cb --- /dev/null +++ b/framework/Collections/TPagedListIterator.php @@ -0,0 +1,97 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Collections + */ + + + +/** + * TPagedListIterator class + * + * TPagedListIterator implements Iterator interface. + * + * TPagedListIterator is used by {@link TPagedDataSource}. It allows TPagedDataSource + * to return a new iterator for traversing the items in a {@link TList} object. + * + * @author Qiang Xue + * @package System.Collections + * @since 3.0 + */ +class TPagedListIterator implements Iterator +{ + private $_list; + private $_startIndex; + private $_count; + private $_index; + + /** + * Constructor. + * @param TList the data to be iterated through + * @param integer start index + * @param integer number of items to be iterated through + */ + public function __construct(TList $list,$startIndex,$count) + { + $this->_list=$list; + $this->_index=0; + $this->_startIndex=$startIndex; + if($startIndex+$count>$list->getCount()) + $this->_count=$list->getCount()-$startIndex; + else + $this->_count=$count; + } + + /** + * Rewinds internal array pointer. + * This method is required by the interface Iterator. + */ + public function rewind() + { + $this->_index=0; + } + + /** + * 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 + */ + public function key() + { + return $this->_index; + } + + /** + * Returns the current array item. + * This method is required by the interface Iterator. + * @return mixed the current array item + */ + public function current() + { + return $this->_list->itemAt($this->_startIndex+$this->_index); + } + + /** + * Moves the internal pointer to the next array item. + * This method is required by the interface Iterator. + */ + public function next() + { + $this->_index++; + } + + /** + * Returns whether there is an item at current position. + * This method is required by the interface Iterator. + * @return boolean + */ + public function valid() + { + return $this->_index<$this->_count; + } +} \ No newline at end of file diff --git a/framework/Collections/TPagedListPageChangedEventParameter.php b/framework/Collections/TPagedListPageChangedEventParameter.php new file mode 100644 index 00000000..9b9f500e --- /dev/null +++ b/framework/Collections/TPagedListPageChangedEventParameter.php @@ -0,0 +1,42 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Collections + */ + +/** + * TPagedListPageChangedEventParameter class. + * TPagedListPageChangedEventParameter is used as the parameter for + * {@link TPagedList::onPageChanged OnPageChanged} event. + * To obtain the page index before it was changed, use {@link getOldPageIndex OldPageIndex}. + * + * @author Qiang Xue + * @package System.Collections + * @since 3.0 + */ +class TPagedListPageChangedEventParameter extends TEventParameter +{ + private $_oldPage; + + /** + * Constructor. + * @param integer old page index + */ + public function __construct($oldPage) + { + $this->_oldPage=$oldPage; + } + + /** + * @return integer the index of the page before the list changed to the new page + */ + public function getOldPageIndex() + { + return $this->_oldPage; + } +} \ No newline at end of file diff --git a/framework/Collections/TPagedMapIterator.php b/framework/Collections/TPagedMapIterator.php new file mode 100644 index 00000000..c5a078c1 --- /dev/null +++ b/framework/Collections/TPagedMapIterator.php @@ -0,0 +1,99 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Collections + */ + +/** + * TPagedMapIterator class + * + * TPagedMapIterator implements Iterator interface. + * + * TPagedMapIterator is used by {@link TPagedDataSource}. It allows TPagedDataSource + * to return a new iterator for traversing the items in a {@link TMap} object. + * + * @author Qiang Xue + * @package System.Collections + * @since 3.0 + */ +class TPagedMapIterator implements Iterator +{ + private $_map; + private $_startIndex; + private $_count; + private $_index; + private $_iterator; + + /** + * Constructor. + * @param array the data to be iterated through + */ + public function __construct(TMap $map,$startIndex,$count) + { + $this->_map=$map; + $this->_index=0; + $this->_startIndex=$startIndex; + if($startIndex+$count>$map->getCount()) + $this->_count=$map->getCount()-$startIndex; + else + $this->_count=$count; + $this->_iterator=$map->getIterator(); + } + + /** + * Rewinds internal array pointer. + * This method is required by the interface Iterator. + */ + public function rewind() + { + $this->_iterator->rewind(); + for($i=0;$i<$this->_startIndex;++$i) + $this->_iterator->next(); + $this->_index=0; + } + + /** + * 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 + */ + public function key() + { + return $this->_iterator->key(); + } + + /** + * Returns the current array item. + * This method is required by the interface Iterator. + * @return mixed the current array item + */ + public function current() + { + return $this->_iterator->current(); + } + + /** + * Moves the internal pointer to the next array item. + * This method is required by the interface Iterator. + */ + public function next() + { + $this->_index++; + $this->_iterator->next(); + } + + /** + * Returns whether there is an item at current position. + * This method is required by the interface Iterator. + * @return boolean + */ + public function valid() + { + return $this->_index<$this->_count; + } +} \ No newline at end of file diff --git a/framework/Collections/TQueue.php b/framework/Collections/TQueue.php index ffa81b95..824a7e5f 100644 --- a/framework/Collections/TQueue.php +++ b/framework/Collections/TQueue.php @@ -171,93 +171,4 @@ class TQueue extends TComponent implements IteratorAggregate,Countable { return $this->getCount(); } -} - -/** - * TQueueIterator class - * - * TQueueIterator implements Iterator interface. - * - * TQueueIterator is used by TQueue. It allows TQueue to return a new iterator - * for traversing the items in the queue. - * - * @author Qiang Xue - * @version $Id$ - * @package System.Collections - * @since 3.1 - */ -class TQueueIterator implements Iterator -{ - /** - * @var array the data to be iterated through - */ - private $_d; - /** - * @var integer index of the current item - */ - private $_i; - /** - * @var integer count of the data items - */ - private $_c; - - /** - * Constructor. - * @param array the data to be iterated through - */ - public function __construct(&$data) - { - $this->_d=&$data; - $this->_i=0; - $this->_c=count($this->_d); - } - - /** - * Rewinds internal array pointer. - * This method is required by the interface Iterator. - */ - public function rewind() - { - $this->_i=0; - } - - /** - * 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 - */ - public function key() - { - return $this->_i; - } - - /** - * Returns the current array item. - * This method is required by the interface Iterator. - * @return mixed the current array item - */ - public function current() - { - return $this->_d[$this->_i]; - } - - /** - * Moves the internal pointer to the next array item. - * This method is required by the interface Iterator. - */ - public function next() - { - $this->_i++; - } - - /** - * Returns whether there is an item at current position. - * This method is required by the interface Iterator. - * @return boolean - */ - public function valid() - { - return $this->_i<$this->_c; - } -} - +} \ No newline at end of file diff --git a/framework/Collections/TQueueIterator.php b/framework/Collections/TQueueIterator.php new file mode 100644 index 00000000..29a973d1 --- /dev/null +++ b/framework/Collections/TQueueIterator.php @@ -0,0 +1,99 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package System.Collections + */ + +/** + * TQueueIterator class + * + * TQueueIterator implements Iterator interface. + * + * TQueueIterator is used by TQueue. It allows TQueue to return a new iterator + * for traversing the items in the queue. + * + * @author Qiang Xue + * @version $Id$ + * @package System.Collections + * @since 3.1 + */ +class TQueueIterator implements Iterator +{ + /** + * @var array the data to be iterated through + */ + private $_d; + /** + * @var integer index of the current item + */ + private $_i; + /** + * @var integer count of the data items + */ + private $_c; + + /** + * Constructor. + * @param array the data to be iterated through + */ + public function __construct(&$data) + { + $this->_d=&$data; + $this->_i=0; + $this->_c=count($this->_d); + } + + /** + * Rewinds internal array pointer. + * This method is required by the interface Iterator. + */ + public function rewind() + { + $this->_i=0; + } + + /** + * 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 + */ + public function key() + { + return $this->_i; + } + + /** + * Returns the current array item. + * This method is required by the interface Iterator. + * @return mixed the current array item + */ + public function current() + { + return $this->_d[$this->_i]; + } + + /** + * Moves the internal pointer to the next array item. + * This method is required by the interface Iterator. + */ + public function next() + { + $this->_i++; + } + + /** + * Returns whether there is an item at current position. + * This method is required by the interface Iterator. + * @return boolean + */ + public function valid() + { + return $this->_i<$this->_c; + } +} \ No newline at end of file diff --git a/framework/Collections/TStack.php b/framework/Collections/TStack.php index 91996aaa..cb98e604 100644 --- a/framework/Collections/TStack.php +++ b/framework/Collections/TStack.php @@ -168,93 +168,4 @@ class TStack extends TComponent implements IteratorAggregate,Countable { return $this->getCount(); } -} - -/** - * TStackIterator class - * - * TStackIterator implements Iterator interface. - * - * TStackIterator is used by TStack. It allows TStack to return a new iterator - * for traversing the items in the list. - * - * @deprecated Issue 264 : ArrayIterator should be used instead - * @author Qiang Xue - * @package System.Collections - * @since 3.0 - */ -class TStackIterator implements Iterator -{ - /** - * @var array the data to be iterated through - */ - private $_d; - /** - * @var integer index of the current item - */ - private $_i; - /** - * @var integer count of the data items - */ - private $_c; - - /** - * Constructor. - * @param array the data to be iterated through - */ - public function __construct(&$data) - { - $this->_d=&$data; - $this->_i=0; - $this->_c=count($this->_d); - } - - /** - * Rewinds internal array pointer. - * This method is required by the interface Iterator. - */ - public function rewind() - { - $this->_i=0; - } - - /** - * 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 - */ - public function key() - { - return $this->_i; - } - - /** - * Returns the current array item. - * This method is required by the interface Iterator. - * @return mixed the current array item - */ - public function current() - { - return $this->_d[$this->_i]; - } - - /** - * Moves the internal pointer to the next array item. - * This method is required by the interface Iterator. - */ - public function next() - { - $this->_i++; - } - - /** - * Returns whether there is an item at current position. - * This method is required by the interface Iterator. - * @return boolean - */ - public function valid() - { - return $this->_i<$this->_c; - } -} - +} \ No newline at end of file diff --git a/framework/Collections/TStackIterator.php b/framework/Collections/TStackIterator.php new file mode 100644 index 00000000..48b7c75f --- /dev/null +++ b/framework/Collections/TStackIterator.php @@ -0,0 +1,98 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Collections + */ + +/** + * TStackIterator class + * + * TStackIterator implements Iterator interface. + * + * TStackIterator is used by TStack. It allows TStack to return a new iterator + * for traversing the items in the list. + * + * @deprecated Issue 264 : ArrayIterator should be used instead + * @author Qiang Xue + * @package System.Collections + * @since 3.0 + */ +class TStackIterator implements Iterator +{ + /** + * @var array the data to be iterated through + */ + private $_d; + /** + * @var integer index of the current item + */ + private $_i; + /** + * @var integer count of the data items + */ + private $_c; + + /** + * Constructor. + * @param array the data to be iterated through + */ + public function __construct(&$data) + { + $this->_d=&$data; + $this->_i=0; + $this->_c=count($this->_d); + } + + /** + * Rewinds internal array pointer. + * This method is required by the interface Iterator. + */ + public function rewind() + { + $this->_i=0; + } + + /** + * 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 + */ + public function key() + { + return $this->_i; + } + + /** + * Returns the current array item. + * This method is required by the interface Iterator. + * @return mixed the current array item + */ + public function current() + { + return $this->_d[$this->_i]; + } + + /** + * Moves the internal pointer to the next array item. + * This method is required by the interface Iterator. + */ + public function next() + { + $this->_i++; + } + + /** + * Returns whether there is an item at current position. + * This method is required by the interface Iterator. + * @return boolean + */ + public function valid() + { + return $this->_i<$this->_c; + } +} \ No newline at end of file -- cgit v1.2.3