Class CollectionExtensions


  • public final class CollectionExtensions
    extends java.lang.Object
    The class CollectionExtensions is an extension class for use with Collection objects.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> void difference​(java.util.Collection<T> one, java.util.Collection<T> other)
      Removes all of the first given collection's elements that are also contained in the second given collection.
      static <T> int hashCode​(java.util.Collection<T[]> arrayObjects)
      Returns a hash code based on the contents of the collection that contains array objects.
      static <T> java.util.Collection<T> intersection​(java.util.Collection<T>... toIntersect)
      Intersection of the given collections.
      static <T> boolean isEmpty​(java.util.Collection<T> collection)
      Checks if the given Collection is null or empty.
      static <T> boolean isEqualCollection​(java.util.Collection<T> one, java.util.Collection<T> other)
      Compare the given two Collection objects in equality.
      static <T> boolean isNotEmpty​(java.util.Collection<T> collection)
      Checks if the given Collection is not null or empty
      static <T> java.util.Collection<java.util.List<T>> partition​(java.util.Collection<T> collection, int size)
      Groups the given Collection to parts from the specified size.
      static <T> java.util.Optional<java.lang.Boolean> preconditionOfEqualCollection​(java.util.Collection<T> one, java.util.Collection<T> other)
      Checks the given two Collection objects if there are null and return the appropriate Optional boolean value
      • Methods inherited from class java.lang.Object

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

      • CollectionExtensions

        public CollectionExtensions()
    • Method Detail

      • isEqualCollection

        public static <T> boolean isEqualCollection​(java.util.Collection<T> one,
                                                    java.util.Collection<T> other)
        Compare the given two Collection objects in equality.
        Type Parameters:
        T - the generic type of the elements
        Parameters:
        one - the one
        other - the other
        Returns:
        true, if the given two Collection objects are equal otherwise false
      • preconditionOfEqualCollection

        public static <T> java.util.Optional<java.lang.Boolean> preconditionOfEqualCollection​(java.util.Collection<T> one,
                                                                                              java.util.Collection<T> other)
        Checks the given two Collection objects if there are null and return the appropriate Optional boolean value
        Type Parameters:
        T - the generic type of the elements
        Parameters:
        one - the one
        other - the other
        Returns:
        the Optional boolean if value is true both are null, if value is false given two Collection objects are not equal otherwise the Optional is empty
      • difference

        public static <T> void difference​(java.util.Collection<T> one,
                                          java.util.Collection<T> other)
        Removes all of the first given collection's elements that are also contained in the second given collection.
        Type Parameters:
        T - the generic type
        Parameters:
        one - the collection where the element will be removed if any containing elements exists
        other - collection containing elements to be removed from the first given collection
      • intersection

        @SafeVarargs
        public static <T> java.util.Collection<T> intersection​(java.util.Collection<T>... toIntersect)
        Intersection of the given collections. Internally this method uses the Collection.retainAll(Collection) for come to the result.
        Type Parameters:
        T - the generic type
        Parameters:
        toIntersect - the to intersect
        Returns:
        the result of the intersection. This will be the first collection that contains the result.
      • isNotEmpty

        public static <T> boolean isNotEmpty​(java.util.Collection<T> collection)
        Checks if the given Collection is not null or empty
        Type Parameters:
        T - the generic type
        Parameters:
        collection - The collection to check
        Returns:
        true if the given Collection is null or empty otherwise false
      • isEmpty

        public static <T> boolean isEmpty​(java.util.Collection<T> collection)
        Checks if the given Collection is null or empty.
        Type Parameters:
        T - the generic type
        Parameters:
        collection - The collection to check
        Returns:
        true if the given Collection is null or empty otherwise false.
      • hashCode

        public static <T> int hashCode​(java.util.Collection<T[]> arrayObjects)
        Returns a hash code based on the contents of the collection that contains array objects.
        Type Parameters:
        T - the generic type of the array objects
        Parameters:
        arrayObjects - the collection that contains array objects whose content-based hash code to compute
        Returns:
        the content-based hash code for the given collection that contains array objects
      • partition

        public static <T> java.util.Collection<java.util.List<T>> partition​(java.util.Collection<T> collection,
                                                                            int size)
        Groups the given Collection to parts from the specified size.
        Type Parameters:
        T - the generic type
        Parameters:
        collection - the collection
        size - the size
        Returns:
        the collection