Class Sliced<T>

  • Type Parameters:
    T - The type of the iterator.
    All Implemented Interfaces:
    Iterator<T>

    public final class Sliced<T>
    extends Object
    implements Iterator<T>
    Creates an iterator returning an interval(slice) of the original iterator by means of providing starting index, number of elements to retrieve from the starting index and a decorated original iterator. Can be used to retrieve the head, tail or a portion in the middle of the original iterator.

    There is no thread-safety guarantee.

    Since:
    1.0.0
    • Constructor Detail

      • Sliced

        public Sliced​(int start,
                      int count,
                      Iterator<? extends T> iterator)
        Constructor.
        Parameters:
        start - Starting index
        count - Maximum number of elements for resulted iterator
        iterator - Decorated iterator
      • Sliced

        public Sliced​(int start,
                      Iterator<? extends T> iterator)
        Constructor. Constructs an iterator of start position and up to the end
        Parameters:
        start - Starting index
        iterator - Decorated iterator
    • Method Detail

      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface Iterator<T>
      • next

        public T next()
        Specified by:
        next in interface Iterator<T>