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
* 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;
// Set it here
$this->setIteratorInstance($iteratorInstance);
- } // END - if
+ }
// And return it
return $iteratorInstance;
* @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]);
}
* @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');
* @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!');
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);
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 = [];
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) {
// 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!');
* @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!');
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);
* @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!');
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);
* @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';
foreach ($groupNames as $groupName) {
// Clear this group
$this->clearGroup($groupName);
- } // END - foreach
+ }
}
/**
* @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();
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];
* @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 = [];
// Skip to next one
$iteratorInstance->next();
- } // END - while
+ }
// Return the list
return $entries;
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;