Package org.ethelred.util.collect
Class Sequences
- java.lang.Object
-
- org.ethelred.util.collect.Sequences
-
public class Sequences extends Object
Utility functions for Lists.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,C extends Collection<T>>
Cconcat(Collection<? extends T> a, Collection<? extends T> b, IntFunction<C> collectionSupplier)Join two Collections into one.static <T> List<T>concat(List<? extends T> a, List<? extends T> b)Join two Lists into one.static <T> List<T>concat(List<? extends T> list, T... items)Join some items to the end of a List.static <T> List<T>head(List<T> list, int items)Retrieve items from the start of a List.static <T> List<List<T>>prefixes(Iterable<T> iterable)Get all possible prefixes of an Iterable.static <T> List<T>tail(List<T> list, int items)Likehead, except it works backwards from the end of the list.
-
-
-
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 elementsC- the type of Collection to return- Parameters:
a- first collectionb- second collectioncollectionSupplier- 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 listb- 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 listitems- 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 fromitems- 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
-
-