]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/iterator/default/class_DefaultIterator.php
Continued:
[core.git] / framework / main / classes / iterator / default / class_DefaultIterator.php
index 5b482861a81073e35e199a901614fabe463995d1..0ee6110fa7500ed5a9b16ac199e3a0cce59bc776 100644 (file)
@@ -15,7 +15,7 @@ use \Iterator;
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -43,7 +43,7 @@ class DefaultIterator extends BaseIterator implements Iterator, Registerable {
         *
         * @return      void
         */
-       protected function __construct () {
+       private function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
        }
@@ -54,14 +54,16 @@ class DefaultIterator extends BaseIterator implements Iterator, Registerable {
         * @param       $listInstance           A list of a Listable
         * @return      $iteratorInstance       An instance a Iterator class
         */
-       public static final function createDefaultIterator (Listable $listInstance) {
+       public static final function createDefaultIterator (Listable $listInstance): DefaultIterator {
                // Get new instance
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DEFAULT-ITERATOR: listInstance=%s - CALLED!', $listInstance));
                $iteratorInstance = new DefaultIterator();
 
                // Set the list
                $iteratorInstance->setListInstance($listInstance);
 
                // Return the prepared instance
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DEFAULT-ITERATOR: iteratorInstance=%s - EXIT!', $iteratorInstance));
                return $iteratorInstance;
        }
 
@@ -71,20 +73,22 @@ class DefaultIterator extends BaseIterator implements Iterator, Registerable {
         * @return      $current        Current value in iteration
         * @throws      IndexOutOfBoundsException       If $indexKey is out of bounds
         */
-       public function current () {
+       public function current (): mixed {
                // Default is null
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('DEFAULT-ITERATOR: CALLED!');
                $current = NULL;
 
                // 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());
+               $current = $this->getListInstance()->getEntryByIndex($this->key());
 
                // Return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DEFAULT-ITERATOR: current[]=%s - EXIT!', gettype($current)));
                return $current;
        }
 
@@ -93,7 +97,8 @@ class DefaultIterator extends BaseIterator implements Iterator, Registerable {
         *
         * @return      $indexKey       Current key in iteration
         */
-       public function key () {
+       public function key (): int {
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DEFAULT-ITERATOR: this->indexKey=%d - EXIT!', $this->indexKey));
                return $this->indexKey;
        }
 
@@ -102,7 +107,8 @@ class DefaultIterator extends BaseIterator implements Iterator, Registerable {
         *
         * @return      void
         */
-       public function next () {
+       public function next (): void {
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FILE-IO-HANDLER: CALLED!');
                $this->indexKey++;
        }
 
@@ -111,7 +117,8 @@ class DefaultIterator extends BaseIterator implements Iterator, Registerable {
         *
         * @return      void
         */
-       public function rewind () {
+       public function rewind (): void {
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FILE-IO-HANDLER: CALLED!');
                $this->indexKey = 0;
        }
 
@@ -120,11 +127,13 @@ class DefaultIterator extends BaseIterator implements Iterator, Registerable {
         *
         * @return      $isValid        Whether the current entry is there
         */
-       public function valid () {
+       public function valid (): bool {
                // Check for total active peers and if we are not at the end
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FILE-IO-HANDLER: CALLED!');
                $isValid = ($this->key() < $this->getListInstance()->count());
 
                // Return result
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-IO-HANDLER: isValid=%d - EXIT!', intval($isValid)));
                return $isValid;
        }