]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/stacker/filo/class_FiLoStacker.php
Continued:
[core.git] / framework / main / classes / stacker / filo / class_FiLoStacker.php
index 61caf361c131e32b8eb3b1d8902ab22b07bd3e8a..5f5a5abc1dd00581809589bef12e9f66af7a75a2 100644 (file)
@@ -1,13 +1,16 @@
 <?php
 // Own namespace
-namespace Org\Mxchange\CoreFramework\Stacker;
+namespace Org\Mxchange\CoreFramework\Stack;
+
+// Import framework-specific stuff
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 
 /**
  * A FiLo 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 +33,7 @@ class FiLoStacker extends BaseStacker implements Stackable {
         *
         * @return      void
         */
-       protected function __construct () {
+       private function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
        }
@@ -42,12 +45,14 @@ class FiLoStacker extends BaseStacker implements Stackable {
         */
        public static final function createFiLoStacker () {
                // Get a new instance
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILO-FILE-STACK: CALLED!');
                $stackInstance = new FiLoStacker();
 
                // Init the generic stacker
                $stackInstance->initStack('generic');
 
                // Return the prepared instance
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILO-FILE-STACK: stackInstance=%s - EXIT!', $stackInstance->__toString()));
                return $stackInstance;
        }
 
@@ -57,11 +62,23 @@ class FiLoStacker 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('FILO-FILE-STACK: 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('FILO-FILE-STACK: Invoking parent::addValueToStack(%s,%s) ...', $stackerName, gettype($value)));
+               parent::addValueToStack($stackerName, $value);
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILO-FILE-STACK: EXIT!');
        }
 
        /**
@@ -69,17 +86,28 @@ class FiLoStacker 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('FILO-FILE-STACK: 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('FILO-FILE-STACK: this->getNamed(%s) ...', $stackerName));
                $value = $this->getNamed($stackerName);
 
                // Call the protected method
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILO-FILE-STACK: parent::popLast(%s) ...', $stackerName));
                parent::popLast($stackerName);
 
                // Return the value
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILO-FILE-STACK: value[]=%s - EXIT!', gettype($value)));
                return $value;
        }
 
@@ -88,12 +116,25 @@ class FiLoStacker 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('FILO-FILE-STACK: 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::getLastValue($stackerName);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILO-FILE-STACK: parent::getLastValue(%s) ...', $stackerName));
+               $value = parent::getLastValue($stackerName);
+
+               // Return the value
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILO-FILE-STACK: value[]=%s - EXIT!', gettype($value)));
+               return $value;
        }
 
 }