Class LimitingByteIterator

java.lang.Object
com.github.tommyettinger.ds.support.util.LimitingByteIterator
All Implemented Interfaces:
ByteIterator, Iterator<Byte>

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

    • iterator

      public ByteIterator iterator
    • limit

      protected int limit
    • remaining

      protected int remaining
  • Constructor Details

    • LimitingByteIterator

      public LimitingByteIterator()
    • LimitingByteIterator

      public LimitingByteIterator(ByteIterator iterator, int limit)
  • Method Details

    • set

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

      public void set(ByteIterator iterator)
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<Byte>
    • nextByte

      public byte nextByte()
      Description copied from interface: ByteIterator
      Returns the next byte element in the iteration.
      Specified by:
      nextByte in interface ByteIterator
      Returns:
      the next byte element in the iteration
    • remove

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