public class ListSlidingWindows extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> Stream<List<T>> |
createClosedSlidingWindow(List<? extends T> input,
int windowSize,
int stepSize)
Create a stream that contains lists that are a sliding window over
the given input list.
|
static <T> Stream<List<T>> |
createSlidingWindow(List<? extends T> input,
int windowSize,
int start,
int maxEnd,
int stepSize)
Create a stream that contains lists that are a sliding window over
the given input list.
|
public static <T> Stream<List<T>> createClosedSlidingWindow(List<? extends T> input, int windowSize, int stepSize)
windowSize elements. If the window size is larger
than the input list, then the stream will be empty.
input : [0, 1, 2, 3, 4, 5, 6, 7 ]
output :
[0, 1, 2, 3, 4 ]
[2, 3, 4, 5, 6 ]
input : [0, 1, 2, 3, 4, 5, 6, 7, 8 ]
output :
[0, 1, 2, 3, 4 ]
[2, 3, 4, 5, 6 ]
[4, 5, 6, 7, 8 ]
T - The element typeinput - The input listwindowSize - The window sizestepSize - The step sizeIllegalArgumentException - If the window size or the step size
is not positivepublic static <T> Stream<List<T>> createSlidingWindow(List<? extends T> input, int windowSize, int start, int maxEnd, int stepSize)
[0, input.size()).start index of the given list. The last
window will contain no element that is located at an index of the input
list that is equal to or greater than the maxEnd index.start index that is smaller than -windowSize.
(The latter will simply cause the first lists to be empty.)
T - The element typeinput - The input listwindowSize - The window sizestart - The start index, inclusivemaxEnd - The maximum end index, exclusivestepSize - The step sizeIllegalArgumentException - If the window size or the step size
is not positiveCopyright © 2018. All rights reserved.