Class DataStorage.AbstractIterator

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractIterator​(int mode, long startPosition, long endPosition)
      Construct a new iterator.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void checkGet()
      Checks if any of the get() methods can be called.
      protected void checkLength()
      Checks if the iterator is at the end yet.
      protected void checkSet()
      Checks if any of the set() methods can be called.
      double getDouble()
      Gets the current element as a double.
      float getFloat()
      Gets the current element as a float.
      protected int getIncrement()
      Returns the increment of the iterator.
      int getInt()
      Gets the current element as an int.
      protected long getLength()
      Returns the remaining length in the iterator.
      long getLong()
      Gets the current element as a long.
      protected int getMode()
      Returns the mode in which the iterator was created.
      protected long getPosition()
      Returns the current position of the iterator.
      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.
      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 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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,
                                   ApfloatRuntimeException
        Construct a new iterator. Elements can be iterated either in forward or in reverse order, depending on if startPosition is less than or greater than endPosition, 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 is startPosition - 1.
        endPosition - End position of iterator in the data set. For forward access, the last accessible element in the iterator is endPosition - 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 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.

        Overrides:
        hasNext in class DataStorage.Iterator
        Returns:
        true if next() can be called, otherwise false.
      • 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 called startPosition - endPosition times. The get() or set() methods should not be called for the last element.

        Overrides:
        next in class DataStorage.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,
                          ApfloatRuntimeException
        Description copied from class: DataStorage.Iterator
        Gets the current element as an int.

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

        Overrides:
        getInt in class DataStorage.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 an int.
        java.lang.IllegalStateException - If the iterator is at the end.
        ApfloatRuntimeException
      • getFloat

        public float getFloat()
                       throws java.lang.UnsupportedOperationException,
                              java.lang.IllegalStateException,
                              ApfloatRuntimeException
        Description copied from class: DataStorage.Iterator
        Gets the current element as a float.

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

        Overrides:
        getFloat in class DataStorage.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 a float.
        java.lang.IllegalStateException - If the iterator is at the end.
        ApfloatRuntimeException
      • getDouble

        public double getDouble()
                         throws java.lang.UnsupportedOperationException,
                                java.lang.IllegalStateException,
                                ApfloatRuntimeException
        Description copied from class: DataStorage.Iterator
        Gets the current element as a double.

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

        Overrides:
        getDouble in class DataStorage.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 a double.
        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
        Description copied from class: DataStorage.Iterator
        Sets the current element as an int.

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

        Overrides:
        setInt in class DataStorage.Iterator
        Parameters:
        value - The value to be set to the current element as an int.
        Throws:
        java.lang.UnsupportedOperationException - If the element type of the data storage can't be converted to an int.
        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
        Description copied from class: DataStorage.Iterator
        Sets the current element as a long.

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

        Overrides:
        setLong in class DataStorage.Iterator
        Parameters:
        value - The value to be set to the current element as a long.
        Throws:
        java.lang.UnsupportedOperationException - If the element type of the data storage can't be converted to a long.
        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
        Description copied from class: DataStorage.Iterator
        Sets the current element as a float.

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

        Overrides:
        setFloat in class DataStorage.Iterator
        Parameters:
        value - The value to be set to the current element as a float.
        Throws:
        java.lang.UnsupportedOperationException - If the element type of the data storage can't be converted to a float.
        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
        Description copied from class: DataStorage.Iterator
        Sets the current element as a double.

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

        Overrides:
        setDouble in class DataStorage.Iterator
        Parameters:
        value - The value to be set to the current element as a double.
        Throws:
        java.lang.UnsupportedOperationException - If the element type of the data storage can't be converted to a double.
        java.lang.IllegalStateException - If the iterator is at the end.
        ApfloatRuntimeException
      • checkGet

        protected void checkGet()
                         throws java.lang.IllegalStateException
        Checks if any of the get() 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.IllegalStateException
        Checks if any of the set() 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.IllegalStateException
        Checks 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.