]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/iterator/pool/class_ShutdownPoolIterator.php
Iterator continued (not fully implemented), iteration on all clients and hubs should...
[hub.git] / application / hub / main / iterator / pool / class_ShutdownPoolIterator.php
index d6a16f562b8a7b1c013cab3d91c14762a17fffe3..1fbc0f19027187cbcbc3991e601e911527384cb5 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 class ShutdownPoolIterator extends BaseIterator implements Iterator {
+       /**
+        * Key for the global list index
+        */
+       private $indexKey = 0;
+
        /**
         * Protected constructor
         *
@@ -53,12 +58,20 @@ class ShutdownPoolIterator extends BaseIterator implements Iterator {
         * Getter for current value from group or generic
         *
         * @return      $current        Current value in iteration
+        * @throws      IndexOutOfBoundsException       If $indexKey is out of bounds
         */
        public function current () {
                // Default is null
                $current = null;
 
-               $this->partialStub('Please implement this method.');
+               // Is the entry valid?
+               if (!$this->valid()) {
+                       // Throw an exception here
+                       throw new IndexOutOfBoundsException($this->key(), self::EXCEPTION_INDEX_OUT_OF_BOUNDS);
+               } // END - if
+
+               // Now get the entry
+               $current = $this->getListInstance()->getEntry($this->key());
 
                // Return it
                return $current;
@@ -67,16 +80,10 @@ class ShutdownPoolIterator extends BaseIterator implements Iterator {
        /**
         * Getter for key from group or generic
         *
-        * @return      $key    Current key in iteration
+        * @return      $indexKey       Current key in iteration
         */
        public function key () {
-               // Default is null
-               $key = null;
-
-               $this->partialStub('Please implement this method.');
-
-               // Return it
-               return $key;
+               return $this->indexKey;
        }
 
        /**
@@ -85,7 +92,7 @@ class ShutdownPoolIterator extends BaseIterator implements Iterator {
         * @return      void
         */
        public function next () {
-               $this->partialStub('Please implement this method.');
+               $this->indexKey++;
        }
 
        /**
@@ -94,16 +101,20 @@ class ShutdownPoolIterator extends BaseIterator implements Iterator {
         * @return      void
         */
        public function rewind () {
-               $this->partialStub('Please implement this method.');
+               $this->indexKey = 0;
        }
 
        /**
         * Checks wether the current entry is valid (not at the end of the list)
         *
-        * @return      void
+        * @return      $isValid        Wether the current entry is there
         */
        public function valid () {
-               $this->partialStub('Please implement this method.');
+               // Check for total active clients and if we are not at the end
+               $isValid = ($this->key() < $this->getListInstance()->count());
+
+               // Return result
+               return $isValid;
        }
 }