Class CollectionUtils

  • All Implemented Interfaces:
    Utils

    public abstract class CollectionUtils
    extends java.lang.Object
    implements Utils
    The utilities class for Java Collection
    Author:
    Mercy
    See Also:
    Collections
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> int addAll​(java.util.Collection<T> collection, T... values)
      Add the multiple values into the specified collection
      static <E> java.lang.Iterable<E> emptyIterable()
      Get the empty Iterable
      static <E> java.util.Iterator<E> emptyIterator()
      Get the empty Iterator
      static boolean equals​(java.util.Collection<?> one, java.util.Collection<?> another)
      Compares the specified collection with another, the main implementation references AbstractSet
      static <T> T first​(java.lang.Iterable<T> values)
      Take the first element from the specified Iterable
      static <T> T first​(java.util.Collection<T> values)
      Take the first element from the specified collection
      static <T> T first​(java.util.Iterator<T> values)
      Take the first element from the specified
      static boolean isEmpty​(java.util.Collection<?> collection)  
      static boolean isNotEmpty​(java.util.Collection<?> collection)  
      static <E> java.util.Enumeration<E> singletonEnumeration​(E element)  
      static <E> java.lang.Iterable<E> singletonIterable​(E element)  
      static <E> java.util.Iterator<E> singletonIterator​(E element)  
      static int size​(java.lang.Iterable<?> iterable)
      Get the size of the specified Iterable
      static int size​(java.util.Collection<?> collection)
      Get the size of the specified Collection
      static <E> java.lang.Iterable<E> toIterable​(java.util.Collection<E> collection)  
      static <E> java.lang.Iterable<E> toIterable​(java.util.Enumeration<E> enumeration)  
      static <E> java.lang.Iterable<E> toIterable​(java.util.Iterator<E> iterator)  
      static <E> java.util.Iterator<E> toIterator​(java.util.Enumeration<E> enumeration)  
      static <E> java.util.Iterator<E> unmodifiableIterator​(java.util.Iterator<E> iterator)  
      • Methods inherited from class java.lang.Object

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

      • isEmpty

        public static boolean isEmpty​(@Nullable
                                      java.util.Collection<?> collection)
      • isNotEmpty

        public static boolean isNotEmpty​(@Nullable
                                         java.util.Collection<?> collection)
      • toIterable

        @Nullable
        public static <E> java.lang.Iterable<E> toIterable​(@Nullable
                                                           java.util.Collection<E> collection)
      • toIterable

        @Nonnull
        public static <E> java.lang.Iterable<E> toIterable​(java.util.Iterator<E> iterator)
      • toIterator

        @Nonnull
        public static <E> java.util.Iterator<E> toIterator​(@Nullable
                                                           java.util.Enumeration<E> enumeration)
      • toIterable

        @Nonnull
        public static <E> java.lang.Iterable<E> toIterable​(@Nullable
                                                           java.util.Enumeration<E> enumeration)
      • singletonIterable

        @Nonnull
        public static <E> java.lang.Iterable<E> singletonIterable​(@Nullable
                                                                  E element)
      • singletonIterator

        @Nonnull
        public static <E> java.util.Iterator<E> singletonIterator​(@Nullable
                                                                  E element)
      • singletonEnumeration

        @Nonnull
        public static <E> java.util.Enumeration<E> singletonEnumeration​(@Nullable
                                                                        E element)
      • unmodifiableIterator

        @Nonnull
        public static <E> java.util.Iterator<E> unmodifiableIterator​(@Nullable
                                                                     java.util.Iterator<E> iterator)
      • emptyIterator

        @Nonnull
        public static <E> java.util.Iterator<E> emptyIterator()
        Get the empty Iterator
        Type Parameters:
        E - the element type
        Returns:
        non-null
      • emptyIterable

        @Nonnull
        public static <E> java.lang.Iterable<E> emptyIterable()
        Get the empty Iterable
        Type Parameters:
        E - the element type
        Returns:
        non-null
      • size

        public static int size​(@Nullable
                               java.util.Collection<?> collection)
        Get the size of the specified Collection
        Parameters:
        collection - the specified Collection
        Returns:
        must be positive number
      • size

        public static int size​(@Nullable
                               java.lang.Iterable<?> iterable)
        Get the size of the specified Iterable
        Parameters:
        iterable - the specified Iterable
        Returns:
        must be positive number
      • equals

        public static boolean equals​(@Nullable
                                     java.util.Collection<?> one,
                                     @Nullable
                                     java.util.Collection<?> another)
        Compares the specified collection with another, the main implementation references AbstractSet
        Parameters:
        one - Collection
        another - Collection
        Returns:
        if equals, return true, or false
      • addAll

        public static <T> int addAll​(@Nullable
                                     java.util.Collection<T> collection,
                                     T... values)
        Add the multiple values into the specified collection
        Type Parameters:
        T - the type of values
        Parameters:
        collection - the specified collection
        values - the multiple values
        Returns:
        the effected count after added
      • first

        @Nullable
        public static <T> T first​(@Nullable
                                  java.util.Collection<T> values)
        Take the first element from the specified collection
        Type Parameters:
        T - the type of element of collection
        Parameters:
        values - the collection object
        Returns:
        if found, return the first one, or null
      • first

        @Nullable
        public static <T> T first​(@Nullable
                                  java.lang.Iterable<T> values)
        Take the first element from the specified Iterable
        Type Parameters:
        T - the type of element of Iterable
        Parameters:
        values - the Iterable object
        Returns:
        if found, return the first one, or null
      • first

        @Nullable
        public static <T> T first​(@Nullable
                                  java.util.Iterator<T> values)
        Take the first element from the specified
        Type Parameters:
        T - the type of element of
        Parameters:
        values - the Iterator object
        Returns:
        if found, return the first one, or null