Class FixSizeEntry

java.lang.Object
org.rostore.v2.fixsize.ValidatingEntry
org.rostore.v2.fixsize.FixSizeEntry
Direct Known Subclasses:
CatalogBlockEntry, KeyBlockEntry

public abstract class FixSizeEntry extends ValidatingEntry
Abstract entry that encapsulates operation on the entries with the fixed size.

This object contains the reference of the block within the sequence, so it specifies a specific entry within the sequence.

  • Constructor Details

    • FixSizeEntry

      public FixSizeEntry(FixSizeEntryBlock fixSizeEntryBlock)
      Initializes the entry
      Parameters:
      fixSizeEntryBlock - a block abstraction to be used for entries
  • Method Details

    • getEntriesNumber

      public int getEntriesNumber()
      Get the number of entries that exist in the block.

      It is not to mix to capacity, and represents a total number of entries added to this block by now.

      Specified by:
      getEntriesNumber in class ValidatingEntry
      Returns:
      the number of entries
    • getHash

      public long getHash()
      Returns a hash of the current location of the entry, which encompasses with the index of the block and the index of the entry.

      Please note that the has can only be used if the block sequence is not changed.

      It also assumes that the number of blocks in the sequence and the number of entries in each block is not bigger that the 32bit.

      Returns:
      the hash that identifies the position of the selected entry in the sequence
    • moveToHash

      public void moveToHash(long hash)
      Moves the location of the current entry to the previously stored hash (see getHash()).
      Parameters:
      hash - the hash to move to
    • toString

      public String toString()
      Provides an explicit string representation of the entry location
      Overrides:
      toString in class ValidatingEntry
    • getFixSizeEntryBlock

      public FixSizeEntryBlock getFixSizeEntryBlock()
      Provides the block abstraction this entry is created with
      Returns:
      the block
    • getEntryLocation

      protected int getEntryLocation()
      Provides a pointer of the start of the entry within the block in bytes

      It validates if the entry is valid and throws an exception otherwise.

      Returns:
      the byte location of the entry within the body of the block
    • expand

      public void expand()
      Creates an entry at the end of the current block.

      It will throw an exception in case the capacity of the block does not allow to expand it.

      The number of entries will be increased.

      The new index will be set to the last entry.

      This operation will not validate the entry as it may be executed on the block without any entry (invalid one!)

    • remove

      public void remove()
      Removes current entry and collapses the space it used.

      All the entries that follows the current one will be moved up by one entry size.

      It will validate the current entry and throw an exception if the entry is invalid.

    • insert

      public void insert()
      Allocates an entry at the current index.

      All the entries at the current position to the end of the block are moved down the block body.

      The function will validate if the entry location is valid and throw an exception otherwise.

      It will not validate if the capacity is enough. Caller is responsible for it.

    • getEntrySize

      public abstract int getEntrySize()
      Provides an entry size in bytes
      Returns:
      the entry size in bytes