Class Sequences


  • public class Sequences
    extends Object
    Utility functions for Lists.
    • Method Detail

      • prefixes

        public static <T> List<List<T>> prefixes​(Iterable<T> iterable)
        Get all possible prefixes of an Iterable. For example, if the parameter is a list [1,2,3], the result will be [[],[1],[1,2],[1,2,3]].
        Type Parameters:
        T - the type of elements
        Parameters:
        iterable - The starting value
        Returns:
        A list of lists
      • concat

        public static <T,​C extends Collection<T>> C concat​(Collection<? extends T> a,
                                                                 Collection<? extends T> b,
                                                                 IntFunction<C> collectionSupplier)
        Join two Collections into one.
        Type Parameters:
        T - the type of elements
        C - the type of Collection to return
        Parameters:
        a - first collection
        b - second collection
        collectionSupplier - Function to construct the collection to return. The int parameter is the expected size of the resulting collection.
        Returns:
        the combined collection
      • concat

        public static <T> List<T> concat​(List<? extends T> a,
                                         List<? extends T> b)
        Join two Lists into one. The order will be all elements of a followed by all elements of b.
        Type Parameters:
        T - the type of elements
        Parameters:
        a - first list
        b - second list
        Returns:
        Combined list
      • concat

        @SafeVarargs
        public static <T> List<T> concat​(List<? extends T> list,
                                         T... items)
        Join some items to the end of a List.
        Type Parameters:
        T - the type of elements
        Parameters:
        list - original list
        items - items to add to the list
        Returns:
        Combined list
      • head

        public static <T> List<T> head​(List<T> list,
                                       int items)
        Retrieve items from the start of a List.
        Type Parameters:
        T - the type of elements
        Parameters:
        list - list to draw from
        items - When positive, return that many items from the start. When negative, return items from the start of the list except for that number at the end. When 0, return an empty list, though I'm not sure why you would want to do that. If greater than the size of the list, the original list is returned.
        Returns:
        resulting list
      • tail

        public static <T> List<T> tail​(List<T> list,
                                       int items)
        Like head, except it works backwards from the end of the list.