Class ValidatingEntry
- Direct Known Subclasses:
FixSizeEntry
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidfirst()Moves the current index to the first available entry in the blockabstract intGet the number of entries that exist in the block.intgetIndex()Get current index of the entrybooleaninvalid()Checks if current entry has been marked as invalid.voidMarks this entry as invalidbooleanisFirst()Checks if currently selected entry is the first one in the blockvoidlast()Moves the current index to the last available entry in the blockvoidmoveTo(int index) Sets the current index to the value as provided.voidnext()Moves current index one step forward: index=index+1voidprevious()Moves current index one step back: index=index-1protected voidthrowExceptionIfInvalid(String message) This should be executed if an unexpected operation is executed on the invalid entrytoString()booleanvalid()Checks if current entry has been marked as valid.voidvalidate()Checks if the current index is valid (the index should be strictly below thegetEntriesNumber()and if it is not correct, marks this entry as invalid.
-
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 blockIt will throw an exception if the entry is invalid.
- Returns:
trueif 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 thegetEntriesNumber()and if it is not correct, marks this entry as invalid. -
toString
-
invalid
public boolean invalid()Checks if current entry has been marked as invalid.See
validate()- Returns:
trueif entry is invalid
-
valid
public boolean valid()Checks if current entry has been marked as valid.See
validate()- Returns:
trueif 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
This should be executed if an unexpected operation is executed on the invalid entry- Parameters:
message- the message be provided in the exception.
-