]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/stacker/class_BaseStacker.php
Some 'final' more, some 'final' less. ;-)
[core.git] / inc / classes / main / stacker / class_BaseStacker.php
index d28175804e3d47e511a0db7886156ae4c92919df..f9dc7b6ad5f1bd95cef374d7bd37d008ba57ed2d 100644 (file)
@@ -2,11 +2,11 @@
 /**
  * A general Stacker
  *
- * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
+ * @link               http://www.shipsimu.org
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -47,15 +47,28 @@ class BaseStacker extends BaseFrameworkSystem {
         * @return      void
         * @throws      AlreadyInitializedStackerException      If the stack is already initialized
         */
-       public final function initStacker ($stackerName, $forceReInit = FALSE) {
+       public function initStack ($stackerName, $forceReInit = FALSE) {
                // Is the stack already initialized?
                if (($forceReInit === FALSE) && ($this->isStackInitialized($stackerName))) {
                        // Then throw the exception
-                       throw new AlreadyInitializedStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_ALREADY_INITIALIZED);
+                       throw new AlreadyInitializedStackerException(array($this, $stackerName, $forceReInit), self::EXCEPTION_STACKER_ALREADY_INITIALIZED);
                } // END - if
 
                // Initialize the given stack
-               $this->initGenericArray('stacks', $stackerName, 'entries');
+               $this->initGenericArrayKey('stacks', $stackerName, 'entries', $forceReInit);
+       }
+
+       /**
+        * Initializes all stacks
+        *
+        * @return      void
+        */
+       public function initStacks (array $stacks, $forceReInit = FALSE) {
+               // "Walk" through all (more will be added as needed
+               foreach ($stacks as $stackerName) {
+                       // Init this stack
+                       $this->initStack($stackerName, $forceReInit);
+               } // END - foreach
        }
 
        /**
@@ -64,7 +77,7 @@ class BaseStacker extends BaseFrameworkSystem {
         * @param       $stackerName    Name of the stack
         * @return      $isInitialized  Whether the stack is initialized
         */
-       public final function isStackInitialized ($stackerName) {
+       public function isStackInitialized ($stackerName) {
                // Is is there?
                $isInitialized = ($this->isValidGenericArrayKey('stacks', $stackerName, 'entries'));
 
@@ -79,7 +92,7 @@ class BaseStacker extends BaseFrameworkSystem {
         * @return      $isFull                 Whether the stack is full
         * @throws      NoStackerException      If given stack is missing
         */
-       protected final function isStackFull ($stackerName) {
+       protected function isStackFull ($stackerName) {
                // Is the stack not yet initialized?
                if (!$this->isStackInitialized($stackerName)) {
                        // Throw an exception
@@ -100,7 +113,7 @@ class BaseStacker extends BaseFrameworkSystem {
         * @return      $isEmpty                        Whether the stack is empty
         * @throws      NoStackerException      If given stack is missing
         */
-       public final function isStackEmpty ($stackerName) {
+       public function isStackEmpty ($stackerName) {
                // Is the stack not yet initialized?
                if (!$this->isStackInitialized($stackerName)) {
                        // Throw an exception
@@ -121,7 +134,7 @@ class BaseStacker extends BaseFrameworkSystem {
         * @return      $count                  Size of stack (array count)
         * @throws      NoStackerException      If given stack is missing
         */
-       public final function getStackCount ($stackerName) {
+       public function getStackCount ($stackerName) {
                // Is the stack not yet initialized?
                if (!$this->isStackInitialized($stackerName)) {
                        // Throw an exception
@@ -143,18 +156,18 @@ class BaseStacker extends BaseFrameworkSystem {
         * @return      void
         * @throws      FullStackerException    Thrown if the stack is full
         */
-       protected final function addValue ($stackerName, $value) {
+       protected function addValue ($stackerName, $value) {
                // Is the stack not yet initialized or full?
                if (!$this->isStackInitialized($stackerName)) {
                        // Then do it here
-                       $this->initStacker($stackerName);
+                       $this->initStack($stackerName);
                } elseif ($this->isStackFull($stackerName)) {
                        // Stacker is full
                        throw new FullStackerException(array($this, $stackerName, $value), self::EXCEPTION_STACKER_IS_FULL);
                }
 
                // Now add the value to the stack
-               $this->pushValueToGenericArrayElement('stacks', $stackerName, 'entries', $value);
+               $this->pushValueToGenericArrayKey('stacks', $stackerName, 'entries', $value);
        }
 
        /**
@@ -165,13 +178,13 @@ class BaseStacker extends BaseFrameworkSystem {
         * @throws      NoStackerException      If the named stacker was not found
         * @throws      EmptyStackerException   If the named stacker is empty
         */
-       protected final function getLastValue ($stackerName) {
+       protected function getLastValue ($stackerName) {
                // Is the stack not yet initialized or full?
                if (!$this->isStackInitialized($stackerName)) {
                        // Throw an exception
                        throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
                } elseif ($this->isStackEmpty($stackerName)) {
-                       //Throw an exception
+                       // Throw an exception
                        throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
                }
 
@@ -190,18 +203,18 @@ class BaseStacker extends BaseFrameworkSystem {
         * @throws      NoStackerException      If the named stacker was not found
         * @throws      EmptyStackerException   If the named stacker is empty
         */
-       protected final function getFirstValue ($stackerName) {
+       protected function getFirstValue ($stackerName) {
                // Is the stack not yet initialized or full?
                if (!$this->isStackInitialized($stackerName)) {
                        // Throw an exception
                        throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
                } elseif ($this->isStackEmpty($stackerName)) {
-                       //Throw an exception
+                       // Throw an exception
                        throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
                }
 
                // Now get the first value
-               $value = $this->popGenericArrayElement('stacks', $stackerName, 'entries', 0);
+               $value = $this->getGenericArrayElement('stacks', $stackerName, 'entries', 0);
 
                // Return it
                return $value;
@@ -211,44 +224,44 @@ class BaseStacker extends BaseFrameworkSystem {
         * "Pops" last entry from stack
         *
         * @param       $stackerName    Name of the stack
-        * @return      void
+        * @return      $value                  Value "poped" from array
         * @throws      NoStackerException      If the named stacker was not found
         * @throws      EmptyStackerException   If the named stacker is empty
         */
-       protected final function popLast ($stackerName) {
+       protected function popLast ($stackerName) {
                // Is the stack not yet initialized or full?
                if (!$this->isStackInitialized($stackerName)) {
                        // Throw an exception
                        throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
                } elseif ($this->isStackEmpty($stackerName)) {
-                       //Throw an exception
+                       // Throw an exception
                        throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
                }
 
                // Now, remove the last entry, we don't care about the return value here, see elseif() block above
-               $this->popGenericArrayElement('stacks', $stackerName, 'entries');
+               return $this->popGenericArrayElement('stacks', $stackerName, 'entries');
        }
 
        /**
         * "Pops" first entry from stack
         *
         * @param       $stackerName    Name of the stack
-        * @return      void
+        * @return      $value                  Value "shifted" from array
         * @throws      NoStackerException      If the named stacker was not found
         * @throws      EmptyStackerException   If the named stacker is empty
         */
-       protected final function popFirst ($stackerName) {
+       protected function popFirst ($stackerName) {
                // Is the stack not yet initialized or full?
                if (!$this->isStackInitialized($stackerName)) {
                        // Throw an exception
                        throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
                } elseif ($this->isStackEmpty($stackerName)) {
-                       //Throw an exception
+                       // Throw an exception
                        throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
                }
 
                // Now, remove the last entry, we don't care about the return value here, see elseif() block above
-               $this->shiftGenericArrayElement('stacks', $stackerName, 'entries');
+               return $this->shiftGenericArrayElement('stacks', $stackerName, 'entries');
        }
 }