Class LimitingCharIterator

java.lang.Object
com.github.tommyettinger.ds.support.util.LimitingCharIterator
All Implemented Interfaces:
CharIterator, Iterator<Character>

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

    • iterator

      public CharIterator iterator
    • limit

      protected int limit
    • remaining

      protected int remaining
  • Constructor Details

    • LimitingCharIterator

      public LimitingCharIterator()
    • LimitingCharIterator

      public LimitingCharIterator(CharIterator iterator, int limit)
  • Method Details