Package org.apache.wayang.core.util
Class WayangCollections
- java.lang.Object
-
- org.apache.wayang.core.util.WayangCollections
-
public class WayangCollections extends java.lang.ObjectUtilities to operateCollections.
-
-
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 aCollectionand returns theCollection.static <T,C extends java.util.Collection<T>>
CaddAll(C collection, C elements)Adds elements to aCollectionand returns theCollection.static <T,C extends java.util.Collection<T>>
CasCollection(java.lang.Iterable<T> iterable, java.util.function.Supplier<C> collectionFactory)Provides the giveniterableasCollection.static <T> java.util.List<T>asList(java.util.Collection<T> collection)Provides the givencollectionasList, thereby checking if it is already aList.static <T> java.util.Set<T>asSet(java.lang.Iterable<T> iterable)Provides the giveniterableasSet, thereby checking if it is already aSet.static <T> java.util.Set<T>asSet(java.util.Collection<T> collection)Provides the givencollectionasSet, thereby checking if it is already aSet.static <T> java.util.Set<T>asSet(T... values)Provides the givenvaluesasSet.static <K,V>
java.util.Map<K,V>createMap(Tuple<K,V>... keyValuePairs)static <T> java.util.ArrayList<T>createNullFilledArrayList(int k)Creates anArrayListthat is filled withknulls.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> TgetAny(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 theiterableif it exists.static <T> TgetSingle(java.util.Collection<T> collection)Validate that there is only a single element in thecollectionand return it.static <T> TgetSingleOrNull(java.util.Collection<T> collection)Validate that there is at most one element in thecollectionand return it (ornullotherwise).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 newListwith mapped values.static <S,T>
java.util.List<T>map(java.util.List<S> list, java.util.function.Function<S,T> mapFunction)Return a newListwith 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 anIterablethat 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 givencollectionasSet, thereby checking if it is already aSet.
-
asSet
public static <T> java.util.Set<T> asSet(java.lang.Iterable<T> iterable)
Provides the giveniterableasSet, thereby checking if it is already aSet.
-
asSet
public static <T> java.util.Set<T> asSet(T... values)
Provides the givenvaluesasSet.
-
asList
public static <T> java.util.List<T> asList(java.util.Collection<T> collection)
Provides the givencollectionasList, 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 giveniterableasCollection.
-
getSingle
public static <T> T getSingle(java.util.Collection<T> collection)
Validate that there is only a single element in thecollectionand return it.
-
getSingleOrNull
public static <T> T getSingleOrNull(java.util.Collection<T> collection)
Validate that there is at most one element in thecollectionand return it (ornullotherwise).
-
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 theiterableif it exists.
-
add
public static <C extends java.util.Collection<T>,T> C add(C collection, T element)Adds an element to aCollectionand 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 aCollectionand 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 newListwith 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 newListwith mapped values.
-
streamedCrossProduct
public static <T> java.lang.Iterable<java.util.List<T>> streamedCrossProduct(java.util.List<? extends java.lang.Iterable<T>> iterables)
Returns anIterablethat 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 anArrayListthat is filled withknulls.
-
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 theLists in the power list
-
createMap
public static <K,V> java.util.Map<K,V> createMap(Tuple<K,V>... keyValuePairs)
-
-