use Org\Mxchange\CoreFramework\Visitor\Visitable;
// Import SPL stuff
+use \BadMethodCallException;
use \InvalidArgumentException;
use \IteratorAggregate;
use \Countable;
*/
public function isGroupSet (string $groupName) {
// Validate parameter
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: groupName=' . $groupName);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-LIST: groupName=%s - CALLED!', $groupName));
if (empty($groupName)) {
// Throw IAE
throw new InvalidArgumentException('Parameter "groupName" is empty');
}
/**
- * Adds the given group or if already added issues a ListGroupAlreadyAddedException
+ * Adds the given group or if already added issues a BadMethodCallException
*
* @param $groupName Group to add
* @return void
- * @throws ListGroupAlreadyAddedException If the given group is already added
+ * @throws BadMethodCallException If the given group is already added
*/
public function addGroup (string $groupName) {
// Validate parameter
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: groupName=' . $groupName . ' - CALLED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-LIST: groupName=%s - CALLED!', $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);
+ throw new BadMethodCallException(sprintf('groupName=%s is already set', $groupName), self::EXCEPTION_GROUP_ALREADY_ADDED);
}
// Add the group which is a simple array
* @param $subGroup Sub group to add instance to
* @param $visitableInstance An instance of Visitable
* @return void
- * @throws NoListGroupException If the given group is not found
+ * @throws BadMethodCallException If the given group is not found
*/
public function addInstance (string $groupName, string $subGroup, Visitable $visitableInstance) {
// Validate parameter
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);
+ throw new BadMethodCallException(sprintf('groupName=%s is not a valid group', $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
}
// Is the sub group there?
// Generate the hash
$hash = $this->generateHash($groupName, $subGroup, $visitableInstance);
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this->listGroups[' . $groupName . ']=' . $this->listGroups[$groupName]->__toString());
-
// Add the hash to the index
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this->listGroups[' . $groupName . ']=' . $this->listGroups[$groupName]->__toString());
array_push($this->listIndex, $hash);
// Add the instance itself to the list
*
* @param $groupName The requested list
* @return $array The requested array
- * @throws NoListGroupException If the given group is not found
+ * @throws BadMethodCallException If the given group is not found
*/
public final function getArrayFromList (string $groupName) {
// Is the group there?
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);
+ throw new BadMethodCallException(sprintf('groupName=%s is not a valid group', $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
}
// Init array
$array = [];
// Is there another list?
- if (!is_null($groupName)) {
+ if ($this->listGroups[$groupName]->isGroupSet($groupName)) {
// Then get it as well
- $array = $this->listGroups[$groupName]->getArrayFromList('__');
+ //* DEBUG-DIE: */ die(sprintf('[%s:%d]: groupName=%s,this=%s', __METHOD__, __LINE__, $groupName, print_r($this, TRUE)));
+ $array = $this->listGroups[$groupName]->getArrayFromList($groupName);
}
// Walk through all entries
* @param $groupName Group to add instance to
* @param $entry An entry of any type
* @return void
- * @throws NoListGroupException If the given group is not found
+ * @throws BadMethodCallException If the given group is not found
*/
public function addEntry (string $groupName, $entry) {
// Is the group already added?
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);
+ throw new BadMethodCallException(sprintf('groupName=%s is not a valid group', $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
}
// Generate hash
* @param $groupName Group where we should remove the entry from
* @param $entry The entry we should remove
* @return void
- * @throws NoListGroupException If the given group is not found
+ * @throws BadMethodCallException If the given group is not found
*/
public function removeEntry (string $groupName, $entry) {
// Is the group already added?
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);
+ throw new BadMethodCallException(sprintf('groupName=%s is not a valid group', $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
}
// Generate hash
*/
private function generateHash (string $groupName, string $subGroup, $entry) {
// Created entry, 'null' is default
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: groupName=' . $groupName . ',subGroup=' . $subGroup . ',entry[]=' . gettype($entry) . ' - CALLED!');
$entry2 = 'null';
// Determine type of entry
}
// Construct string which we shall hash
- $hashString = $groupName . ':' . $subGroup . ':' . $entry2;
+ $hashString = sprintf('%s:%s:%s', $groupName, $subGroup, $entry2);
// Hash it with fastest hasher
$hash = crc32($hashString);
// And return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-LIST: hash=%s - EXIT!', $hash));
return $hash;
}
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);
+ throw new BadMethodCallException(sprintf('groupName=%s is not a valid group', $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
}
// Then clear this group list
*
* @param $groupName The group name to get a list for
* @return $entries The array with all entries
- * @throws NoListGroupException If the specified group is invalid
+ * @throws BadMethodCallException If the specified group is invalid
*/
public function getArrayFromProtocolInstance (string $groupName) {
// Is the group valid?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-LIST: groupName=%s - CALLED!', $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);
+ throw new BadMethodCallException(sprintf('groupName=%s is not a valid group', $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
}
// Init the entries' array
// ... and the final entry which is the stored instance
$entry = $this->getEntry($entryIndex);
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('LIST: Adding entry ' . $entry . ' ...');
-
// Add it to the list
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: Adding entry ' . $entry . ' ...');
$entries[$iteratorInstance->current()] = $entry;
// Skip to next one