use Org\Mxchange\CoreFramework\Visitor\Visitable;
// Import SPL stuff
+use \InvalidArgumentException;
use \IteratorAggregate;
use \Countable;
* @return $isset Whether the group is valid
*/
public function isGroupSet (string $groupName) {
+ // Validate parameter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName);
+ if (empty($groupName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "groupName" is empty');
+ }
+
+ // Check on existence ...
return isset($this->listGroups[$groupName]);
}
* @throws ListGroupAlreadyAddedException If the given group is already added
*/
public function addGroup (string $groupName) {
+ // Validate parameter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!');
- // Is the group already added?
- if ($this->isGroupSet($groupName)) {
+ if (empty($groupName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "groupName" is empty');
+ } elseif ($this->isGroupSet($groupName)) {
// Throw the exception here
throw new ListGroupAlreadyAddedException(array($this, $groupName), self::EXCEPTION_GROUP_ALREADY_ADDED);
}
* @throws NoListGroupException If the given group is not found
*/
public function addInstance (string $groupName, string $subGroup, Visitable $visitableInstance) {
- // Debug message
+ // Validate parameter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ',subGroup=' . $subGroup . ',visitableInstance=' . $visitableInstance->__toString() . ' - CALLED!');
-
- // Is the group there?
- if (!$this->isGroupSet($groupName)) {
+ if (empty($groupName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "groupName" is empty');
+ } elseif (empty($subGroup)) {
+ // Throw it again
+ throw new InvalidArgumentException('Parameter "subGroup" is empty');
+ } elseif (!$this->isGroupSet($groupName)) {
// Throw the exception here
throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
}
/**
* Gets an array from given list
*
- * @param $list The requested list
+ * @param $groupName The requested list
* @return $array The requested array
* @throws NoListGroupException If the given group is not found
*/
- public final function getArrayFromList ($list) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',list[' . gettype($list) . ']=' . $list . ' - CALLED!');
-
+ public final function getArrayFromList ($groupName) {
// Is the group there?
- if ((!is_null($list)) && (!$this->isGroupSet($list))) {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName[' . gettype($groupName) . ']=' . $groupName . ' - CALLED!');
+ if (empty($groupName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "groupName" is empty');
+ } elseif ((!is_null($groupName)) && (!$this->isGroupSet($groupName))) {
// Throw the exception here
- throw new NoListGroupException(array($this, $list), self::EXCEPTION_GROUP_NOT_FOUND);
+ throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
}
// Init array
$array = [];
// Is there another list?
- if (!is_null($list)) {
+ if (!is_null($groupName)) {
// Then get it as well
- $array = $this->listGroups[$list]->getArrayFromList(NULL);
+ $array = $this->listGroups[$groupName]->getArrayFromList(NULL);
}
// Walk through all entries
foreach ($this->listIndex as $hash) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: hash=' . $hash);
-
// Is the list entry set?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: hash=' . $hash);
if ($this->isHashValid($hash)) {
// Add it
array_push($array, $this->listEntries[$hash]);
}
}
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',list[' . gettype($list) . ']=' . $list . ',[]=' . count($array) . ' - EXIT!');
-
// Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName[' . gettype($groupName) . ']=' . $groupName . ',[]=' . count($array) . ' - EXIT!');
return $array;
}
* @throws NoListGroupException If the given group is not found
*/
public function addEntry (string $groupName, $entry) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!');
-
// Is the group already added?
- if (!$this->isGroupSet($groupName)) {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!');
+ if (empty($groupName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "groupName" is empty');
+ } elseif (!$this->isGroupSet($groupName)) {
// Throw the exception here
throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
}
* @throws NoListGroupException If the given group is not found
*/
public function removeEntry (string $groupName, $entry) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!');
-
// Is the group already added?
- if (!$this->isGroupSet($groupName)) {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!');
+ if (empty($groupName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "groupName" is empty');
+ } elseif (!$this->isGroupSet($groupName)) {
// Throw the exception here
throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
}
*/
protected function clearGroup (string $groupName) {
// Does this group exist?
- if (!$this->isGroupSet($groupName)) {
+ if (empty($groupName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "groupName" is empty');
+ } elseif (!$this->isGroupSet($groupName)) {
// Throw the exception here
throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
}
* @param $hash The hash we should validate
* @return $isValid Whether the given hash is valid
*/
- public final function isHashValid ($hash) {
+ public final function isHashValid (string $hash) {
+ // Validate parameter
+ if (empty($hash)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "hash" is empty');
+ }
+
// Check it
$isValid = ((in_array($hash, $this->listIndex)) && (isset($this->listEntries[$hash])));
*/
public function getArrayFromProtocolInstance (string $groupName) {
// Is the group valid?
- if (!$this->isGroupSet($groupName)) {
+ if (empty($groupName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "groupName" is empty');
+ } elseif (!$this->isGroupSet($groupName)) {
// Throw the exception here
throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
}
* @return void
* @throws InvalidListHashException If the solved hash index is invalid
*/
- public function updateCurrentEntryByHash ($hash, array $entryArray) {
+ public function updateCurrentEntryByHash (string $hash, array $entryArray) {
// Is the hash valid?
- if (!$this->isHashValid($hash)) {
+ if (empty($hash)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "hash" is empty');
+ } elseif (!$this->isHashValid($hash)) {
// Throw an exception here, hashIndex is unknown at this point
throw new InvalidListHashException(array($this, $hash, -999), self::EXCEPTION_INVALID_HASH);
}