public final class Collections extends Object
| Modifier and Type | Method and Description |
|---|---|
static <A,T extends Collection<A>,S extends Iterable<? extends A>> |
appendTo(T target,
S as)
Append source collection
as to target. |
static <A,T extends Collection<A>,X extends A> |
appendToA(T target,
X... as)
Append source collections
as to target. |
static <A,T extends Collection<A>,S extends Iterable<? extends A>> |
appendToM(T target,
S... as)
Append source collections
as to target. |
static <K,V> Map<K,V> |
asMap(List<V> values,
Function<V,K> keyGen)
Partition a list after some predicate
keyGen. |
static <K,V> Map<K,V> |
asMap(Map<K,V> map,
List<V> values,
Function<V,K> keyGen)
Partition a list after some predicate
keyGen into map. |
static <A> List<A> |
concat(List<? extends A> as,
List<? extends A> bs)
Concatenates two lists.
|
static <A,M extends Collection<? extends Collection<A>>> |
concat(M as)
Concat (aka flatten) a collection of collections by concatenating them all.
|
static <A,M extends Iterable<? extends A>> |
concat(M as,
M bs)
Concatenates two iterables into a new list.
|
static <A> List<A> |
cons(A a,
List<? extends A> as)
Construct a new list by prepending an element to a given list.
|
static <A> Function<List<A>,Function<A,Boolean>> |
containedIn()
Curried version of
List.contains(Object). |
static <A> Function<A,Boolean> |
containedIn(List<A> as)
Create a function that checks if its argument is contained in
as. |
static <K,V> Dictionary<K,V> |
dict(Tuple<? extends K,? extends V>... ts)
Create a dictionary from a list of tuples (K, V).
|
static <A,M extends Iterable<? extends A>> |
diff(M as,
M bs) |
static <A> boolean |
exists(Collection<A> as,
Predicate<A> p)
Deprecated.
use
Monadics |
static <A,M extends Collection<A>> |
filter(M as,
Predicate<A> p)
Deprecated.
use
Monadics |
static <A> Option<A> |
find(Collection<A> as,
Predicate<A> p)
Deprecated.
use
Monadics |
static <A,B> Collection<B> |
flatMap(Collection<A> as,
Function<A,Collection<B>> f)
Deprecated.
use
Monadics |
static <A,B,M extends Collection<B>> |
flatMap(Collection<A> as,
M bs,
Function<A,Collection<B>> f)
Deprecated.
use
Monadics |
static <A,B> Function<A[],List<B>> |
flatMapArrayToList(Function<A,List<B>> f) |
static <A,B> B |
foldl(Collection<A> as,
B start,
Function2<B,A,B> f)
Deprecated.
use
Monadics |
static <A> Iterable<A> |
forc(Iterator<A> as)
Make an Iterator usable in a for comprehension like this:
|
static <A,B> Function<A,Option<B>> |
getMap(Map<A,B> map)
Return a function to get data from a map.
|
static <K,V> V |
getOrCreate(Map<K,V> map,
K key,
Creator<V> c)
Get a value from a map, creating and adding a new one, if the value is missing, i.e.
|
static <K,V> V |
getOrCreate(Map<K,V> map,
K key,
Function0<V> f)
Get a value from a map, creating and adding a new one, if the value is missing, i.e.
|
static <A> Function<Option<A>,A> |
getOrElse(A a) |
static <K,V> com.google.common.collect.ImmutableMultimap<K,V> |
groupBy(Iterable<? extends V> values,
Function<? super V,? extends K> group)
Partition a list after some predicate
group into map. |
static <K,V> com.google.common.collect.Multimap<K,V> |
groupBy(com.google.common.collect.Multimap<K,V> map,
Iterable<? extends V> values,
Function<? super V,? extends K> group)
Partition a list after some predicate
group into map. |
static <A> List<List<A>> |
grouped(List<A> as,
int size)
Partition a list in chunks of size
size. |
static <A> Function<List<A>,Option<A>> |
head() |
static <A> Option<A> |
head(List<A> as)
Return the head of list
as or none. |
static <A> Iterator<A> |
iterator(A... as)
Create an iterator form an array.
|
static <A> Iterator<A> |
join(Iterator<A> a,
Iterator<A> b)
Join two iterators.
|
static <A> Option<A> |
last(A[] as)
Return the last element of the array.
|
static <A> Option<A> |
last(List<A> as)
Return the last element of the list.
|
static <A> List<A> |
list(A... as)
Create a list from an array.
|
static <K,V,X> com.google.common.collect.Multimap<K,V> |
makeMap(com.google.common.collect.Multimap<K,V> map,
Iterable<? extends X> values,
Function<? super X,Tuple<K,V>> group)
Partition a list after some predicate
group into map. |
static <A,B> Collection<B> |
map(Collection<A> as,
Function<A,B> f)
Deprecated.
use
Monadics |
static <A,B,M extends Collection<B>> |
map(Collection<A> as,
M bs,
Function<A,B> f)
Deprecated.
use
Monadics |
static <K,V> Map<K,V> |
map(Tuple<? extends K,? extends V>... ts)
Create a map from a list of tuples (K, V).
|
static <A,B> Map<A,B> |
merge(Map<? extends A,? extends B> a,
Map<? extends A,? extends B> b)
Merge two maps where
b takes precedence. |
static <A> Set<A> |
merge(Set<? extends A> a,
Set<? extends A> b)
Merge two sets into one.
|
static <A> List<A> |
mkList(List<A> as)
Deprecated.
|
static String |
mkString(Collection<?> as,
String sep)
Make a string from a collection separating each element by
sep. |
static <A> List<A> |
nil()
The empty list.
|
static <A> List<A> |
nil(Class<A> type)
The empty list.
|
static <A> List<A> |
nonNullList(A... as)
Create a list from an array.
|
static <A> List<A> |
nullToNil(List<A> as)
Return the list as is or nil, if
as is null. |
static <A> Function<Option<A>,Iterator<A>> |
optionToIterator()
Turn an option into an iterator.
|
static <A> Function<Option<A>,List<A>> |
optionToList() |
static Properties |
properties(Tuple<String,String>... ts)
Create properties from a list of tuples (K, V).
|
static <A,X extends A> |
repeat(X a,
int times)
Create an iterator that repeats
a for the said times. |
static <A> Set<A> |
set(A... as)
Create a set from an array.
|
static <K,V> SortedMap<K,V> |
smap(Tuple<? extends K,? extends V>... ts)
Create a sorted map from a list of tuples (K, V) based on the natural ordering of K.
|
static <A extends Comparable> |
sort()
Sort a list.
|
static <A,B extends A> |
toArray(Class<A> elemType,
Collection<B> a)
Create an array from a collection.
|
static double[] |
toDoubleArray(Collection<Double> as)
Convert a collection of
Doubles into an array of primitive type. |
static float[] |
toFloatArray(Collection<Float> as)
Convert a collection of
Floats into an array of primitive type. |
static int[] |
toIntArray(Collection<Integer> as)
Convert a collection of
Integers into an array of primitive type. |
static <A> List<A> |
toList(A a)
Return nil if
a is null or a list containing a otherwise. |
static <A> List<A> |
toList(Collection<A> as)
Drain all elements of
as into a list. |
static <A> List<A> |
toList(Iterator<? extends A> as)
Drain all elements of
as into a list. |
static <K,V> List<Tuple<K,V>> |
toList(Map<K,V> map)
Create a list of tuples (K, V) from a map.
|
static <K,V> Map<K,V> |
toList(Tuple<? extends K,? extends V>... ts) |
static Map<String,String> |
toMap(Properties p)
Convert a properties object into a typed immutable map.
|
static <A> Set<A> |
toSet(List<A> as)
Create a set from a list.
|
static <A,B> Collection<A> |
unique(List<A> as,
Function<A,B> criteria)
Create a list of unique elements determined by a given criteria.
|
public static <K,V> V getOrCreate(Map<K,V> map, K key, Creator<V> c)
c - creates the missing valuepublic static <K,V> V getOrCreate(Map<K,V> map, K key, Function0<V> f)
@Deprecated public static <A,B,M extends Collection<B>> M map(Collection<A> as, M bs, Function<A,B> f)
Monadicsf to all elements of collection as to produce a new collection
bs.
An (empty) instance of the target collection has to be provided explicitly.as - the source collectionbs - the (empty) target collectionf - the function to apply to each element of as@Deprecated public static <A,B> B foldl(Collection<A> as, B start, Function2<B,A,B> f)
Monadics@Deprecated public static <A,B> Collection<B> map(Collection<A> as, Function<A,B> f)
Monadicsf to all elements of collection as to produce a new collection
bs.
The type of collection as needs a parameterless constructor.
Please note that since java does not support higher-order polymorphism -- which is needed to capture the type of
the collection -- some casting on the client side may still be necessary.RuntimeException - if the target collection cannot be created@Deprecated public static <A,B> Collection<B> flatMap(Collection<A> as, Function<A,Collection<B>> f)
Monadicsf to all elements of collection as to produce a new collection
bs by concatenating the results.
The type of collection as needs a parameterless constructor.
Please note that since java does not support higher-order polymorphism -- which is needed to capture the type of
the collection -- some casting on the client side may still be necessary.RuntimeException - if the result collection cannot be created@Deprecated public static <A,B,M extends Collection<B>> M flatMap(Collection<A> as, M bs, Function<A,Collection<B>> f)
MonadicsflatMap(java.util.Collection, Function) but you have to provide the target collection
yourself.@Deprecated public static <A> Option<A> find(Collection<A> as, Predicate<A> p)
Monadicsas that satisfies a predicate p.@Deprecated public static <A> boolean exists(Collection<A> as, Predicate<A> p)
Monadicsas satisfies predicate p.@Deprecated public static <A,M extends Collection<A>> M filter(M as, Predicate<A> p)
Monadicsp.
The type of collection as needs a parameterless constructor.public static <A> Option<A> last(A[] as)
public static String mkString(Collection<?> as, String sep)
sep.public static <A,T extends Collection<A>,S extends Iterable<? extends A>> T appendTo(T target, S as)
as to target.@SafeVarargs public static <A,T extends Collection<A>,S extends Iterable<? extends A>> T appendToM(T target, S... as)
as to target.@SafeVarargs public static <A,T extends Collection<A>,X extends A> T appendToA(T target, X... as)
as to target.public static <A,M extends Iterable<? extends A>> List<A> concat(M as, M bs)
public static <A> List<A> concat(List<? extends A> as, List<? extends A> bs)
public static <A,B> Map<A,B> merge(Map<? extends A,? extends B> a, Map<? extends A,? extends B> b)
b takes precedence.public static <A> Set<A> merge(Set<? extends A> a, Set<? extends A> b)
b takes precedence over a.public static <A> List<A> toList(Iterator<? extends A> as)
as into a list.public static <K,V> List<Tuple<K,V>> toList(Map<K,V> map)
@SafeVarargs public static <K,V> Map<K,V> toList(Tuple<? extends K,? extends V>... ts)
public static <A> List<A> toList(Collection<A> as)
as into a list.public static <A> List<A> toList(A a)
a is null or a list containing a otherwise.@Deprecated public static <A> List<A> mkList(List<A> as)
nullToNil(java.util.List)as is null.public static <A> List<A> nullToNil(List<A> as)
as is null.@SafeVarargs public static <A> List<A> list(A... as)
@SafeVarargs public static <A> List<A> nonNullList(A... as)
public static <A> List<A> nil()
public static <A> List<A> cons(A a, List<? extends A> as)
@SafeVarargs public static <A> Set<A> set(A... as)
@SafeVarargs public static <K,V> Map<K,V> map(Tuple<? extends K,? extends V>... ts)
@SafeVarargs public static <K,V> SortedMap<K,V> smap(Tuple<? extends K,? extends V>... ts)
@SafeVarargs public static <K,V> Dictionary<K,V> dict(Tuple<? extends K,? extends V>... ts)
@SafeVarargs public static Properties properties(Tuple<String,String>... ts)
public static Map<String,String> toMap(Properties p)
public static <K,V> com.google.common.collect.Multimap<K,V> groupBy(com.google.common.collect.Multimap<K,V> map,
Iterable<? extends V> values,
Function<? super V,? extends K> group)
group into map.
Use e.g. ArrayListMultimap.create() to create a multimap.groupBy(Iterable, Function)public static <K,V> com.google.common.collect.ImmutableMultimap<K,V> groupBy(Iterable<? extends V> values, Function<? super V,? extends K> group)
group into map.ImmutableMultimapgroupBy(com.google.common.collect.Multimap, Iterable, Function)public static <K,V,X> com.google.common.collect.Multimap<K,V> makeMap(com.google.common.collect.Multimap<K,V> map,
Iterable<? extends X> values,
Function<? super X,Tuple<K,V>> group)
group into map.public static <A> List<List<A>> grouped(List<A> as, int size)
size. The last chunk may be smaller.public static <A,B> Collection<A> unique(List<A> as, Function<A,B> criteria)
public static <K,V> Map<K,V> asMap(List<V> values, Function<V,K> keyGen)
keyGen. The partition function has to make sure that keys are
unique per list element because each key holds only one value. Later values overwrite newer ones.
The resulting map is an immutable HashMap.public static <K,V> Map<K,V> asMap(Map<K,V> map, List<V> values, Function<V,K> keyGen)
keyGen into map. The partition function has to make
sure that keys are unique per list element because each key holds only one value. Later values overwrite newer
ones.asMap(java.util.List, Function)public static <A,B extends A> A[] toArray(Class<A> elemType, Collection<B> a)
public static double[] toDoubleArray(Collection<Double> as)
Doubles into an array of primitive type.public static float[] toFloatArray(Collection<Float> as)
Floats into an array of primitive type.public static int[] toIntArray(Collection<Integer> as)
Integers into an array of primitive type.@SafeVarargs public static <A> Iterator<A> iterator(A... as)
public static <A,X extends A> Iterator<A> repeat(X a, int times)
a for the said times.public static <A> Iterable<A> forc(Iterator<A> as)
Iterator<A> as = ...
for (A a : forc(as)) {
...
}
public static <A,B> Function<A[],List<B>> flatMapArrayToList(Function<A,List<B>> f)
public static <A> Function<Option<A>,Iterator<A>> optionToIterator()
public static <A extends Comparable> Function<List<A>,List<A>> sort()
public static <A> Function<A,Boolean> containedIn(List<A> as)
as.public static <A> Function<List<A>,Function<A,Boolean>> containedIn()
List.contains(Object).public static <A,M extends Collection<? extends Collection<A>>> List<A> concat(M as)
Copyright © 2009–2021 Opencast Project. All rights reserved.