Continued:
[core.git] / framework / main / classes / stacker / fifo / class_FiFoStacker.php
index 6e73709eac79431d7411514aeee2ba438fddc76e..2ab3ec5f632c3f9b0f2784cc27a87cf713be5962 100644 (file)
@@ -1,13 +1,19 @@
 <?php
 // Own namespace
-namespace Org\Mxchange\CoreFramework\Stacker;
+namespace Org\Mxchange\CoreFramework\Stack;
+
+// Import framework-specific stuff
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
+
+// Import SPL stuff
+use \InvalidArgumentException;
 
 /**
  * A FiFo Stacker class
  *
  * @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
  *
@@ -30,7 +36,7 @@ class FiFoStacker extends BaseStacker implements Stackable {
         *
         * @return      void
         */
-       protected function __construct () {
+       private function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
        }
@@ -57,11 +63,23 @@ class FiFoStacker extends BaseStacker implements Stackable {
         * @param       $stackerName    Name of the stack
         * @param       $value                  Value to push on it
         * @return      void
-        * @throws      StackerFullException    If the stack is full
+        * @throws      InvalidArgumentException        If a parameter is invalid
+        * @throws      BadMethodCallException  If the stack is full
         */
-       public function pushNamed ($stackerName, $value) {
+       public function pushNamed (string $stackerName, $value) {
+               // Validate parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s,value[]=%s - CALLED!', $stackerName, gettype($value)));
+               if (empty($stackerName)) {
+                       // No empty stack name
+                       throw new InvalidArgumentException('Parameter "stackerName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               }
+
                // Call the protected method
-               parent::addValue($stackerName, $value);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: Invoking parent::addValueToStack(%s,%s) ...', $stackerName, gettype($value)));
+               parent::addValueToStack($stackerName, $value);
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-STACKER: EXIT!');
        }
 
        /**
@@ -69,17 +87,28 @@ class FiFoStacker extends BaseStacker implements Stackable {
         *
         * @param       $stackerName    Name of the stack
         * @return      $value                  Value of the current stack entry
-        * @throws      NoStackerException      If the named stacker was not found
-        * @throws      EmptyStackerException   If the named stacker is empty
+        * @throws      InvalidArgumentException        If a parameter is invalid
+        * @throws      BadMethodCallException  If the named stacker was not found
+        * @throws      BadMethodCallException  If the named stacker is empty
         */
-       public function popNamed ($stackerName) {
+       public function popNamed (string $stackerName) {
+               // Validate parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s - CALLED!', $stackerName));
+               if (empty($stackerName)) {
+                       // No empty stack name
+                       throw new InvalidArgumentException('Parameter "stackerName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               }
+
                // Get the value
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: Invoking this->getNamed(%s) ...', $stackerName));
                $value = $this->getNamed($stackerName);
 
                // Call the protected method
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: Invoking parent::popFirst(%s) ...', $stackerName));
                parent::popFirst($stackerName);
 
                // Return the value
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: value[]=%s - EXIT!', gettype($value)));
                return $value;
        }
 
@@ -88,12 +117,25 @@ class FiFoStacker extends BaseStacker implements Stackable {
         *
         * @param       $stackerName    Name of the stack
         * @return      $value                  Value of last added value
-        * @throws      NoStackerException      If the named stacker was not found
-        * @throws      EmptyStackerException   If the named stacker is empty
+        * @throws      InvalidArgumentException        If a parameter is invalid
+        * @throws      BadMethodCallException  If the named stacker was not found
+        * @throws      BadMethodCallException  If the named stacker is empty
         */
-       public function getNamed ($stackerName) {
+       public function getNamed (string $stackerName) {
+               // Validate parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s - CALLED!', $stackerName));
+               if (empty($stackerName)) {
+                       // No empty stack name
+                       throw new InvalidArgumentException('Parameter "stackerName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               }
+
                // Call the protected method
-               return parent::getFirstValue($stackerName);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: Invoking parent::getFirstValue(%s) ...', $stackerName));
+               $value = parent::getFirstValue($stackerName);
+
+               // Return value
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: value[]=%s - EXIT!', gettype($value)));
+               return $value;
        }
 
 }