From 550ba06593b467b643862d41a00ca2dd12ee704b Mon Sep 17 00:00:00 2001 From: xue <> Date: Wed, 2 Aug 2006 02:24:29 +0000 Subject: merge from 3.0 branch till 1320. --- framework/Collections/TDummyDataSource.php | 12 +++++++++++- framework/Collections/TList.php | 15 ++++++++++++--- framework/Collections/TMap.php | 15 ++++++++++++--- framework/Collections/TPagedDataSource.php | 12 +++++++++++- framework/Collections/TStack.php | 12 +++++++++++- 5 files changed, 57 insertions(+), 9 deletions(-) (limited to 'framework/Collections') diff --git a/framework/Collections/TDummyDataSource.php b/framework/Collections/TDummyDataSource.php index 46e625ab..d7fee4a9 100644 --- a/framework/Collections/TDummyDataSource.php +++ b/framework/Collections/TDummyDataSource.php @@ -26,7 +26,7 @@ * @package System.Collections * @since 3.0 */ -class TDummyDataSource extends TComponent implements IteratorAggregate +class TDummyDataSource extends TComponent implements IteratorAggregate, Countable { private $_count; @@ -54,6 +54,16 @@ class TDummyDataSource extends TComponent implements IteratorAggregate { return new TDummyDataSourceIterator($this->_count); } + + /** + * Returns the number of (virtual) items in the data source. + * This method is required by Countable interface. + * @return integer number of (virtual) items in the data source. + */ + public function count() + { + return $this->getCount(); + } } /** diff --git a/framework/Collections/TList.php b/framework/Collections/TList.php index 015781cb..1104ec47 100644 --- a/framework/Collections/TList.php +++ b/framework/Collections/TList.php @@ -25,9 +25,8 @@ * 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 * - * Note, count($list) will always return 1. You should use {@link getCount()} - * to determine the number of items in the list. * * To extend TList by doing additional operations with each addition or removal * operation, override {@link insertAt()}, and {@link removeAt()}. @@ -37,7 +36,7 @@ * @package System.Collections * @since 3.0 */ -class TList extends TComponent implements IteratorAggregate,ArrayAccess +class TList extends TComponent implements IteratorAggregate,ArrayAccess,Countable { /** * internal data storage @@ -94,6 +93,16 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess return new TListIterator($this->_d); } + /** + * Returns the number of items in the list. + * This method is required by Countable interface. + * @return integer number of items in the list. + */ + public function count() + { + return $this->getCount(); + } + /** * @return integer the number of items in the list */ diff --git a/framework/Collections/TMap.php b/framework/Collections/TMap.php index e3a26e5f..ef393866 100644 --- a/framework/Collections/TMap.php +++ b/framework/Collections/TMap.php @@ -24,16 +24,15 @@ * unset($map[$key]); // remove the value with the specified key * if(isset($map[$key])) // if the map contains the key * foreach($map as $key=>$value) // traverse the items in the map + * $n=count($map); // returns the number of items in the map * - * Note, count($map) will always return 1. You should use {@link getCount()} - * to determine the number of items in the map. * * @author Qiang Xue * @version $Revision: $ $Date: $ * @package System.Collections * @since 3.0 */ -class TMap extends TComponent implements IteratorAggregate,ArrayAccess +class TMap extends TComponent implements IteratorAggregate,ArrayAccess,Countable { /** * @var array internal data storage @@ -84,6 +83,16 @@ class TMap extends TComponent implements IteratorAggregate,ArrayAccess return new TMapIterator($this->_d); } + /** + * Returns the number of items in the map. + * This method is required by Countable interface. + * @return integer number of items in the map. + */ + public function count() + { + return $this->getCount(); + } + /** * @return integer the number of items in the map */ diff --git a/framework/Collections/TPagedDataSource.php b/framework/Collections/TPagedDataSource.php index 6192b1f7..a2bce9e3 100644 --- a/framework/Collections/TPagedDataSource.php +++ b/framework/Collections/TPagedDataSource.php @@ -28,7 +28,7 @@ * @package System.Collections * @since 3.0 */ -class TPagedDataSource extends TComponent implements IteratorAggregate +class TPagedDataSource extends TComponent implements IteratorAggregate,Countable { /** * @var mixed original data source @@ -182,6 +182,16 @@ class TPagedDataSource extends TComponent implements IteratorAggregate return $this->_pageSize; } + /** + * Returns the number of items in the current page. + * This method is required by Countable interface. + * @return integer number of items in the current page. + */ + public function count() + { + return $this->getCount(); + } + /** * @return integer number of pages */ diff --git a/framework/Collections/TStack.php b/framework/Collections/TStack.php index 79d17902..f1118d90 100644 --- a/framework/Collections/TStack.php +++ b/framework/Collections/TStack.php @@ -31,7 +31,7 @@ * @package System.Collections * @since 3.0 */ -class TStack extends TComponent implements IteratorAggregate +class TStack extends TComponent implements IteratorAggregate,Countable { /** * internal data storage @@ -160,6 +160,16 @@ class TStack extends TComponent implements IteratorAggregate { return $this->_c; } + + /** + * Returns the number of items in the stack. + * This method is required by Countable interface. + * @return integer number of items in the stack. + */ + public function count() + { + return $this->getCount(); + } } /** -- cgit v1.2.3