Class OkkamLists


  • public class OkkamLists
    extends Object
    • Method Detail

      • appendElements

        @SafeVarargs
        public static <T> List<T> appendElements​(List<T> list,
                                                 T... elements)
        Append elements to a list.
        Type Parameters:
        T - The list and elements type
        Parameters:
        list - The list
        elements - The elements to append
        Returns:
        The new List
      • prependElements

        @SafeVarargs
        public static <T> List<T> prependElements​(List<T> list,
                                                  T... elements)
        Prepend elements to a list.
        Type Parameters:
        T - The list and elements type
        Parameters:
        list - The list
        elements - The elements to prepend
        Returns:
        The new List
      • addIfNotContained

        @SafeVarargs
        public static <T> List<T> addIfNotContained​(List<T> list,
                                                    T... elements)
        add elements if not already contained.
        Type Parameters:
        T - The list and elements type
        Parameters:
        list - The list
        elements - The elements to add
        Returns:
        The new List
      • addIfEquals

        public static <T> boolean addIfEquals​(List<T> list,
                                              T elemToAdd,
                                              T elemToCompare)
        Add elemToAdd to the list only if it is equals to elemToCompare.
        Type Parameters:
        T - The list and elements type
        Parameters:
        list - The list
        elemToAdd - The element to add
        elemToCompare - The second element
        Returns:
        true if the elemToAdd was added, false otherwise
      • addIfEquals

        public static <T,​T1> boolean addIfEquals​(List<T> list,
                                                       T elemToAdd,
                                                       T1 element1,
                                                       T1 element2)
        Add elemToAdd to the list only if element1 is equals to element2.
        Type Parameters:
        T - The list and elements type
        T1 - The type of elements to check
        Parameters:
        list - The list
        elemToAdd - The element to add
        element1 - The first element
        element2 - The second element
        Returns:
        true if the elemToAdd was added, false otherwise
      • createArrayListIfNull

        public static <T> List<T> createArrayListIfNull​(List<T> list)
        Create an ArrayList if the List is null.
        Type Parameters:
        T - The list type
        Parameters:
        list - The input list
        Returns:
        The old list or the input one