Class DataStorage.AbstractIterator
- All Implemented Interfaces:
Serializable
,AutoCloseable
- Enclosing class:
DataStorage
DataStorage
.
This class provides most of the common functionality needed.- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractIterator
(int mode, long startPosition, long endPosition) Construct a new iterator. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkGet()
Checks if any of theget()
methods can be called.protected void
Checks if the iterator is at the end yet.protected void
checkSet()
Checks if any of theset()
methods can be called.double
Gets the current element as adouble
.float
getFloat()
Gets the current element as afloat
.protected int
Returns the increment of the iterator.int
getInt()
Gets the current element as anint
.protected long
Returns the remaining length in the iterator.long
getLong()
Gets the current element as along
.protected int
getMode()
Returns the mode in which the iterator was created.protected long
Returns the current position of the iterator.boolean
hasNext()
Check ifnext()
can be called without going past the end of the sequence.void
next()
Advances the position in the stream by one element.void
setDouble
(double value) Sets the current element as adouble
.void
setFloat
(float value) Sets the current element as afloat
.void
setInt
(int value) Sets the current element as anint
.void
setLong
(long value) Sets the current element as along
.Methods inherited from class org.apfloat.spi.DataStorage.Iterator
close, get, set
-
Constructor Details
-
AbstractIterator
protected AbstractIterator(int mode, long startPosition, long endPosition) throws IllegalArgumentException, IllegalStateException, ApfloatRuntimeException Construct a new iterator. Elements can be iterated either in forward or in reverse order, depending on ifstartPosition
is less than or greater thanendPosition
, correspondingly.- Parameters:
mode
- Access mode for iterator:DataStorage.READ
,DataStorage.WRITE
or both.startPosition
- Starting position of iterator in the data set. For reverse access, the first element in the iterator isstartPosition - 1
.endPosition
- End position of iterator in the data set. For forward access, the last accessible element in the iterator isendPosition - 1
.- Throws:
IllegalArgumentException
- If the requested block is out of bounds of the data storage.IllegalStateException
- If write access is requested for a read-only data storage.ApfloatRuntimeException
-
-
Method Details
-
hasNext
public boolean hasNext()Check ifnext()
can be called without going past the end of the sequence. That is, ifnext()
can be called without deliberately causing an exception.Note: It is important that the iterator is iterated past the last element; that is
next()
is calledstartPosition - endPosition
times. Theget()
orset()
methods should not be called for the last element.- Overrides:
hasNext
in classDataStorage.Iterator
- Returns:
true
ifnext()
can be called, otherwisefalse
.
-
next
Advances the position in the stream by one element.Note: It is important that the iterator is iterated past the last element; that is
next()
is calledstartPosition - endPosition
times. Theget()
orset()
methods should not be called for the last element.- Overrides:
next
in classDataStorage.Iterator
- Throws:
IllegalStateException
- If the iterator has been iterated to the end already.ApfloatRuntimeException
-
getInt
public int getInt() throws UnsupportedOperationException, IllegalStateException, ApfloatRuntimeExceptionDescription copied from class:DataStorage.Iterator
Gets the current element as anint
.The default implementation calls
DataStorage.Iterator.get(Class)
with argumentInteger.TYPE
.- Overrides:
getInt
in classDataStorage.Iterator
- Returns:
- The current element as an
int
. - Throws:
UnsupportedOperationException
- If the element type of the data storage can't be converted to anint
.IllegalStateException
- If the iterator is at the end.ApfloatRuntimeException
-
getLong
public long getLong() throws UnsupportedOperationException, IllegalStateException, ApfloatRuntimeExceptionDescription copied from class:DataStorage.Iterator
Gets the current element as along
.The default implementation calls
DataStorage.Iterator.get(Class)
with argumentLong.TYPE
.- Overrides:
getLong
in classDataStorage.Iterator
- Returns:
- The current element as a
long
. - Throws:
UnsupportedOperationException
- If the element type of the data storage can't be converted to along
.IllegalStateException
- If the iterator is at the end.ApfloatRuntimeException
-
getFloat
public float getFloat() throws UnsupportedOperationException, IllegalStateException, ApfloatRuntimeExceptionDescription copied from class:DataStorage.Iterator
Gets the current element as afloat
.The default implementation calls
DataStorage.Iterator.get(Class)
with argumentFloat.TYPE
.- Overrides:
getFloat
in classDataStorage.Iterator
- Returns:
- The current element as a
float
. - Throws:
UnsupportedOperationException
- If the element type of the data storage can't be converted to afloat
.IllegalStateException
- If the iterator is at the end.ApfloatRuntimeException
-
getDouble
public double getDouble() throws UnsupportedOperationException, IllegalStateException, ApfloatRuntimeExceptionDescription copied from class:DataStorage.Iterator
Gets the current element as adouble
.The default implementation calls
DataStorage.Iterator.get(Class)
with argumentDouble.TYPE
.- Overrides:
getDouble
in classDataStorage.Iterator
- Returns:
- The current element as a
double
. - Throws:
UnsupportedOperationException
- If the element type of the data storage can't be converted to adouble
.IllegalStateException
- If the iterator is at the end.ApfloatRuntimeException
-
setInt
public void setInt(int value) throws UnsupportedOperationException, IllegalStateException, ApfloatRuntimeException Description copied from class:DataStorage.Iterator
Sets the current element as anint
.The default implementation calls
DataStorage.Iterator.set(Class,Object)
with first argumentInteger.TYPE
.- Overrides:
setInt
in classDataStorage.Iterator
- Parameters:
value
- The value to be set to the current element as anint
.- Throws:
UnsupportedOperationException
- If the element type of the data storage can't be converted to anint
.IllegalStateException
- If the iterator is at the end.ApfloatRuntimeException
-
setLong
public void setLong(long value) throws UnsupportedOperationException, IllegalStateException, ApfloatRuntimeException Description copied from class:DataStorage.Iterator
Sets the current element as along
.The default implementation calls
DataStorage.Iterator.set(Class,Object)
with first argumentLong.TYPE
.- Overrides:
setLong
in classDataStorage.Iterator
- Parameters:
value
- The value to be set to the current element as along
.- Throws:
UnsupportedOperationException
- If the element type of the data storage can't be converted to along
.IllegalStateException
- If the iterator is at the end.ApfloatRuntimeException
-
setFloat
public void setFloat(float value) throws UnsupportedOperationException, IllegalStateException, ApfloatRuntimeException Description copied from class:DataStorage.Iterator
Sets the current element as afloat
.The default implementation calls
DataStorage.Iterator.set(Class,Object)
with first argumentFloat.TYPE
.- Overrides:
setFloat
in classDataStorage.Iterator
- Parameters:
value
- The value to be set to the current element as afloat
.- Throws:
UnsupportedOperationException
- If the element type of the data storage can't be converted to afloat
.IllegalStateException
- If the iterator is at the end.ApfloatRuntimeException
-
setDouble
public void setDouble(double value) throws UnsupportedOperationException, IllegalStateException, ApfloatRuntimeException Description copied from class:DataStorage.Iterator
Sets the current element as adouble
.The default implementation calls
DataStorage.Iterator.set(Class,Object)
with first argumentDouble.TYPE
.- Overrides:
setDouble
in classDataStorage.Iterator
- Parameters:
value
- The value to be set to the current element as adouble
.- Throws:
UnsupportedOperationException
- If the element type of the data storage can't be converted to adouble
.IllegalStateException
- If the iterator is at the end.ApfloatRuntimeException
-
checkGet
Checks if any of theget()
methods can be called. This checks both that the iterator is not at the end yet, and that the iterator was opened in a readable mode.- Throws:
IllegalStateException
- If the iterator is at end or is not readable.
-
checkSet
Checks if any of theset()
methods can be called. This checks both that the iterator is not at the end yet, and that the iterator was opened in a writable mode.- Throws:
IllegalStateException
- If the iterator is at end or is not writable.
-
checkLength
Checks if the iterator is at the end yet.- Throws:
IllegalStateException
- If the iterator is at end.
-
getMode
protected int getMode()Returns the mode in which the iterator was created.- Returns:
- The mode in which the iterator was created.
-
getPosition
protected long getPosition()Returns the current position of the iterator.- Returns:
- The current position of the iterator.
-
getLength
protected long getLength()Returns the remaining length in the iterator.- Returns:
- The remaining length in the iterator.
-
getIncrement
protected int getIncrement()Returns the increment of the iterator. This is 1 if the iterator runs forward, or -1 if the iterator runs backwards in the data.- Returns:
- The increment of the iterator.
-