3 * A ShutdownPool iterator
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class ShutdownPoolIterator extends BaseIterator implements Iterator {
26 * Key for the global list index
28 private $indexKey = 0;
31 * Protected constructor
35 protected function __construct () {
36 // Call parent constructor
37 parent::__construct(__CLASS__);
41 * Creates an instance of this class
43 * @param $listInstance A list of a Listable
44 * @return $iteratorInstance An instance a Iterator class
46 public static final function createShutdownPoolIterator (Listable $listInstance) {
48 $iteratorInstance = new ShutdownPoolIterator();
51 $iteratorInstance->setListInstance($listInstance);
53 // Return the prepared instance
54 return $iteratorInstance;
58 * Getter for current value from group or generic
60 * @return $current Current value in iteration
61 * @throws IndexOutOfBoundsException If $indexKey is out of bounds
63 public function current () {
67 // Is the entry valid?
68 if (!$this->valid()) {
69 // Throw an exception here
70 throw new IndexOutOfBoundsException($this->key(), self::EXCEPTION_INDEX_OUT_OF_BOUNDS);
74 $current = $this->getListInstance()->getEntry($this->key());
81 * Getter for key from group or generic
83 * @return $indexKey Current key in iteration
85 public function key () {
86 return $this->indexKey;
90 * Advances to the next entry
94 public function next () {
99 * Rewinds to the beginning of the iteration
103 public function rewind () {
108 * Checks wether the current entry is valid (not at the end of the list)
110 * @return $isValid Wether the current entry is there
112 public function valid () {
113 // Check for total active peers and if we are not at the end
114 $isValid = ($this->key() < $this->getListInstance()->count());