public class ListSplitting extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> List<T> |
extractChunk(List<? extends T> list,
int numChunks,
int chunkIndex)
Virtually splits the given list into the given number of chunks, and
returns an unmodifiable view on the chunk with the given index.
|
static <T> Stream<List<T>> |
extractChunks(List<T> list,
int numChunks)
Creates a stream that provides the given number of chunks from the
given list, in form of unmodifiable lists.
|
static <T> List<T> |
omitChunk(List<? extends T> list,
int numChunks,
int chunkIndex)
Virtually splits the given list into the given number of chunks, and
returns an unmodifiable view on the list, omitting the chunk
with the given index.
|
static <T> Stream<List<T>> |
omitChunks(List<T> list,
int numChunks)
Creates a stream that provides lists where chunks of the given list
are omitted, in form of unmodifiable lists.
|
public static <T> Stream<List<T>> extractChunks(List<T> list, int numChunks)
list = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
numChunks = 3
will create a stream that contains lists
[ 0, 1, 2, 3 ]
[ 4, 5, 6 ]
[ 7, 8, 9 ]
(This means that if the number of chunks is greater than the
size of the list, then the last chunks will be empty lists).T - The element typelist - The input listnumChunks - The number of chunksIllegalArgumentException - If the number of chunks is smaller
than 1public static <T> Stream<List<T>> omitChunks(List<T> list, int numChunks)
list = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
numChunks = 3
will create a stream that returns lists
[ _ _ _ _ 4, 5, 6, 7, 8, 9 ]
[ 0, 1, 2, 3, _ _ _ 7, 8, 9 ]
[ 0, 1, 2, 3, 4, 5, 6 _ _ _ ]
(This means that if the number of chunks is greater than the
size of the list, then the last elements will be the whole
input list!).T - The element typelist - The input listnumChunks - The number of chunksIllegalArgumentException - If the number of chunks is smaller
than 1public static <T> List<T> extractChunk(List<? extends T> list, int numChunks, int chunkIndex)
T - The type of the elementslist - the backing listnumChunks - The number of chunkschunkIndex - The index of the chunk to returnIllegalArgumentException - If the number of chunks is smaller
than 1, or the chunk index is negative or not smaller than the number
of chunkspublic static <T> List<T> omitChunk(List<? extends T> list, int numChunks, int chunkIndex)
T - The type of the elementslist - the backing listnumChunks - The number of chunkschunkIndex - The index of the chunk to returnIllegalArgumentException - If the number of chunks is smaller
than 1, or the chunk index is negative or not smaller than the number
of chunksCopyright © 2018. All rights reserved.