Class ListUtils
- java.lang.Object
-
- org.apache.jackrabbit.oak.commons.collections.ListUtils
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> @NotNull List<List<T>>
partitionList(List<T> list, int n)
Split a list into partitions of a given size.static <T> @NotNull List<T>
reverse(List<T> l)
Returns a new list containing the elements of the specified list in reverse order.static <T> @NotNull List<T>
toLinkedList(Iterable<T> iterable)
Convert an iterable to aLinkedList
.static <T> @NotNull List<T>
toList(@NotNull Iterable<? extends T> iterable)
Convert an iterable to a list.static <T> @NotNull List<T>
toList(Iterator<? extends T> iterator)
Convert an iterator to a list.
-
-
-
Method Detail
-
toList
@NotNull public static <T> @NotNull List<T> toList(@NotNull @NotNull Iterable<? extends T> iterable)
Convert an iterable to a list. The returning list is mutable and supports all optional operations.- Type Parameters:
T
- the type of the elements- Parameters:
iterable
- the iterable to convert- Returns:
- the list
-
toLinkedList
@NotNull public static <T> @NotNull List<T> toLinkedList(Iterable<T> iterable)
Convert an iterable to aLinkedList
. The returning LinkedList is mutable and supports all optional operations.- Type Parameters:
T
- the type of the elements- Parameters:
iterable
- the iterator to convert- Returns:
- the LinkedList
-
toList
@NotNull public static <T> @NotNull List<T> toList(Iterator<? extends T> iterator)
Convert an iterator to a list. The returning list is mutable and supports all optional operations.- Type Parameters:
T
- the type of the elements- Parameters:
iterator
- the iterator to convert- Returns:
- the list
-
partitionList
@NotNull public static <T> @NotNull List<List<T>> partitionList(List<T> list, int n)
Split a list into partitions of a given size.- Type Parameters:
T
- the type of the elements- Parameters:
list
- the list to partitionn
- the size of partitions- Returns:
- a list of partitions. The resulting partitions aren’t a view of the main List, so any changes happening to the main List won’t affect the partitions.
-
reverse
@NotNull public static <T> @NotNull List<T> reverse(List<T> l)
Returns a new list containing the elements of the specified list in reverse order.- Type Parameters:
T
- the type of elements in the list- Parameters:
l
- the list to be reversed, must not be null- Returns:
- a new list containing the elements of the specified list in reverse order
- Throws:
NullPointerException
- if the list is null
-
-