Class LimitingFloatIterator

java.lang.Object
com.github.tommyettinger.ds.support.util.LimitingFloatIterator
All Implemented Interfaces:
FloatIterator, Iterator<Float>

public class LimitingFloatIterator extends Object implements FloatIterator
Wraps an Iterator so that it only returns at most a specific amount of items (defined by calls to nextFloat(). This can be useful to limit infinite Iterators so they only produce a finite amount of results. This has undefined behavior if any items the Iterator could return are modified during iteration.
You can change the Iterator and limit at once using set(FloatIterator, int), and can also just change the Iterator with set(FloatIterator).
  • Field Details

    • iterator

      public FloatIterator iterator
    • limit

      protected int limit
    • remaining

      protected int remaining
  • Constructor Details

    • LimitingFloatIterator

      public LimitingFloatIterator()
    • LimitingFloatIterator

      public LimitingFloatIterator(FloatIterator iterator, int limit)
  • Method Details

    • set

      public void set(FloatIterator iterator, int limit)
    • set

      public void set(FloatIterator iterator)
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<Float>
    • nextFloat

      public float nextFloat()
      Description copied from interface: FloatIterator
      Returns the next float element in the iteration.
      Specified by:
      nextFloat in interface FloatIterator
      Returns:
      the next float element in the iteration
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<Float>