Class CollectionsUtil


  • public final class CollectionsUtil
    extends Object
    Various methods for operating on collections.
    • Method Detail

      • intRange

        public static List<Integer> intRange​(int start,
                                             int end)
      • intRange

        public static List<Integer> intRange​(int start,
                                             int end,
                                             int step)
      • charRange

        public static List<Character> charRange​(char start,
                                                char end)
      • charStringRange

        public static List<String> charStringRange​(char start,
                                                   char end)
      • randomAccessList

        public static <T> List<? extends T> randomAccessList​(Collection<? extends T> coll)
      • allTuples

        public static <T> Iterable<List<T>> allTuples​(Iterable<? extends T> domain,
                                                      int length)
      • allTuples

        public static <T> Iterable<List<T>> allTuples​(Iterable<? extends T> domain,
                                                      int minLength,
                                                      int maxLength)
        Returns an iterator that iterates over all tuples of the given source domain whose length (dimension) is within the specified range. Each intermediate combination of elements is computed lazily.

        Note: Subsequent calls to the returned iterator's next() method return a reference to the same list, and only update the contents of the list. If you plan to reuse intermediate results, you'll need to explicitly copy them.

        Type Parameters:
        T - type of elements
        Parameters:
        domain - the iterables for the source domains
        minLength - the minimal length of the tuple
        maxLength - the maximum length of the tuple
        Returns:
        an iterator that iterates over all tuples of the given source domain whose length (dimension) is within the specified range
      • cartesianProduct

        @SafeVarargs
        public static <T> Iterable<List<T>> cartesianProduct​(Iterable<T>... iterables)
        Returns an iterator that iterates over the cartesian product of its given source domains. Each intermediate combination of elements is computed lazily.

        Note: Subsequent calls to the returned iterator's next() method return a reference to the same list, and only update the contents of the list. If you plan to reuse intermediate results, you'll need to explicitly copy them.

        Type Parameters:
        T - type of elements
        Parameters:
        iterables - the iterables for the source domains
        Returns:
        an iterator that iterates over the cartesian product of its given source domains