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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
first()
Moves the current index to the first available entry in the blockabstract int
Get the number of entries that exist in the block.int
getIndex()
Get current index of the entryboolean
invalid()
Checks if current entry has been marked as invalid.void
Marks this entry as invalidboolean
isFirst()
Checks if currently selected entry is the first one in the blockvoid
last()
Moves the current index to the last available entry in the blockvoid
moveTo
(int index) Sets the current index to the value as provided.void
next()
Moves current index one step forward: index=index+1void
previous()
Moves current index one step back: index=index-1protected void
throwExceptionIfInvalid
(String message) This should be executed if an unexpected operation is executed on the invalid entrytoString()
boolean
valid()
Checks if current entry has been marked as valid.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.
-
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:
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 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:
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
This should be executed if an unexpected operation is executed on the invalid entry- Parameters:
message
- the message be provided in the exception.
-