Class LimitingShortIterator

java.lang.Object
com.github.tommyettinger.ds.support.util.LimitingShortIterator
All Implemented Interfaces:
ShortIterator, Iterator<Short>

public class LimitingShortIterator extends Object implements ShortIterator
Wraps an Iterator so that it only returns at most a specific amount of items (defined by calls to nextShort(). 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(ShortIterator, int), and can also just change the Iterator with set(ShortIterator).
  • Field Details

    • iterator

      public ShortIterator iterator
    • limit

      protected int limit
    • remaining

      protected int remaining
  • Constructor Details

    • LimitingShortIterator

      public LimitingShortIterator()
    • LimitingShortIterator

      public LimitingShortIterator(ShortIterator iterator, int limit)
  • Method Details

    • set

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

      public void set(ShortIterator iterator)
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<Short>
    • nextShort

      public short nextShort()
      Description copied from interface: ShortIterator
      Returns the next short element in the iteration.
      Specified by:
      nextShort in interface ShortIterator
      Returns:
      the next short element in the iteration
    • remove

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