# Class DataStorage.Iterator

java.lang.Object
org.apfloat.spi.DataStorage.Iterator

All Implemented Interfaces:
  `Serializable, AutoCloseable`

Direct Known Subclasses:
  `DataStorage.AbstractIterator`

Enclosing class:
  `DataStorage`

public abstract static class DataStorage.Iterator extends Object implements Serializable, AutoCloseable
Iterator for iterating through elements of the data storage.

Version:
  1.15.0
Author:
  Mikko Tommila
See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `Iterator()`
  Default constructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  Closes the iterator.
  `<T> T`
  `get(Class<T> type)`
  Gets the current element as a the specified element type.
  `double`
  `getDouble()`
  Gets the current element as a `double`.
  `float`
  `getFloat()`
  Gets the current element as a `float`.
  `int`
  `getInt()`
  Gets the current element as an `int`.
  `long`
  `getLong()`
  Gets the current element as a `long`.
  `boolean`
  `hasNext()`
  Check if `next()` 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(Class<T> type, T value)`
  Sets the current element as the specified element type.
  `void`
  `setDouble(double value)`
  Sets the current element as a `double`.
  `void`
  `setFloat(float value)`
  Sets the current element as a `float`.
  `void`
  `setInt(int value)`
  Sets the current element as an `int`.
  `void`
  `setLong(long value)`
  Sets the current element as a `long`.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Iterator

    protected Iterator()
    Default constructor. Can be used e.g. for simple anonymous subclasses.

- ## Method Details

  - ### hasNext

    public boolean hasNext()
    Check if `next()` 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 is `next()` is called `startPosition - endPosition` times. The `get()` or `set()` methods should not be called for the last element.

    The default implementation always returns `false`.

    Returns:
      `true` if `next()` can be called, otherwise `false`.

  - ### next

    public void next() throws 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 called `startPosition - endPosition` times. The `get()` or `set()` methods should not be called for the last element.

    The default implementation always throws `IllegalStateException`.

    Throws:
      `IllegalStateException` - If the iterator has been iterated to the end already.
      `ApfloatRuntimeException`

  - ### getInt

    public int getInt() throws UnsupportedOperationException, IllegalStateException, ApfloatRuntimeException
    Gets the current element as an `int`.

    The default implementation calls `get(Class)` with argument `Integer.TYPE`.

    Returns:
      The current element as an `int`.
    Throws:
      `UnsupportedOperationException` - If the element type of the data storage can't be converted to an `int`.
      `IllegalStateException` - If the iterator is at the end.
      `ApfloatRuntimeException`

  - ### getLong

    public long getLong() throws UnsupportedOperationException, IllegalStateException, ApfloatRuntimeException
    Gets the current element as a `long`.

    The default implementation calls `get(Class)` with argument `Long.TYPE`.

    Returns:
      The current element as a `long`.
    Throws:
      `UnsupportedOperationException` - If the element type of the data storage can't be converted to a `long`.
      `IllegalStateException` - If the iterator is at the end.
      `ApfloatRuntimeException`

  - ### getFloat

    public float getFloat() throws UnsupportedOperationException, IllegalStateException, ApfloatRuntimeException
    Gets the current element as a `float`.

    The default implementation calls `get(Class)` with argument `Float.TYPE`.

    Returns:
      The current element as a `float`.
    Throws:
      `UnsupportedOperationException` - If the element type of the data storage can't be converted to a `float`.
      `IllegalStateException` - If the iterator is at the end.
      `ApfloatRuntimeException`

  - ### getDouble

    public double getDouble() throws UnsupportedOperationException, IllegalStateException, ApfloatRuntimeException
    Gets the current element as a `double`.

    The default implementation calls `get(Class)` with argument `Double.TYPE`.

    Returns:
      The current element as a `double`.
    Throws:
      `UnsupportedOperationException` - If the element type of the data storage can't be converted to a `double`.
      `IllegalStateException` - If the iterator is at the end.
      `ApfloatRuntimeException`

  - ### setInt

    public void setInt(int value) throws UnsupportedOperationException, IllegalStateException, ApfloatRuntimeException
    Sets the current element as an `int`.

    The default implementation calls `set(Class,Object)` with first argument `Integer.TYPE`.

    Parameters:
      `value` - The value to be set to the current element as an `int`.
    Throws:
      `UnsupportedOperationException` - If the element type of the data storage can't be converted to an `int`.
      `IllegalStateException` - If the iterator is at the end.
      `ApfloatRuntimeException`

  - ### setLong

    public void setLong(long value) throws UnsupportedOperationException, IllegalStateException, ApfloatRuntimeException
    Sets the current element as a `long`.

    The default implementation calls `set(Class,Object)` with first argument `Long.TYPE`.

    Parameters:
      `value` - The value to be set to the current element as a `long`.
    Throws:
      `UnsupportedOperationException` - If the element type of the data storage can't be converted to a `long`.
      `IllegalStateException` - If the iterator is at the end.
      `ApfloatRuntimeException`

  - ### setFloat

    public void setFloat(float value) throws UnsupportedOperationException, IllegalStateException, ApfloatRuntimeException
    Sets the current element as a `float`.

    The default implementation calls `set(Class,Object)` with first argument `Float.TYPE`.

    Parameters:
      `value` - The value to be set to the current element as a `float`.
    Throws:
      `UnsupportedOperationException` - If the element type of the data storage can't be converted to a `float`.
      `IllegalStateException` - If the iterator is at the end.
      `ApfloatRuntimeException`

  - ### setDouble

    public void setDouble(double value) throws UnsupportedOperationException, IllegalStateException, ApfloatRuntimeException
    Sets the current element as a `double`.

    The default implementation calls `set(Class,Object)` with first argument `Double.TYPE`.

    Parameters:
      `value` - The value to be set to the current element as a `double`.
    Throws:
      `UnsupportedOperationException` - If the element type of the data storage can't be converted to a `double`.
      `IllegalStateException` - If the iterator is at the end.
      `ApfloatRuntimeException`

  - ### get

    public <T> T get(Class<T> type) throws UnsupportedOperationException, 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:
      `UnsupportedOperationException` - If the element type of the data storage can't be converted to the specified type.
      `IllegalStateException` - If the iterator is at the end.
      `ApfloatRuntimeException`
    Since:
      1.7.0

  - ### set

    public <T> void set(Class<T> type, T value) throws UnsupportedOperationException, IllegalArgumentException, 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:
      `UnsupportedOperationException` - If the element type of the data storage can't be converted to the specified type.
      `IllegalArgumentException` - If the value is not of the specified type.
      `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 interface `AutoCloseable`
    Throws:
      `ApfloatRuntimeException`