]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/index/file_stack/class_FileStackIndex.php
Continued:
[core.git] / framework / main / classes / index / file_stack / class_FileStackIndex.php
index a274dc46e5279738e6cd5b0bc0682f3d1beb3233..218b9b74f4e8e8d44fdd9b9b8913ed211a747555 100644 (file)
@@ -10,6 +10,7 @@ use Org\Mxchange\CoreFramework\Stacker\Filesystem\BaseFileStack;
 use Org\Mxchange\CoreFramework\Stacker\Index\IndexableStack;
 
 // Import SPL stuff
+use \InvalidArgumentException;
 use \SplFileInfo;
 
 /**
@@ -53,12 +54,14 @@ class FileStackIndex extends BaseIndex implements IndexableStack, Registerable {
         */
        public final static function createFileStackIndex (SplFileInfo $fileInfoInstance) {
                // Get a new instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: fileInfoInstance=%s - CALLED!', $fileInfoInstance));
                $indexInstance = new FileStackIndex();
 
                // Initialize index
                $indexInstance->initIndex($fileInfoInstance);
 
                // Return the prepared instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: indexInstance=%s - EXIT!', $indexInstance->__toString()));
                return $indexInstance;
        }
 
@@ -69,11 +72,9 @@ class FileStackIndex extends BaseIndex implements IndexableStack, Registerable {
         * @param       $data           Hash and gap position to be added to the index
         * @return      void
         */
-       public function addHashToIndex ($groupId, array $data) {
-               // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] groupId=%s,hash=%s,gap=%d,length=%d - CALLED!', __METHOD__, __LINE__, $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], $data[BaseFileStack::ARRAY_INDEX_GAP_POSITION], $data[BaseFileStack::ARRAY_INDEX_DATA_LENGTH]));
-
+       public function addHashToIndex (string $groupId, array $data) {
                // Raw data been written to the file
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,gap=%d,length=%d - CALLED!', $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], $data[BaseFileStack::ARRAY_INDEX_GAP_POSITION], $data[BaseFileStack::ARRAY_INDEX_DATA_LENGTH]));
                $rawData = sprintf('%s%s%s%s%s%s%s',
                        $groupId,
                        self::SEPARATOR_GROUP_HASH,
@@ -85,7 +86,7 @@ class FileStackIndex extends BaseIndex implements IndexableStack, Registerable {
                );
 
                // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] groupId=%s,hash=%s,rawData()=%d', __METHOD__, __LINE__, $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], strlen($rawData)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,rawData()=%d', $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], strlen($rawData)));
 
                // Search for next free gap
                $gapPosition = $this->getIteratorInstance()->searchNextGap(strlen($rawData));
@@ -93,14 +94,12 @@ class FileStackIndex extends BaseIndex implements IndexableStack, Registerable {
                // Gap position cannot be smaller than header length + 1
                assert($gapPosition > $this->getIteratorInstance()->getHeaderSize());
 
-               // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] groupId=%s,hash=%s,gapPosition=%s', __METHOD__, __LINE__, $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], $gapPosition));
-
                // Then write the data at that gap
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,gapPosition=%s', $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], $gapPosition));
                $this->getIteratorInstance()->writeData($gapPosition, $rawData);
 
-               // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] groupId=%s,hash=%s,rawData()=%d - EXIT!', __METHOD__, __LINE__, $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], strlen($rawData)));
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,rawData()=%d - EXIT!', $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], strlen($rawData)));
        }
 
        /**
@@ -109,9 +108,16 @@ class FileStackIndex extends BaseIndex implements IndexableStack, Registerable {
         *
         * @param       $length                 Length of raw data
         * @return      $seekPosition   Found next gap's seek position
+        * @throws      InvalidArgumentException        If the parameter is not valid
+        * @todo        Unfinished work
         */
-       public function searchNextGap ($length) {
-               $this->partialStub('length=' . $length);
+       public function searchNextGap (int $length) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: length=%d - CALLED!', $length));
+               if ($length <= 0) {
+                       // Throw IAE
+                       throw new InvalidArgumentException(sprintf('length=%d is not valid', $length));
+               }
        }
 
 }