]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/lists/class_BaseList.php
Continued:
[core.git] / framework / main / classes / lists / class_BaseList.php
index 08d60de88167a0d48da4e269b983e8dc52424830..b31350285775b6a942a698543f741fe1183f5a14 100644 (file)
@@ -6,6 +6,7 @@ namespace Org\Mxchange\CoreFramework\Lists;
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait;
 use Org\Mxchange\CoreFramework\Visitor\Visitable;
 
 // Import SPL stuff
@@ -35,6 +36,9 @@ use \Countable;
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countable {
+       // Load traits
+       use IteratorTrait;
+
        // Exception constants
        const EXCEPTION_GROUP_ALREADY_ADDED = 0xf20;
        const EXCEPTION_GROUP_NOT_FOUND     = 0xf21;
@@ -82,7 +86,7 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
 
                        // Set it here
                        $this->setIteratorInstance($iteratorInstance);
-               } // END - if
+               }
 
                // And return it
                return $iteratorInstance;
@@ -94,7 +98,7 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
         * @param       $groupName      Group to check if found in list
         * @return      $isset          Whether the group is valid
         */
-       public function isGroupSet ($groupName) {
+       public function isGroupSet (string $groupName) {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName);
                return isset($this->listGroups[$groupName]);
        }
@@ -106,13 +110,13 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
         * @return      void
         * @throws      ListGroupAlreadyAddedException  If the given group is already added
         */
-       public function addGroup ($groupName) {
+       public function addGroup (string $groupName) {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!');
                // Is the group already added?
                if ($this->isGroupSet($groupName)) {
                        // Throw the exception here
                        throw new ListGroupAlreadyAddedException(array($this, $groupName), self::EXCEPTION_GROUP_ALREADY_ADDED);
-               } // END - if
+               }
 
                // Add the group which is a simple array
                $this->listGroups[$groupName] = ObjectFactory::createObjectByConfiguredName('list_group_class');
@@ -128,7 +132,7 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
         * @return      void
         * @throws      NoListGroupException    If the given group is not found
         */
-       public function addInstance ($groupName, $subGroup, Visitable $visitableInstance) {
+       public function addInstance (string $groupName, string $subGroup, Visitable $visitableInstance) {
                // Debug message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName  . ',subGroup=' . $subGroup . ',visitableInstance=' . $visitableInstance->__toString() . ' - CALLED!');
 
@@ -136,13 +140,13 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
                if (!$this->isGroupSet($groupName)) {
                        // Throw the exception here
                        throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
-               } // END - if
+               }
 
                // Is the sub group there?
                if (!$this->listGroups[$groupName]->isGroupSet($subGroup)) {
                        // Automatically add it
                        $this->listGroups[$groupName]->addGroup($subGroup);
-               } // END - if
+               }
 
                // Generate the hash
                $hash = $this->generateHash($groupName, $subGroup, $visitableInstance);
@@ -175,7 +179,7 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
                if ((!is_null($list)) && (!$this->isGroupSet($list))) {
                        // Throw the exception here
                        throw new NoListGroupException(array($this, $list), self::EXCEPTION_GROUP_NOT_FOUND);
-               } // END - if
+               }
 
                // Init array
                $array = [];
@@ -184,7 +188,7 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
                if (!is_null($list)) {
                        // Then get it as well
                        $array = $this->listGroups[$list]->getArrayFromList(NULL);
-               } // END - if
+               }
 
                // Walk through all entries
                foreach ($this->listIndex as $hash) {
@@ -196,8 +200,8 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
                                // Add it
                                array_push($array, $this->listEntries[$hash]);
                                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: hash=' . $hash . ',array(' . count($array) . ')=' . print_r($array, true) . ' - ADDED!');
-                       } // END - if
-               } // END - foreach
+                       }
+               }
 
                // Debug message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',list[' . gettype($list) . ']=' . $list . ',[]=' . count($array) . ' - EXIT!');
@@ -214,7 +218,7 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
         * @return      void
         * @throws      NoListGroupException    If the given group is not found
         */
-       public function addEntry ($groupName, $entry) {
+       public function addEntry (string $groupName, $entry) {
                // Debug message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!');
 
@@ -222,7 +226,7 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
                if (!$this->isGroupSet($groupName)) {
                        // Throw the exception here
                        throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
-               } // END - if
+               }
 
                // Generate hash
                $hash = $this->generateHash($groupName, $groupName, $entry);
@@ -251,7 +255,7 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
         * @return      void
         * @throws      NoListGroupException    If the given group is not found
         */
-       public function removeEntry ($groupName, $entry) {
+       public function removeEntry (string $groupName, $entry) {
                // Debug message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!');
 
@@ -259,7 +263,7 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
                if (!$this->isGroupSet($groupName)) {
                        // Throw the exception here
                        throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
-               } // END - if
+               }
 
                // Generate hash
                $hash = $this->generateHash($groupName, $groupName, $entry);
@@ -285,7 +289,7 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
         * @param       $entry          An entry of any type
         * @return      $hash           The generated
         */
-       private function generateHash ($groupName, $subGroup, $entry) {
+       private function generateHash (string $groupName, string $subGroup, $entry) {
                // Created entry, 'null' is default
                $entry2 = 'null';
 
@@ -336,7 +340,7 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
                foreach ($groupNames as $groupName) {
                        // Clear this group
                        $this->clearGroup($groupName);
-               } // END - foreach
+               }
        }
 
        /**
@@ -345,12 +349,12 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
         * @param       $groupName      Name of an existing group to clear
         * @return      void
         */
-       protected function clearGroup ($groupName) {
+       protected function clearGroup (string $groupName) {
                // Does this group exist?
                if (!$this->isGroupSet($groupName)) {
                        // Throw the exception here
                        throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
-               } // END - if
+               }
 
                // Then clear this group list
                $this->listGroups[$groupName]->clearList();
@@ -412,7 +416,7 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
                if (!$this->isHashValid($hash)) {
                        // Throw an exception here
                        throw new InvalidListHashException(array($this, $hash, $hashIndex), self::EXCEPTION_INVALID_HASH);
-               } // END - if
+               }
 
                // Now copy the entry
                $entry = $this->listEntries[$hash];
@@ -428,12 +432,12 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
         * @return      $entries        The array with all entries
         * @throws      NoListGroupException    If the specified group is invalid
         */
-       public function getArrayFromProtocolInstance ($groupName) {
+       public function getArrayFromProtocolInstance (string $groupName) {
                // Is the group valid?
                if (!$this->isGroupSet($groupName)) {
                        // Throw the exception here
                        throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
-               } // END - if
+               }
 
                // Init the entries' array
                $entries = [];
@@ -460,7 +464,7 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
 
                        // Skip to next one
                        $iteratorInstance->next();
-               } // END - while
+               }
 
                // Return the list
                return $entries;
@@ -479,7 +483,7 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
                if (!$this->isHashValid($hash)) {
                        // Throw an exception here, hashIndex is unknown at this point
                        throw new InvalidListHashException(array($this, $hash, -999), self::EXCEPTION_INVALID_HASH);
-               } // END - if
+               }
 
                // Set the entry
                $this->listEntries[$hash] = $entryArray;