From: Raphaël Barrois Date: Thu, 18 Mar 2010 20:45:30 +0000 (+0100) Subject: Add PlEmptyIterator X-Git-Tag: core/1.1.0~30 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=c291ca5486bce705cd3dfd81065cbd2d92b96da5;p=platal.git Add PlEmptyIterator Signed-off-by: Raphaël Barrois --- diff --git a/classes/pliteratorutils.php b/classes/pliteratorutils.php index 930cc56..a77244b 100644 --- a/classes/pliteratorutils.php +++ b/classes/pliteratorutils.php @@ -21,6 +21,13 @@ class PlIteratorUtils { + /** Builds a new empty iterator + */ + public static function emptyIterator() + { + return new PlEmptyIterator(); + } + /** Build an iterator over an array. * @param array The array. * @param depth The depth of iteration. @@ -130,6 +137,31 @@ class PlIteratorUtils } } +/** Empty iterator + */ +class PlEmptyIterator implements PlIterator +{ + public function first() + { + return false; + } + + public function last() + { + return false; + } + + public function next() + { + return null; + } + + public function total() + { + return 0; + } +} + /** Iterates over an array. */ class PlArrayIterator implements PlIterator