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 Details

    • ListFunctionalSupport

      public ListFunctionalSupport()
  • Method Details

    • 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 get
      count - 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 list
      count - element count to drop
      Returns:
      newly created sublist that drops the first N elements from origin list. null if list is null.
    • rest

      public static <T> List<T> rest(List<T> list)
      Drop the only first element and create a new list. equivalent to drop(list, 1).
      Parameters:
      list - the list
      Returns:
      newly created sublist that drops the first element from origin list. null if list is null.