Class DataStorage.Iterator
- java.lang.Object
-
- org.apfloat.spi.DataStorage.Iterator
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.AutoCloseable
- Direct Known Subclasses:
DataStorage.AbstractIterator
- Enclosing class:
- DataStorage
public abstract static class DataStorage.Iterator extends java.lang.Object implements java.io.Serializable, java.lang.AutoCloseable
Iterator for iterating through elements of the data storage.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static long
serialVersionUID
-
Constructor Summary
Constructors Modifier Constructor Description protected
Iterator()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the iterator.<T> T
get(java.lang.Class<T> type)
Gets the current element as a the specified element type.double
getDouble()
Gets the current element as adouble
.float
getFloat()
Gets the current element as afloat
.int
getInt()
Gets the current element as anint
.long
getLong()
Gets the current element as along
.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.<T> void
set(java.lang.Class<T> type, T value)
Sets the current element as the specified element type.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
.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Method Detail
-
hasNext
public boolean hasNext()
Check ifnext()
can be called without going past the end of the sequence.That is, if
next()
can be called without deliberately causing an exception. Note: It is important that the iterator is iterated past the last element; that isnext()
is calledstartPosition - endPosition
times. Theget()
orset()
methods should not be called for the last element.The default implementation always returns
false
.- Returns:
true
ifnext()
can be called, otherwisefalse
.
-
next
public void next() throws java.lang.IllegalStateException, ApfloatRuntimeException
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.The default implementation always throws
IllegalStateException
.- 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, ApfloatRuntimeException
Gets the current element as anint
.The default implementation calls
get(Class)
with argumentInteger.TYPE
.- 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, ApfloatRuntimeException
Gets the current element as along
.The default implementation calls
get(Class)
with argumentLong.TYPE
.- 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, ApfloatRuntimeException
Gets the current element as afloat
.The default implementation calls
get(Class)
with argumentFloat.TYPE
.- 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, ApfloatRuntimeException
Gets the current element as adouble
.The default implementation calls
get(Class)
with argumentDouble.TYPE
.- 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, ApfloatRuntimeException
Sets the current element as anint
.The default implementation calls
set(Class,Object)
with first argumentInteger.TYPE
.- 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, ApfloatRuntimeException
Sets the current element as along
.The default implementation calls
set(Class,Object)
with first argumentLong.TYPE
.- 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, ApfloatRuntimeException
Sets the current element as afloat
.The default implementation calls
set(Class,Object)
with first argumentFloat.TYPE
.- 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, ApfloatRuntimeException
Sets the current element as adouble
.The default implementation calls
set(Class,Object)
with first argumentDouble.TYPE
.- 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
-
get
public <T> T get(java.lang.Class<T> type) throws java.lang.UnsupportedOperationException, java.lang.IllegalStateException, ApfloatRuntimeException
Gets the current element as a the specified element type.The default implementation always throws
UnsupportedOperationException
.- Type Parameters:
T
- The type of the element.- Parameters:
type
- The type of the element.- Returns:
- The current element as the specified type.
- Throws:
java.lang.UnsupportedOperationException
- If the element type of the data storage can't be converted to the specified type.java.lang.IllegalStateException
- If the iterator is at the end.ApfloatRuntimeException
- Since:
- 1.7.0
-
set
public <T> void set(java.lang.Class<T> type, T value) throws java.lang.UnsupportedOperationException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, ApfloatRuntimeException
Sets the current element as the specified element type.The default implementation always throws
UnsupportedOperationException
.- Type Parameters:
T
- The type of the element.- Parameters:
type
- The type of the element.value
- The value to be set to the current element as the specified type.- Throws:
java.lang.UnsupportedOperationException
- If the element type of the data storage can't be converted to the specified type.java.lang.IllegalArgumentException
- If the value is not of the specified type.java.lang.IllegalStateException
- If the iterator is at the end.ApfloatRuntimeException
- Since:
- 1.7.0
-
close
public void close() throws ApfloatRuntimeException
Closes the iterator. This needs to be called only if the iterator is not iterated to the end.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
ApfloatRuntimeException
-
-