Class WayangCollections


  • public class WayangCollections
    extends java.lang.Object
    Utilities to operate Collections.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <C extends java.util.Collection<T>,​T>
      C
      add​(C collection, T element)
      Adds an element to a Collection and returns the Collection.
      static <T,​C extends java.util.Collection<T>>
      C
      addAll​(C collection, C elements)
      Adds elements to a Collection and returns the Collection.
      static <T,​C extends java.util.Collection<T>>
      C
      asCollection​(java.lang.Iterable<T> iterable, java.util.function.Supplier<C> collectionFactory)
      Provides the given iterable as Collection.
      static <T> java.util.List<T> asList​(java.util.Collection<T> collection)
      Provides the given collection as List, thereby checking if it is already a List.
      static <T> java.util.Set<T> asSet​(java.lang.Iterable<T> iterable)
      Provides the given iterable as Set, thereby checking if it is already a Set.
      static <T> java.util.Set<T> asSet​(java.util.Collection<T> collection)
      Provides the given collection as Set, thereby checking if it is already a Set.
      static <T> java.util.Set<T> asSet​(T... values)
      Provides the given values as Set.
      static <K,​V>
      java.util.Map<K,​V>
      createMap​(Tuple<K,​V>... keyValuePairs)  
      static <T> java.util.ArrayList<T> createNullFilledArrayList​(int k)
      Creates an ArrayList that is filled with k nulls.
      static <T> java.util.Collection<java.util.List<T>> createPowerList​(java.util.Collection<T> base)
      Creates the power list of the given base (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 given base (akin to power sets of sets).
      static <T> T getAny​(java.lang.Iterable<T> iterable)
      Return any element from the iterable.
      static <T> java.util.Optional<T> getAnyOptional​(java.lang.Iterable<T> iterable)
      Return any element from the iterable if it exists.
      static <T> T getSingle​(java.util.Collection<T> collection)
      Validate that there is only a single element in the collection and return it.
      static <T> T getSingleOrNull​(java.util.Collection<T> collection)
      Validate that there is at most one element in the collection and return it (or null 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 new List 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 new List with mapped values.
      static <K,​V>
      void
      put​(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 an Iterable that iterates the cross product of the given iterables.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 given collection as Set, thereby checking if it is already a Set.
      • asSet

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

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

        public static <T> java.util.List<T> asList​(java.util.Collection<T> collection)
        Provides the given collection as List, thereby checking if it is already a List.
      • 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 given iterable as Collection.
      • getSingle

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

        public static <T> T getSingleOrNull​(java.util.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​(java.lang.Iterable<T> iterable)
        Return any element from the iterable.
      • getAnyOptional

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

        public static <C extends java.util.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 java.util.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> java.util.List<T> map​(java.util.List<S> list,
                                                        java.util.function.Function<S,​T> mapFunction)
        Return a new List 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 new List 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 an Iterable that iterates the cross product of the given iterables.
        Parameters:
        iterables - should be iterable multiple times
      • createNullFilledArrayList

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

        public static <T> java.util.Collection<java.util.List<T>> createPowerList​(java.util.Collection<T> base)
        Creates the power list of the given base (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 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> java.util.Map<K,​V> createMap​(Tuple<K,​V>... keyValuePairs)