Class WayangCollections

java.lang.Object
org.apache.wayang.core.util.WayangCollections

public class WayangCollections extends Object
Utilities to operate Collections.
  • Method Details

    • put

      public static <K, V> void put(Map<K,Collection<V>> map, K key, V value)
    • asSet

      public static <T> Set<T> asSet(Collection<T> collection)
      Provides the given collection as Set, thereby checking if it is already a Set.
    • asSet

      public static <T> Set<T> asSet(Iterable<T> iterable)
      Provides the given iterable as Set, thereby checking if it is already a Set.
    • asSet

      public static <T> Set<T> asSet(T... values)
      Provides the given values as Set.
    • asList

      public static <T> List<T> asList(Collection<T> collection)
      Provides the given collection as List, thereby checking if it is already a List.
    • asCollection

      public static <T, C extends Collection<T>> C asCollection(Iterable<T> iterable, Supplier<C> collectionFactory)
      Provides the given iterable as Collection.
    • getSingle

      public static <T> T getSingle(Collection<T> collection)
      Validate that there is only a single element in the collection and return it.
    • getSingleOrNull

      public static <T> T getSingleOrNull(Collection<T> collection)
      Validate that there is at most one element in the collection and return it (or null otherwise).
    • getAny

      public static <T> T getAny(Iterable<T> iterable)
      Return any element from the iterable.
    • getAnyOptional

      public static <T> Optional<T> getAnyOptional(Iterable<T> iterable)
      Return any element from the iterable if it exists.
    • add

      public static <C extends Collection<T>, T> C add(C collection, T element)
      Adds an element to a Collection and returns the Collection.
      Parameters:
      collection - to which the element should be added
      element - that should be added to the collection
      Returns:
      the collection
    • addAll

      public static <T, C extends Collection<T>> C addAll(C collection, C elements)
      Adds elements to a Collection and returns the Collection.
      Parameters:
      collection - to which the element should be added
      elements - that should be added to the collection
      Returns:
      the collection
    • map

      public static <S, T> List<T> map(List<S> list, Function<S,T> mapFunction)
      Return a new List with mapped values.
    • map

      public static <S, T> List<T> map(List<S> list, BiFunction<Integer,S,T> mapFunction)
      Return a new List with mapped values.
    • streamedCrossProduct

      public static <T> Iterable<List<T>> streamedCrossProduct(List<? extends Iterable<T>> iterables)
      Returns an Iterable that iterates the cross product of the given iterables.
      Parameters:
      iterables - should be iterable multiple times
    • createNullFilledArrayList

      public static <T> ArrayList<T> createNullFilledArrayList(int k)
      Creates an ArrayList that is filled with k nulls.
    • createPowerList

      public static <T> Collection<List<T>> createPowerList(Collection<T> base)
      Creates the power list of the given base (akin to power sets of sets).
    • createPowerList

      public static <T> Collection<List<T>> createPowerList(Collection<T> base, int maxElements)
      Creates the power list of the given base (akin to power sets of sets).
      Parameters:
      maxElements - maximum number of elements in the Lists in the power list
    • createMap

      public static <K, V> Map<K,V> createMap(Tuple<K,V>... keyValuePairs)