Class CollectionUtils


  • public final class CollectionUtils
    extends java.lang.Object
    The CollectionUtils class provides static utility methods for working with collections. Andrei Tatarnikov
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> java.util.List<T> appendToList​(java.util.List<T> first, java.util.List<T> second)
      Appends all elements from the specified list to another list and returns the updated list with the appended elements.
      static <T> java.util.List<T> appendToList​(java.util.List<T> list, T element)
      Appends the specified element to the specified list and returns the updated list with the appended element.
      static <E> boolean areIntersectedSets​(java.util.Set<E> lhs, java.util.Set<E> rhs)
      Checks whether two sets are intersected (have as non-empty intersection).
      static <E> java.util.Set<E> complementSets​(java.util.Set<E> lhs, java.util.Set<E> rhs)
      Returns a relative complement of two sets.
      static <E> java.util.Set<E> intersectSets​(java.util.Set<E> lhs, java.util.Set<E> rhs)
      Returns an intersection of two sets.
      static <T> java.util.List<T> mergeLists​(java.util.List<T> first, java.util.List<T> second)
      Merges two lists two lists.
      static <E> java.util.Set<E> uniteSets​(java.util.Set<E> lhs, java.util.Set<E> rhs)
      Returns a union of two sets.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • uniteSets

        public static <E> java.util.Set<E> uniteSets​(java.util.Set<E> lhs,
                                                     java.util.Set<E> rhs)
        Returns a union of two sets.
        Type Parameters:
        E - Set element type.
        Parameters:
        lhs - First set (left hand).
        rhs - Second set (right hand).
        Returns:
        Union of two sets.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null.
      • intersectSets

        public static <E> java.util.Set<E> intersectSets​(java.util.Set<E> lhs,
                                                         java.util.Set<E> rhs)
        Returns an intersection of two sets.
        Type Parameters:
        E - Set element type.
        Parameters:
        lhs - First set (left hand).
        rhs - Second set (right hand).
        Returns:
        Intersection of two sets.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null.
      • areIntersectedSets

        public static <E> boolean areIntersectedSets​(java.util.Set<E> lhs,
                                                     java.util.Set<E> rhs)
        Checks whether two sets are intersected (have as non-empty intersection).
        Type Parameters:
        E - Set element type.
        Parameters:
        lhs - First set (left hand).
        rhs - Second set (right hand).
        Returns:
        true if the sets are intersected, false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null.
      • complementSets

        public static <E> java.util.Set<E> complementSets​(java.util.Set<E> lhs,
                                                          java.util.Set<E> rhs)
        Returns a relative complement of two sets.
        Type Parameters:
        E - Set element type.
        Parameters:
        lhs - First set (left hand).
        rhs - Second set (right hand).
        Returns:
        Relative complement of two sets.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null.
      • appendToList

        public static <T> java.util.List<T> appendToList​(java.util.List<T> first,
                                                         java.util.List<T> second)
        Appends all elements from the specified list to another list and returns the updated list with the appended elements.
        Type Parameters:
        T - List element type.
        Parameters:
        first - List to which the elements will be appended.
        second - List which contains elements to be appended.
        Returns:
        Updated list that contains the appended elements.
        Throws:
        java.lang.IllegalArgumentException - if any of the arguments is null.
      • appendToList

        public static <T> java.util.List<T> appendToList​(java.util.List<T> list,
                                                         T element)
        Appends the specified element to the specified list and returns the updated list with the appended element.
        Type Parameters:
        T - List element type.
        Parameters:
        list - List to which the element will be appended.
        element - Element to be added.
        Returns:
        Updated list that contains the appended element.
        Throws:
        java.lang.IllegalArgumentException - if the list argument is null.
      • mergeLists

        public static <T> java.util.List<T> mergeLists​(java.util.List<T> first,
                                                       java.util.List<T> second)
        Merges two lists two lists. Returns a new list that contains elements of both lists. If any of the lists is empty, returns the other list.
        Type Parameters:
        T - List element type.
        Parameters:
        first - First list to be merged.
        second - Second list to be merged.
        Returns:
        Merged list.
        Throws:
        java.lang.IllegalArgumentException - if any of the arguments is null.