Package org.ethelred.util.collect
Class Sequences
java.lang.Object
org.ethelred.util.collect.Sequences
Utility functions for Lists.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <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>Join two Lists into one.static <T> List<T>Join some items to the end of a List.static <T> List<T>Retrieve items from the start of a List.Get all possible prefixes of an Iterable.static <T> List<T>Likehead, except it works backwards from the end of the list.
-
Method Details
-
prefixes
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
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
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
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
-
tail
Likehead, except it works backwards from the end of the list.
-