Package org.apache.wayang.core.util
Class WayangCollections
- java.lang.Object
-
- org.apache.wayang.core.util.WayangCollections
-
public class WayangCollections extends java.lang.Object
Utilities to operateCollection
s.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <C extends java.util.Collection<T>,T>
Cadd(C collection, T element)
Adds an element to aCollection
and returns theCollection
.static <T,C extends java.util.Collection<T>>
CaddAll(C collection, C elements)
Adds elements to aCollection
and returns theCollection
.static <T,C extends java.util.Collection<T>>
CasCollection(java.lang.Iterable<T> iterable, java.util.function.Supplier<C> collectionFactory)
Provides the giveniterable
asCollection
.static <T> java.util.List<T>
asList(java.util.Collection<T> collection)
Provides the givencollection
asList
, thereby checking if it is already aList
.static <T> java.util.Set<T>
asSet(java.lang.Iterable<T> iterable)
Provides the giveniterable
asSet
, thereby checking if it is already aSet
.static <T> java.util.Set<T>
asSet(java.util.Collection<T> collection)
Provides the givencollection
asSet
, thereby checking if it is already aSet
.static <T> java.util.Set<T>
asSet(T... values)
Provides the givenvalues
asSet
.static <K,V>
java.util.Map<K,V>createMap(Tuple<K,V>... keyValuePairs)
static <T> java.util.ArrayList<T>
createNullFilledArrayList(int k)
Creates anArrayList
that is filled withk
null
s.static <T> java.util.Collection<java.util.List<T>>
createPowerList(java.util.Collection<T> base)
Creates the power list of the givenbase
(akin to power sets of sets).static <T> java.util.Collection<java.util.List<T>>
createPowerList(java.util.Collection<T> base, int maxElements)
Creates the power list of the givenbase
(akin to power sets of sets).static <T> T
getAny(java.lang.Iterable<T> iterable)
Return any element from theiterable
.static <T> java.util.Optional<T>
getAnyOptional(java.lang.Iterable<T> iterable)
Return any element from theiterable
if it exists.static <T> T
getSingle(java.util.Collection<T> collection)
Validate that there is only a single element in thecollection
and return it.static <T> T
getSingleOrNull(java.util.Collection<T> collection)
Validate that there is at most one element in thecollection
and return it (ornull
otherwise).static <S,T>
java.util.List<T>map(java.util.List<S> list, java.util.function.BiFunction<java.lang.Integer,S,T> mapFunction)
Return a newList
with mapped values.static <S,T>
java.util.List<T>map(java.util.List<S> list, java.util.function.Function<S,T> mapFunction)
Return a newList
with mapped values.static <K,V>
voidput(java.util.Map<K,java.util.Collection<V>> map, K key, V value)
static <T> java.lang.Iterable<java.util.List<T>>
streamedCrossProduct(java.util.List<? extends java.lang.Iterable<T>> iterables)
Returns anIterable
that iterates the cross product of the giveniterables
.
-
-
-
Method Detail
-
put
public static <K,V> void put(java.util.Map<K,java.util.Collection<V>> map, K key, V value)
-
asSet
public static <T> java.util.Set<T> asSet(java.util.Collection<T> collection)
Provides the givencollection
asSet
, thereby checking if it is already aSet
.
-
asSet
public static <T> java.util.Set<T> asSet(java.lang.Iterable<T> iterable)
Provides the giveniterable
asSet
, thereby checking if it is already aSet
.
-
asSet
public static <T> java.util.Set<T> asSet(T... values)
Provides the givenvalues
asSet
.
-
asList
public static <T> java.util.List<T> asList(java.util.Collection<T> collection)
Provides the givencollection
asList
, thereby checking if it is already aList
.
-
asCollection
public static <T,C extends java.util.Collection<T>> C asCollection(java.lang.Iterable<T> iterable, java.util.function.Supplier<C> collectionFactory)
Provides the giveniterable
asCollection
.
-
getSingle
public static <T> T getSingle(java.util.Collection<T> collection)
Validate that there is only a single element in thecollection
and return it.
-
getSingleOrNull
public static <T> T getSingleOrNull(java.util.Collection<T> collection)
Validate that there is at most one element in thecollection
and return it (ornull
otherwise).
-
getAny
public static <T> T getAny(java.lang.Iterable<T> iterable)
Return any element from theiterable
.
-
getAnyOptional
public static <T> java.util.Optional<T> getAnyOptional(java.lang.Iterable<T> iterable)
Return any element from theiterable
if it exists.
-
add
public static <C extends java.util.Collection<T>,T> C add(C collection, T element)
Adds an element to aCollection
and returns theCollection
.- Parameters:
collection
- to which the element should be addedelement
- that should be added to thecollection
- Returns:
- the
collection
-
addAll
public static <T,C extends java.util.Collection<T>> C addAll(C collection, C elements)
Adds elements to aCollection
and returns theCollection
.- Parameters:
collection
- to which the element should be addedelements
- that should be added to thecollection
- Returns:
- the
collection
-
map
public static <S,T> java.util.List<T> map(java.util.List<S> list, java.util.function.Function<S,T> mapFunction)
Return a newList
with mapped values.
-
map
public static <S,T> java.util.List<T> map(java.util.List<S> list, java.util.function.BiFunction<java.lang.Integer,S,T> mapFunction)
Return a newList
with mapped values.
-
streamedCrossProduct
public static <T> java.lang.Iterable<java.util.List<T>> streamedCrossProduct(java.util.List<? extends java.lang.Iterable<T>> iterables)
Returns anIterable
that iterates the cross product of the giveniterables
.- Parameters:
iterables
- should be iterable multiple times
-
createNullFilledArrayList
public static <T> java.util.ArrayList<T> createNullFilledArrayList(int k)
Creates anArrayList
that is filled withk
null
s.
-
createPowerList
public static <T> java.util.Collection<java.util.List<T>> createPowerList(java.util.Collection<T> base)
Creates the power list of the givenbase
(akin to power sets of sets).
-
createPowerList
public static <T> java.util.Collection<java.util.List<T>> createPowerList(java.util.Collection<T> base, int maxElements)
Creates the power list of the givenbase
(akin to power sets of sets).- Parameters:
maxElements
- maximum number of elements in theList
s in the power list
-
createMap
public static <K,V> java.util.Map<K,V> createMap(Tuple<K,V>... keyValuePairs)
-
-