Klasse WindowIterator<T>

java.lang.Object
de.erichseifert.gral.util.WindowIterator<T>
Typparameter:
T - Type of the values.
Alle implementierten Schnittstellen:
Iterator<List<T>>

public class WindowIterator<T> extends Object implements Iterator<List<T>>

An iterator that turns a sequence of values into a sequence of overlapping windows. Each call of next() shifts the window by one value and returns a new list of the current contents.

Iterator<List<Integer>> windows =
    new WindowIterator<>(Arrays.asList(1, 2, 3, 4).iterator(), 2);
// yields [1, 2], then [2, 3], then [3, 4]

There is no padding at the ends: m input values and a window of n produce m − n + 1 windows, and no window at all if the source is shorter than n. This is what the window-based filters in de.erichseifert.gral.data.filters are built on.

Each returned list is a fresh copy, so it may be kept and modified. As with ConcatenationIterator, remove() is a no-op for backwards compatibility rather than an exception.

  • Konstruktordetails

    • WindowIterator

      public WindowIterator(Iterator<T> iterator, int windowSize)
      Initializes a new instance that returns sliding windows of the specified size. If the source iterator provides fewer values than the window size, no window can be built and the new instance is empty.
      Parameter:
      iterator - Source iterator.
      windowSize - Number of values in a window.
  • Methodendetails

    • hasNext

      public boolean hasNext()
      Angegeben von:
      hasNext in Schnittstelle Iterator<T>
    • next

      public List<T> next()
      Angegeben von:
      next in Schnittstelle Iterator<T>
    • remove

      public void remove()
      Does nothing. See the class documentation for why this is not an UnsupportedOperationException.
      Angegeben von:
      remove in Schnittstelle Iterator<T>