Class StridingDoubleIterator

java.lang.Object
com.github.tommyettinger.ds.support.util.StridingDoubleIterator
All Implemented Interfaces:
DoubleIterator, Iterator<Double>

public class StridingDoubleIterator extends Object implements DoubleIterator
Wraps a DoubleIterator so that it starts at an offset, skipping that many items, then returning items that match a given stride, such as every other item, or every tenth item. If the offset is 0, this will try to return the first item and then any items matching the stride, so if the stride is 2, it will return the first item, skip one item, return the item after that, skip, return, skip, return, etc. This has undefined behavior if any items the DoubleIterator could return are modified during iteration.
You can change the iterator, offset, and stride at once using set(DoubleIterator, int, int), and can also just change the iterator with set(DoubleIterator).
  • Field Details

    • iterator

      public DoubleIterator iterator
    • offset

      protected int offset
    • stride

      protected int stride
    • index

      protected int index
    • end

      protected boolean end
    • available

      protected boolean available
    • next

      protected double next
  • Constructor Details

    • StridingDoubleIterator

      public StridingDoubleIterator()
    • StridingDoubleIterator

      public StridingDoubleIterator(DoubleIterator iterator, int offset, int stride)
  • Method Details

    • set

      public void set(DoubleIterator iterator, int offset, int stride)
    • set

      public void set(DoubleIterator iterator)
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<Double>
    • nextDouble

      public double nextDouble()
      Description copied from interface: DoubleIterator
      Returns the next double element in the iteration.
      Specified by:
      nextDouble in interface DoubleIterator
      Returns:
      the next double element in the iteration
    • remove

      public void remove()
      NOTE: this does not change the stride or offset, so the same sequence of values will be returned regardless of if some elements are removed with this method.
      Specified by:
      remove in interface Iterator<Double>