Source for file MultiIteratorIterator.class.php

Documentation is available at MultiIteratorIterator.class.php

  1. <?php
  2.  
  3. require_once(dirname(__FILE__)."/HarmoniIterator.class.php");
  4.  
  5. /**
  6. * A class for passing an arbitrary input array as an iterator.
  7. *
  8. * @package harmoni.osid_v2.shared
  9. *
  10. * @copyright Copyright &copy; 2005, Middlebury College
  11. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  12. *
  13. * @version $Id: MultiIteratorIterator.class.php,v 1.4 2007/09/04 20:25:48 adamfranco Exp $
  14. */
  15. class MultiIteratorIterator
  16. extends HarmoniIterator
  17. {
  18. /**
  19. * Constructor
  20. *
  21. * @return object
  22. * @access public
  23. * @since 12/6/06
  24. */
  25. function MultiIteratorIterator () {
  26. $this->HarmoniIterator($null = null);
  27. }
  28. /**
  29. * Add a new iterator to this iterator
  30. *
  31. * @param object Iterator $iterator
  32. * @return void
  33. * @access public
  34. * @since 5/9/06
  35. */
  36. function addIterator ( $iterator ) {
  37. $this->_elements[] =$iterator;
  38. unset($this->_count);
  39. }
  40.  
  41. // public boolean hasNext();
  42. function hasNext() {
  43. for ($i = max(0, $this->_i); $i < count($this->_elements); $i++) {
  44. if ($this->_elements[$i]->hasNext())
  45. return true;
  46. }
  47. return false;
  48. }
  49.  
  50. // public Type & next();
  51. function next() {
  52. for ($i = max(0, $this->_i); $i < count($this->_elements); $i++) {
  53. if ($this->_elements[$i]->hasNext())
  54. return $this->_elements[$i]->next();
  55. else
  56. $this->_i++;
  57. }
  58. throwError(new Error(SharedException::NO_MORE_ITERATOR_ELEMENTS(), get_class($this), 1));
  59. }
  60.  
  61. /**
  62. * Gives the number of items in the iterator
  63. *
  64. * @return int
  65. * @public
  66. */
  67. function count () {
  68. if (!isset($this->_count)) {
  69. $this->_count = 0;
  70. foreach ($this->_elements as $iterator)
  71. $this->_count += $iterator->count();
  72. }
  73. return $this->_count;
  74. }
  75. /**
  76. * Skips the next item in the iterator
  77. *
  78. * @return void
  79. * @public
  80. */
  81. function skipNext() {
  82. for ($i = max(0, $this->_i); $i < count($this->_elements); $i++) {
  83. if ($this->_elements[$i]->hasNext()) {
  84. $this->_elements[$i]->skipNext();
  85. return;
  86. } else
  87. $this->_i++;
  88. }
  89. throwError(new Error(SharedException::NO_MORE_ITERATOR_ELEMENTS(), get_class($this), 1));
  90. }
  91. }
  92.  
  93. ?>

Documentation generated on Wed, 19 Sep 2007 10:25:09 -0400 by phpDocumentor 1.3.0RC3