public class Collections2 extends Object
Constructor and Description |
---|
Collections2() |
Modifier and Type | Method and Description |
---|---|
static <S extends Number,T extends Number> |
addAsInteger(List<T> a,
List<S> b)
adds b to a: a[i] += b[i]
Afterwards a has the size of max(a.size(),b.size()) |
static void |
fill(List in,
Object fill) |
static <T> T |
get(Collection<T> collection,
int i)
Gets the specific indexed element.
|
static int |
indexOf(List list,
Object o) |
static <T> String |
join(Collection<T> c,
Formatter<T> f,
String glue) |
static String |
join(Collection c,
Character glue) |
static String |
join(Collection c,
String glue) |
static String |
joinToString(List in,
String glue) |
static <T> T |
last(Collection<T> collection)
returns the last element of the collection.
|
static <T> T |
last(List<T> list)
returns the last element of the list.
|
static int |
max(Collection<? extends Comparable> in)
Find and return the index with the greatest value.
|
static <T> int |
max(Collection<T> in,
Comparator<T> comparator)
Find and return the index with the greatest value.
|
static <T extends Comparable> |
maxValue(Collection<T> in)
Find and return the object the is the max value
|
static double |
mean(Collection<? extends Number> list)
calculates the mean of all elements in the list
|
static int |
min(Collection<? extends Comparable> in)
Find and return the index with the smallest value.
|
static <T> int |
min(Collection<T> in,
Comparator<T> comparator)
Find and return the index with the greatest value.
|
static <T extends Comparable> |
minValue(Collection<T> in)
Find and return the object the is the max value
|
static <T> List<T> |
randomSample(Collection<T> in,
double ratio) |
static <T> List<T> |
randomSample(Collection<T> in,
double ratio,
Random rnd)
returns a random sample from the input list
|
static <T> List<T> |
randomSample(Collection<T> in,
int size)
returns a random sample from the input list
|
static <T> List<T> |
randomSample(Collection<T> in,
int size,
Random rnd)
returns a random sample from the input list
|
static double |
sum(Collection<? extends Number> list)
calculates the sum of all values in the list
|
static void |
trimToSize(Collection in,
int size) |
static <T> List<T> |
unique(Collection<T> src)
Returns a new List with unique elements from the source list.
|
static double |
variance(Collection<? extends Number> list)
calculates the variance of the elements in the list
|
public static <T> List<T> randomSample(Collection<T> in, int size)
T
- in
- source listsize
- size of sampleNullPointerException
- if in = nullIllegalArgumentException
- if size > in.size()public static <T> List<T> randomSample(Collection<T> in, double ratio)
public static <T> List<T> randomSample(Collection<T> in, double ratio, Random rnd)
T
- in
- source listratio
- percentage of returned elements = Math.round(in.size() * ratiornd
- random seedNullPointerException
- if in = nullIllegalArgumentException
- if ratio <= 0 || ratio > 1public static <T> List<T> randomSample(Collection<T> in, int size, Random rnd)
T
- in
- source listsize
- size of sampleNullPointerException
- if in = nullIllegalArgumentException
- if size > in.size()public static void trimToSize(Collection in, int size)
public static <T> List<T> unique(Collection<T> src)
src
- public static int max(Collection<? extends Comparable> in)
in
- the collection of objectspublic static <T extends Comparable> T maxValue(Collection<T> in)
T
- in
- max(java.util.Collection)
public static <T> int max(Collection<T> in, Comparator<T> comparator)
in
- the collection of objectscomparator
- which does the comparisonspublic static int min(Collection<? extends Comparable> in)
a
- public static <T extends Comparable> T minValue(Collection<T> in)
T
- in
- max(java.util.Collection)
public static <T> int min(Collection<T> in, Comparator<T> comparator)
in
- the collection of objectscomparator
- which does the comparisonspublic static double sum(Collection<? extends Number> list)
list
- public static double mean(Collection<? extends Number> list)
list
- public static double variance(Collection<? extends Number> list)
list
- public static <T> String join(Collection<T> c, Formatter<T> f, String glue)
public static String join(Collection c, Character glue)
public static String join(Collection c, String glue)
public static <S extends Number,T extends Number> void addAsInteger(List<T> a, List<S> b)
a
- b
- public static <T> T last(List<T> list)
T
- list
- public static <T> T last(Collection<T> collection)
T
- list
- public static <T> T get(Collection<T> collection, int i)
T
- collection
- i
- Copyright © 2013. All Rights Reserved.