Package org.opencastproject.util.data
Class Collections
java.lang.Object
org.opencastproject.util.data.Collections
Deprecated.
By now, all of this is natively available in Java.
This class provides functions to ease and secure the handling of collections by supporting a type safe -- at least to
the extent Java's type system allows -- immutable and more functional style.
Note that all functions do not mutate input collections unless otherwise stated.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A,T extends Collection<A>, S extends Iterable<? extends A>>
TappendTo(T target, S as) Deprecated.Append source collectionastotarget.static <A,T extends Collection<A>, X extends A>
TappendToA(T target, X... as) Deprecated.Append source collectionsastotarget.static <A,T extends Collection<A>, S extends Iterable<? extends A>>
TappendToM(T target, S... as) Deprecated.Append source collectionsastotarget.static <A,M extends Collection<? extends Collection<A>>>
List<A> concat(M as) Deprecated.Concat (aka flatten) a collection of collections by concatenating them all.concat(M as, M bs) Deprecated.Concatenates two iterables into a new list.static <A> List<A> Deprecated.Construct a new list by prepending an element to a given list.static <K,V> Dictionary <K, V> Deprecated.Create a dictionary from a list of tuples (K, V).static <A,M extends Collection<A>>
MDeprecated.useMonadicsstatic <A> Iterable<A> Deprecated.Make an Iterator usable in a for comprehension like this:static <A> Option<A> Deprecated.Return the head of listasornone.static <A> Iterator<A> iterator(A... as) Deprecated.Create an iterator form an array.static <A> Iterator<A> Deprecated.Join two iterators.static <A> List<A> list(A... as) Deprecated.Create a list from an array.static <A,B, M extends Collection<B>>
Mmap(Collection<A> as, M bs, Function<A, B> f) Deprecated.useMonadicsstatic <A,B> Collection <B> map(Collection<A> as, Function<A, B> f) Deprecated.useMonadicsstatic <K,V> Map <K, V> Deprecated.Create a map from a list of tuples (K, V).static <A,B> Map <A, B> Deprecated.Merge two maps wherebtakes precedence.static <A> List<A> Deprecated.static StringmkString(Collection<?> as, String sep) Deprecated.Make a string from a collection separating each element bysep.static <A> List<A> nil()Deprecated.The empty list.static <A> List<A> Deprecated.The empty list.static <A> List<A> nonNullList(A... as) Deprecated.Create a list from an array.static <A> List<A> Deprecated.Return the list as is or nil, ifasis null.static <A,X extends A>
Iterator<A> repeat(X a, int times) Deprecated.Create an iterator that repeatsafor the said times.static <A> Set<A> set(A... as) Deprecated.Create a set from an array.static <A,B extends A>
A[]toArray(Class<A> elemType, Collection<B> a) Deprecated.Create an array from a collection.static double[]Deprecated.Convert a collection ofDoubles into an array of primitive type.static <A> List<A> toList(Collection<A> as) Deprecated.Drain all elements ofasinto a list.static <A> List<A> Deprecated.Drain all elements ofasinto a list.static <A> Set<A> Deprecated.Create a set from a list.
-
Method Details
-
map
@Deprecated public static <A,B, M mapM extends Collection<B>> (Collection<A> as, M bs, Function<A, B> f) Deprecated.useMonadicsApply a functionfto all elements of collectionasto produce a new collectionbs. An (empty) instance of the target collection has to be provided explicitly.- Parameters:
as- the source collectionbs- the (empty) target collectionf- the function to apply to each element ofas
-
map
Deprecated.useMonadicsApply a functionfto all elements of collectionasto produce a new collectionbs. The type of collectionasneeds 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.- Throws:
RuntimeException- if the target collection cannot be created
-
filter
Deprecated.useMonadicsReturn a new collection containing only the elements that satisfy predicatep. The type of collectionasneeds a parameterless constructor. -
head
Deprecated.Return the head of listasornone. -
mkString
Deprecated.Make a string from a collection separating each element bysep. -
appendTo
public static <A,T extends Collection<A>, T appendToS extends Iterable<? extends A>> (T target, S as) Deprecated.Append source collectionastotarget. -
appendToM
@SafeVarargs public static <A,T extends Collection<A>, T appendToMS extends Iterable<? extends A>> (T target, S... as) Deprecated.Append source collectionsastotarget. -
appendToA
Deprecated.Append source collectionsastotarget. -
concat
Deprecated.Concatenates two iterables into a new list. -
merge
Deprecated.Merge two maps wherebtakes precedence.- Returns:
- a new immutable map
-
toList
Deprecated.Drain all elements ofasinto a list. -
toList
Deprecated.Drain all elements ofasinto a list. -
mkList
Deprecated.Return the list as is or nil, ifasis null. -
nullToNil
Deprecated.Return the list as is or nil, ifasis null. -
list
Deprecated.Create a list from an array. -
nonNullList
Deprecated.Create a list from an array. -
nil
Deprecated.The empty list. -
nil
Deprecated.The empty list. -
cons
Deprecated.Construct a new list by prepending an element to a given list. -
set
Deprecated.Create a set from an array. -
toSet
Deprecated.Create a set from a list. -
map
Deprecated.Create a map from a list of tuples (K, V). -
dict
Deprecated.Create a dictionary from a list of tuples (K, V). -
toArray
Deprecated.Create an array from a collection. -
toDoubleArray
Deprecated.Convert a collection ofDoubles into an array of primitive type. -
iterator
Deprecated.Create an iterator form an array. -
repeat
Deprecated.Create an iterator that repeatsafor the said times. -
join
Deprecated.Join two iterators. -
forc
Deprecated.Make an Iterator usable in a for comprehension like this:Iterator<A> as = ... for (A a : forc(as)) { ... } -
concat
Deprecated.Concat (aka flatten) a collection of collections by concatenating them all. [[a]] -> [a]
-