Package org.apache.wayang.core.util
Class WayangCollections
java.lang.Object
org.apache.wayang.core.util.WayangCollections
Utilities to operate
Collection
s.-
Method Summary
Modifier and TypeMethodDescriptionstatic <C extends Collection<T>,
T>
Cadd
(C collection, T element) Adds an element to aCollection
and returns theCollection
.static <T,
C extends Collection<T>>
CaddAll
(C collection, C elements) Adds elements to aCollection
and returns theCollection
.static <T,
C extends Collection<T>>
CasCollection
(Iterable<T> iterable, Supplier<C> collectionFactory) Provides the giveniterable
asCollection
.static <T> List<T>
asList
(Collection<T> collection) static <T> Set<T>
static <T> Set<T>
asSet
(Collection<T> collection) static <T> Set<T>
asSet
(T... values) Provides the givenvalues
asSet
.static <K,
V> Map<K, V> static <T> ArrayList<T>
createNullFilledArrayList
(int k) static <T> Collection<List<T>>
createPowerList
(Collection<T> base) Creates the power list of the givenbase
(akin to power sets of sets).static <T> Collection<List<T>>
createPowerList
(Collection<T> base, int maxElements) Creates the power list of the givenbase
(akin to power sets of sets).static <T> T
Return any element from theiterable
.static <T> Optional<T>
getAnyOptional
(Iterable<T> iterable) Return any element from theiterable
if it exists.static <T> T
getSingle
(Collection<T> collection) Validate that there is only a single element in thecollection
and return it.static <T> T
getSingleOrNull
(Collection<T> collection) Validate that there is at most one element in thecollection
and return it (ornull
otherwise).static <S,
T> List<T> map
(List<S> list, BiFunction<Integer, S, T> mapFunction) Return a newList
with mapped values.static <S,
T> List<T> Return a newList
with mapped values.static <K,
V> void put
(Map<K, Collection<V>> map, K key, V value) streamedCrossProduct
(List<? extends Iterable<T>> iterables) Returns anIterable
that iterates the cross product of the giveniterables
.
-
Method Details
-
put
-
asSet
-
asSet
-
asSet
Provides the givenvalues
asSet
. -
asList
-
asCollection
public static <T,C extends Collection<T>> C asCollection(Iterable<T> iterable, Supplier<C> collectionFactory) Provides the giveniterable
asCollection
. -
getSingle
Validate that there is only a single element in thecollection
and return it. -
getSingleOrNull
Validate that there is at most one element in thecollection
and return it (ornull
otherwise). -
getAny
Return any element from theiterable
. -
getAnyOptional
Return any element from theiterable
if it exists. -
add
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
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
Return a newList
with mapped values. -
map
Return a newList
with mapped values. -
streamedCrossProduct
Returns anIterable
that iterates the cross product of the giveniterables
.- Parameters:
iterables
- should be iterable multiple times
-
createNullFilledArrayList
-
createPowerList
Creates the power list of the givenbase
(akin to power sets of sets). -
createPowerList
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
-