public class ListUtils extends Object
Modifier and Type | Method and Description |
---|---|
static void |
addRange(Collection<Integer> c,
int start,
int to,
int step)
Adds values into the given collection using integer in the specified range and step size.
|
static <T> List<T> |
collectFutures(Collection<Future<T>> futures)
Collects all future values in a collection into a list, and returns said list.
|
static <T> List<T> |
mergedView(List<T> left,
List<T> right)
Returns a new unmodifiable view that is the merging of two lists
|
static <T> void |
randomSample(Collection<T> source,
Collection<T> dest,
int samples,
Random rand)
Obtains a random sample without replacement from a source collection and
places it in the destination collection.
|
static <T> void |
randomSample(List<T> source,
List<T> dest,
int samples)
Obtains a random sample without replacement from a source list and places
it in the destination list.
|
static <T> void |
randomSample(List<T> source,
List<T> dest,
int samples,
Random rand)
Obtains a random sample without replacement from a source list and places
it in the destination list.
|
static <T> List<List<T>> |
splitList(List<T> source,
int count)
This method takes a list and breaks it into count lists backed by the original
list, with elements being equally spaced among the lists.
|
static void |
swap(List list,
int i,
int j)
Swaps the values in the list at the given positions
|
public static <T> List<List<T>> splitList(List<T> source, int count)
List.subList(int, int)
,
changes to the returned lists will be reflected in the source list.T
- the type contained in the listsource
- the source list that will be used to back the count listscount
- the number of lists to partition the source into.public static <T> List<T> mergedView(List<T> left, List<T> right)
T
- the type the lists holdleft
- the left portion of the merged viewright
- the right portion of the merged viewpublic static void swap(List list, int i, int j)
list
- the list to perform the swap ini
- the first position to swapj
- the second position to swappublic static <T> List<T> collectFutures(Collection<Future<T>> futures) throws ExecutionException, InterruptedException
T
- the type of future objectfutures
- the collection of future objectsExecutionException
InterruptedException
public static void addRange(Collection<Integer> c, int start, int to, int step)
c
- the collection to add tostart
- the first value to add, inclusiveto
- the last value to add, exclusivestep
- the step size.RuntimeException
- if the step size is zero or negative.public static <T> void randomSample(List<T> source, List<T> dest, int samples, Random rand)
T
- the list content type involvedsource
- the source of values to randomly sample fromdest
- the list to store the random samples in. The list does not
need to be empty for the sampling to work correctlysamples
- the number of samples to select from the sourcerand
- the source of randomness for the samplingIllegalArgumentException
- if the sample size is not positive or l
arger than the source population.public static <T> void randomSample(Collection<T> source, Collection<T> dest, int samples, Random rand)
Set
T
- the list content type involvedsource
- the source of values to randomly sample fromdest
- the collection to store the random samples in. It does
not need to be empty for the sampling to work correctlysamples
- the number of samples to select from the sourcerand
- the source of randomness for the samplingIllegalArgumentException
- if the sample size is not positive or l
arger than the source population.public static <T> void randomSample(List<T> source, List<T> dest, int samples)
T
- the list content type involvedsource
- the source of values to randomly sample fromdest
- the list to store the random samples in. The list does not
need to be empty for the sampling to work correctlysamples
- the number of samples to select from the sourceIllegalArgumentException
- if the sample size is not positive or l
arger than the source population.Copyright © 2017. All rights reserved.