Class Lists


  • public final class Lists
    extends Object
    • Method Detail

      • createWhenNull

        public static <T> List<T> createWhenNull​(List<T> list)
        Returns the list when it is not null. Returns a new list otherwise.
        Parameters:
        list - The list to process, can be null
        Returns:
        The input list when it is not null, a new list otherwise
      • create

        public static <T> List<T> create​(T item)
        Creates a new List with the given item as the first entry.
        Parameters:
        item - The item to add to the new list
        Returns:
        List containing the given item
      • firstEntry

        public static <T> T firstEntry​(List<T> list)
        Extracts the first entry of the list when it is not null and contains values.
        Parameters:
        list - The list to extract the first entry from, can be null
        Returns:
        The first entry of the list when it is not null or empty, null otherwise
      • isEmpty

        public static boolean isEmpty​(List<?> list)
        Checks whether the list is null or empty.
        Parameters:
        list - The list to check
        Returns:
        true when the list is null or empty, false otherwise
      • isNotEmpty

        public static boolean isNotEmpty​(List<?> list)
        Checks whether the list is not null and not empty.
        Parameters:
        list - The list to check
        Returns:
        true when the list is not null and not empty
      • sizeIs

        public static boolean sizeIs​(List<?> list,
                                     int size)
        Checks whether the list has the given size. A null list is treated like a list without entries.
        Parameters:
        list - The list to check
        size - The size to check
        Returns:
        true when the list has the given size or when size = 0 and the list is null, false otherwise
      • emptyToNull

        public static <T> List<T> emptyToNull​(List<T> list)
        Returns null, when the given list is empty or null
        Parameters:
        list - The list to process
        Returns:
        null when the list is empty or null, the given list otherwise