]> 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 0d1692463daa09ecf6b4abd484c82db45f389ea8..570cc8fd24fbaf40f7e31daf50fa98bcfbfcde9b 100644 (file)
@@ -7,7 +7,7 @@ use Org\Mxchange\CoreFramework\Index\BaseIndex;
 use Org\Mxchange\CoreFramework\Index\Indexable;
 use Org\Mxchange\CoreFramework\Registry\Registerable;
 use Org\Mxchange\CoreFramework\Stack\File\StackableFile;
-use Org\Mxchange\CoreFramework\Stack\Index\IndexableStack;
+use Org\Mxchange\CoreFramework\Index\Stack\IndexableStack;
 
 // Import SPL stuff
 use \InvalidArgumentException;
@@ -67,16 +67,35 @@ class FileStackIndex extends BaseIndex implements IndexableStack, Registerable {
        }
 
        /**
-        * Adds given hash to an index file
+        * Adds given data's hash to an index file
         *
         * @param       $groupId        Name of stack to add hash for
         * @param       $data           Hash and gap position to be added to the index
         * @return      void
+        * @throws      InvalidArgumentException        If a parameter is not valid
         * @throws      UnexpectedValueException        If an invalid gap position is being returned
         */
-       public function addHashToIndex (string $groupId, array $data) {
+       public function addHashedDataToIndex (string $groupId, array $data) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,data()=%d - CALLED!', $groupId, count($data)));
+               if (empty($groupId)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "groupId" is empty');
+               } elseif (count($data) == 0) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "data" is an empty array');
+               } elseif (!isset($data[StackableFile::ARRAY_NAME_HASH])) {
+                       // Important array element missing
+                       throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_HASH]));
+               } elseif (!isset($data[StackableFile::ARRAY_NAME_GAP_POSITION])) {
+                       // Important array element missing
+                       throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_GAP_POSITION]));
+               } elseif (!isset($data[StackableFile::ARRAY_NAME_DATA_LENGTH])) {
+                       // Important array element missing
+                       throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_DATA_LENGTH]));
+               }
+
                // 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[StackableFile::ARRAY_NAME_HASH], $data[StackableFile::ARRAY_NAME_GAP_POSITION], $data[StackableFile::ARRAY_NAME_DATA_LENGTH]));
                $rawData = sprintf('%s%s%s%s%s%s%s',
                        $groupId,
                        Indexable::SEPARATOR_GROUP_HASH,
@@ -122,6 +141,9 @@ class FileStackIndex extends BaseIndex implements IndexableStack, Registerable {
                        // Throw IAE
                        throw new InvalidArgumentException(sprintf('length=%d is not valid', $length));
                }
+
+               // Partial stub!
+               $this->partialStub('length=' . $length);
        }
 
        /**
@@ -152,4 +174,15 @@ class FileStackIndex extends BaseIndex implements IndexableStack, Registerable {
                return $status;
        }
 
+       /**
+        * Checks if this index file has been fully and properly loaded.
+        *
+        * @return      $isLoaded       Whether this index file has been loaded
+        */
+       public function isIndexFileLoaded () {
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-STACK-INDEX: CALLED!');
+               /* DEBUG-DIE: */ die(sprintf('[%s:%d]: this=%s', __METHOD__, __LINE__, print_r($this, true)));
+       }
+
 }