Package org.apache.storm.daemon.utils
Class ListFunctionalSupport
- java.lang.Object
-
- org.apache.storm.daemon.utils.ListFunctionalSupport
-
public class ListFunctionalSupport extends Object
Implements missing sequence functions in Java compared to Clojure. To make thing simpler, it only supports List type.
-
-
Constructor Summary
Constructors Constructor Description ListFunctionalSupport()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> List<T>
drop(List<T> list, int count)
Drop the first N elements and create a new list.static <T> T
first(List<T> list)
Get the first element in list.static <T> T
last(List<T> list)
get the last element in list.static <T> List<T>
rest(List<T> list)
Drop the only first element and create a new list.static <T> List<T>
takeLast(List<T> list, int count)
Get the last N elements as a new list.
-
-
-
Method Detail
-
first
public static <T> T first(List<T> list)
Get the first element in list.- Parameters:
list
- list to get- Returns:
- the first element. null if list is null or empty.
-
last
public static <T> T last(List<T> list)
get the last element in list.- Parameters:
list
- list to get- Returns:
- the last element. null if list is null or empty.
-
takeLast
public static <T> List<T> takeLast(List<T> list, int count)
Get the last N elements as a new list.- Parameters:
list
- list to getcount
- element count to get- Returns:
- the first element. null if list is null. elements in a new list may be less than count if there're not enough elements in the list.
-
drop
public static <T> List<T> drop(List<T> list, int count)
Drop the first N elements and create a new list.- Parameters:
list
- the listcount
- element count to drop- Returns:
- newly created sublist that drops the first N elements from origin list. null if list is null.
-
-