Class DataStorage.AbstractIterator
- java.lang.Object
-
- org.apfloat.spi.DataStorage.Iterator
-
- org.apfloat.spi.DataStorage.AbstractIterator
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.AutoCloseable
- Direct Known Subclasses:
DoubleDiskDataStorage.BlockIterator,DoubleMemoryDataStorage.ReadWriteIterator,FloatDiskDataStorage.BlockIterator,FloatMemoryDataStorage.ReadWriteIterator,IntDiskDataStorage.BlockIterator,IntMemoryDataStorage.ReadWriteIterator,LongDiskDataStorage.BlockIterator,LongMemoryDataStorage.ReadWriteIterator
- Enclosing class:
- DataStorage
protected abstract class DataStorage.AbstractIterator extends DataStorage.Iterator
Abstract base class for iterators iterating through thisDataStorage. This class provides most of the common functionality needed.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private intincrementprivate longlengthprivate intmodeprivate longpositionprivate static longserialVersionUID
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractIterator(int mode, long startPosition, long endPosition)Construct a new iterator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckGet()Checks if any of theget()methods can be called.protected voidcheckLength()Checks if the iterator is at the end yet.protected voidcheckSet()Checks if any of theset()methods can be called.doublegetDouble()Gets the current element as adouble.floatgetFloat()Gets the current element as afloat.protected intgetIncrement()Returns the increment of the iterator.intgetInt()Gets the current element as anint.protected longgetLength()Returns the remaining length in the iterator.longgetLong()Gets the current element as along.protected intgetMode()Returns the mode in which the iterator was created.protected longgetPosition()Returns the current position of the iterator.booleanhasNext()Check ifnext()can be called without going past the end of the sequence.voidnext()Advances the position in the stream by one element.voidsetDouble(double value)Sets the current element as adouble.voidsetFloat(float value)Sets the current element as afloat.voidsetInt(int value)Sets the current element as anint.voidsetLong(long value)Sets the current element as along.-
Methods inherited from class org.apfloat.spi.DataStorage.Iterator
close, get, set
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
mode
private int mode
-
increment
private int increment
-
position
private long position
-
length
private long length
-
-
Constructor Detail
-
AbstractIterator
protected AbstractIterator(int mode, long startPosition, long endPosition) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException, ApfloatRuntimeExceptionConstruct a new iterator. Elements can be iterated either in forward or in reverse order, depending on ifstartPositionis less than or greater thanendPosition, correspondingly.- Parameters:
mode- Access mode for iterator:DataStorage.READ,DataStorage.WRITEor 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:
java.lang.IllegalArgumentException- If the requested block is out of bounds of the data storage.java.lang.IllegalStateException- If write access is requested for a read-only data storage.ApfloatRuntimeException
-
-
Method Detail
-
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 - endPositiontimes. Theget()orset()methods should not be called for the last element.- Overrides:
hasNextin classDataStorage.Iterator- Returns:
trueifnext()can be called, otherwisefalse.
-
next
public void next() throws java.lang.IllegalStateException, ApfloatRuntimeExceptionAdvances 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 - endPositiontimes. Theget()orset()methods should not be called for the last element.- Overrides:
nextin classDataStorage.Iterator- Throws:
java.lang.IllegalStateException- If the iterator has been iterated to the end already.ApfloatRuntimeException
-
getInt
public int getInt() throws java.lang.UnsupportedOperationException, java.lang.IllegalStateException, ApfloatRuntimeExceptionDescription copied from class:DataStorage.IteratorGets the current element as anint.The default implementation calls
DataStorage.Iterator.get(Class)with argumentInteger.TYPE.- Overrides:
getIntin classDataStorage.Iterator- Returns:
- The current element as an
int. - Throws:
java.lang.UnsupportedOperationException- If the element type of the data storage can't be converted to anint.java.lang.IllegalStateException- If the iterator is at the end.ApfloatRuntimeException
-
getLong
public long getLong() throws java.lang.UnsupportedOperationException, java.lang.IllegalStateException, ApfloatRuntimeExceptionDescription copied from class:DataStorage.IteratorGets the current element as along.The default implementation calls
DataStorage.Iterator.get(Class)with argumentLong.TYPE.- Overrides:
getLongin classDataStorage.Iterator- Returns:
- The current element as a
long. - Throws:
java.lang.UnsupportedOperationException- If the element type of the data storage can't be converted to along.java.lang.IllegalStateException- If the iterator is at the end.ApfloatRuntimeException
-
getFloat
public float getFloat() throws java.lang.UnsupportedOperationException, java.lang.IllegalStateException, ApfloatRuntimeExceptionDescription copied from class:DataStorage.IteratorGets the current element as afloat.The default implementation calls
DataStorage.Iterator.get(Class)with argumentFloat.TYPE.- Overrides:
getFloatin classDataStorage.Iterator- Returns:
- The current element as a
float. - Throws:
java.lang.UnsupportedOperationException- If the element type of the data storage can't be converted to afloat.java.lang.IllegalStateException- If the iterator is at the end.ApfloatRuntimeException
-
getDouble
public double getDouble() throws java.lang.UnsupportedOperationException, java.lang.IllegalStateException, ApfloatRuntimeExceptionDescription copied from class:DataStorage.IteratorGets the current element as adouble.The default implementation calls
DataStorage.Iterator.get(Class)with argumentDouble.TYPE.- Overrides:
getDoublein classDataStorage.Iterator- Returns:
- The current element as a
double. - Throws:
java.lang.UnsupportedOperationException- If the element type of the data storage can't be converted to adouble.java.lang.IllegalStateException- If the iterator is at the end.ApfloatRuntimeException
-
setInt
public void setInt(int value) throws java.lang.UnsupportedOperationException, java.lang.IllegalStateException, ApfloatRuntimeExceptionDescription copied from class:DataStorage.IteratorSets the current element as anint.The default implementation calls
DataStorage.Iterator.set(Class,Object)with first argumentInteger.TYPE.- Overrides:
setIntin classDataStorage.Iterator- Parameters:
value- The value to be set to the current element as anint.- Throws:
java.lang.UnsupportedOperationException- If the element type of the data storage can't be converted to anint.java.lang.IllegalStateException- If the iterator is at the end.ApfloatRuntimeException
-
setLong
public void setLong(long value) throws java.lang.UnsupportedOperationException, java.lang.IllegalStateException, ApfloatRuntimeExceptionDescription copied from class:DataStorage.IteratorSets the current element as along.The default implementation calls
DataStorage.Iterator.set(Class,Object)with first argumentLong.TYPE.- Overrides:
setLongin classDataStorage.Iterator- Parameters:
value- The value to be set to the current element as along.- Throws:
java.lang.UnsupportedOperationException- If the element type of the data storage can't be converted to along.java.lang.IllegalStateException- If the iterator is at the end.ApfloatRuntimeException
-
setFloat
public void setFloat(float value) throws java.lang.UnsupportedOperationException, java.lang.IllegalStateException, ApfloatRuntimeExceptionDescription copied from class:DataStorage.IteratorSets the current element as afloat.The default implementation calls
DataStorage.Iterator.set(Class,Object)with first argumentFloat.TYPE.- Overrides:
setFloatin classDataStorage.Iterator- Parameters:
value- The value to be set to the current element as afloat.- Throws:
java.lang.UnsupportedOperationException- If the element type of the data storage can't be converted to afloat.java.lang.IllegalStateException- If the iterator is at the end.ApfloatRuntimeException
-
setDouble
public void setDouble(double value) throws java.lang.UnsupportedOperationException, java.lang.IllegalStateException, ApfloatRuntimeExceptionDescription copied from class:DataStorage.IteratorSets the current element as adouble.The default implementation calls
DataStorage.Iterator.set(Class,Object)with first argumentDouble.TYPE.- Overrides:
setDoublein classDataStorage.Iterator- Parameters:
value- The value to be set to the current element as adouble.- Throws:
java.lang.UnsupportedOperationException- If the element type of the data storage can't be converted to adouble.java.lang.IllegalStateException- If the iterator is at the end.ApfloatRuntimeException
-
checkGet
protected void checkGet() throws java.lang.IllegalStateExceptionChecks 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:
java.lang.IllegalStateException- If the iterator is at end or is not readable.
-
checkSet
protected void checkSet() throws java.lang.IllegalStateExceptionChecks 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:
java.lang.IllegalStateException- If the iterator is at end or is not writable.
-
checkLength
protected void checkLength() throws java.lang.IllegalStateExceptionChecks if the iterator is at the end yet.- Throws:
java.lang.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.
-
-