Class ValidatingEntry

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

public abstract class ValidatingEntry extends Object
An entry of the block that validates the index to be valid.

It encapsulates the number of entries and index of the entry withing the block as well as simple operation to move this index withing the boundaries of the block (given number of entries within the block).

It also supports an invalid status of the entry, but prevents any operation on it, in case the index is not within expected boundaries.

This is extracted as a separate entry to protected the FixSizeEntry from direct manipulating of the index, to have a better protection in case of invalid operations.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Moves the current index to the first available entry in the block
    abstract int
    Get the number of entries that exist in the block.
    int
    Get current index of the entry
    boolean
    Checks if current entry has been marked as invalid.
    void
    Marks this entry as invalid
    boolean
    Checks if currently selected entry is the first one in the block
    void
    Moves the current index to the last available entry in the block
    void
    moveTo(int index)
    Sets the current index to the value as provided.
    void
    Moves current index one step forward: index=index+1
    void
    Moves current index one step back: index=index-1
    protected void
    This should be executed if an unexpected operation is executed on the invalid entry
     
    boolean
    Checks if current entry has been marked as valid.
    void
    Checks if the current index is valid (the index should be strictly below the getEntriesNumber() and if it is not correct, marks this entry as invalid.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ValidatingEntry

      public ValidatingEntry()
  • Method Details

    • getEntriesNumber

      public abstract 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.

      Returns:
      the number of entries
    • getIndex

      public int getIndex()
      Get current index of the entry
      Returns:
      the index of currently selected entry
    • isFirst

      public boolean isFirst()
      Checks if currently selected entry is the first one in the block

      It will throw an exception if the entry is invalid.

      Returns:
      true if currently selected entry is the first one
    • invalidate

      public void invalidate()
      Marks this entry as invalid
    • validate

      public void validate()
      Checks if the current index is valid (the index should be strictly below the getEntriesNumber() and if it is not correct, marks this entry as invalid.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • invalid

      public boolean invalid()
      Checks if current entry has been marked as invalid.

      See validate()

      Returns:
      true if entry is invalid
    • valid

      public boolean valid()
      Checks if current entry has been marked as valid.

      See validate()

      Returns:
      true if entry is valid
    • moveTo

      public void moveTo(int index)
      Sets the current index to the value as provided.

      The function would mark the entry as invalid if the index does not lay withing the boundaries: 0..getEntriesNumber()

      Parameters:
      index - the index to be set
    • last

      public void last()
      Moves the current index to the last available entry in the block
    • first

      public void first()
      Moves the current index to the first available entry in the block
    • previous

      public void previous()
      Moves current index one step back: index=index-1
    • next

      public void next()
      Moves current index one step forward: index=index+1
    • throwExceptionIfInvalid

      protected void throwExceptionIfInvalid(String message)
      This should be executed if an unexpected operation is executed on the invalid entry
      Parameters:
      message - the message be provided in the exception.