Package it.tidalwave.util
Class CollectionUtils
- java.lang.Object
-
- it.tidalwave.util.CollectionUtils
-
public final class CollectionUtils extends java.lang.Object
This class contains a bunch of utility methods for manipulating lists.- Since:
- 3.2-ALPHA-13
- Author:
- Fabrizio Giudici
- Status: stable API
-
-
Constructor Summary
Constructors Constructor Description CollectionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.List<T>
concat(java.util.List<? extends T> list1, java.util.List<? extends T> list2)
Appends a list to another.static <T> java.util.List<T>
concat(java.util.List<? extends T> list, T object)
Appends a list to an object.static <T> T
head(java.util.List<? extends T> list)
Returns the first element of a list.static <T> java.util.Optional<T>
optionalHead(java.util.List<? extends T> list)
Returns the (optional) first element of a list.static <T> java.util.List<T>
reversed(java.util.List<? extends T> list)
Reverses a list.static <T> java.util.List<T>
tail(java.util.List<? extends T> list)
Returns the tail element of a list, that is a list without the first element.
-
-
-
Method Detail
-
concat
@Nonnull public static <T> java.util.List<T> concat(@Nonnull java.util.List<? extends T> list, @Nonnull T object)
Appends a list to an object. The resulting list is mutable.- Parameters:
list
- the listobject
- the list to append- Returns:
- the list with the appended object
-
concat
@Nonnull public static <T> java.util.List<T> concat(@Nonnull java.util.List<? extends T> list1, @Nonnull java.util.List<? extends T> list2)
Appends a list to another. The resulting list is mutable.- Parameters:
list1
- the former listlist2
- the latter list- Returns:
- the list with the appended object
-
reversed
@Nonnull public static <T> java.util.List<T> reversed(@Nonnull java.util.List<? extends T> list)
Reverses a list. The resulting list is mutable.- Parameters:
list
- the list- Returns:
- the reversed list
-
optionalHead
@Nonnull public static <T> java.util.Optional<T> optionalHead(@Nonnull java.util.List<? extends T> list)
Returns the (optional) first element of a list.- Parameters:
list
- the list- Returns:
- the first element
-
head
@Nonnull public static <T> T head(@Nonnull java.util.List<? extends T> list)
Returns the first element of a list.- Parameters:
list
- the list (cannot be empty)- Returns:
- the first element
- Throws:
java.lang.IllegalArgumentException
- if the list is empty
-
tail
@Nonnull public static <T> java.util.List<T> tail(@Nonnull java.util.List<? extends T> list)
Returns the tail element of a list, that is a list without the first element. The tail of an empty list is an empty list. The resulting list is mutable.- Parameters:
list
- the list- Returns:
- the tail of the list
-
-