Class XCollectionUtils


  • public class XCollectionUtils
    extends Object
    Utility class for operations on collections
    Since:
    7.0.0
    Author:
    XIMA Media GmbH
    • Method Detail

      • firstItem

        public static <T> T firstItem​(List<T> list)
        Type Parameters:
        T - Type of the elements in the list.
        Parameters:
        list - List to process.
        Returns:
        The first item in the list, or null if the list is null or empty, or the first item is null.
      • lastItem

        public static <T> T lastItem​(List<T> list)
        Type Parameters:
        T - Type of the elements in the list.
        Parameters:
        list - List to process.
        Returns:
        The last item in the list, or null if the list is null or empty, or the last item is null.
      • serializableList

        public static <T> List<T> serializableList​(Iterable<T> sequence)
        Takes any Collection or Iterable and converts it to a serializable list that can be transferred via the API.
        Type Parameters:
        T - Type of the list items.
        Parameters:
        sequence - A sequence of items to put into a list.
        Returns:
        A serializable list with the given items.
      • listOfSize

        public static <T> List<T> listOfSize​(int targetSize,
                                             T initialValue)
        Type Parameters:
        T - Type of the list elements.
        Parameters:
        targetSize - Desired size of the list.
        initialValue - Initial value for each element.
        Returns:
        A list of the given size, with each element set to the given initial value.
      • listOfSizeWith

        public static <T> List<T> listOfSizeWith​(int targetSize,
                                                 IntFunction<T> initialValue)
        Type Parameters:
        T - Type of the list elements.
        Parameters:
        targetSize - Desired size of the list.
        initialValue - Supplier for the initial value for each element.
        Returns:
        A list of the given size, with each element set to the value returned by the given supplier.