Class CollectionUtils


  • public class CollectionUtils
    extends java.lang.Object
    Since:
    5.0.0
    • Constructor Summary

      Constructors 
      Constructor Description
      CollectionUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.springframework.util.MultiValueMap asMultiValueMap​(java.lang.String key, java.lang.Object value)
      As multi value map.
      static org.springframework.util.MultiValueMap asMultiValueMap​(java.lang.String key1, java.lang.Object value1, java.lang.String key2, java.lang.Object value2)
      As multi value map.
      static org.springframework.util.MultiValueMap asMultiValueMap​(java.util.Map innerMap)
      As multi value map.
      static java.util.Map<java.lang.String,​java.lang.String> convertDirectedListToMap​(java.util.Collection<java.lang.String> inputList)
      Convert directed list to map.
      static java.util.Optional<java.lang.Object> firstElement​(java.lang.Object obj)
      Converts the provided object into a collection and return the first element, or empty.
      static <T> java.util.Optional<T> firstElement​(java.lang.Object obj, java.lang.Class<T> clazz)
      Converts the provided object into a collection and return the first element, or empty.
      static java.util.Map<java.lang.String,​java.lang.Object> merge​(java.util.Map<java.lang.String,​?>... attributes)
      Merge map.
      static java.util.Set<java.lang.Object> toCollection​(java.lang.Object obj)
      Convert the object given into a Collection instead.
      static <T extends java.util.Collection>
      T
      toCollection​(java.lang.Object obj, java.lang.Class<T> clazz)
      To collection t.
      static <K,​V>
      java.util.Map<K,​V>
      wrap​(com.google.common.collect.Multimap<K,​V> source)
      Wrap map.
      static <K,​V>
      java.util.Map<K,​V>
      wrap​(java.lang.String key, java.lang.Object value)
      Wrap map.
      static <K extends java.lang.String,​V>
      java.util.Map<K,​V>
      wrap​(java.lang.String key, java.lang.Object value, java.lang.String key2, java.lang.Object value2)
      Wrap map.
      static <K,​V>
      java.util.Map<K,​V>
      wrap​(java.lang.String key, java.lang.Object value, java.lang.String key2, java.lang.Object value2, java.lang.String key3, java.lang.Object value3)
      Wrap map.
      static <K,​V>
      java.util.Map<K,​V>
      wrap​(java.lang.String key, java.lang.Object value, java.lang.String key2, java.lang.Object value2, java.lang.String key3, java.lang.Object value3, java.lang.String key4, java.lang.Object value4)
      Wrap map.
      static <K,​V>
      java.util.Map<K,​V>
      wrap​(java.lang.String key, java.lang.Object value, java.lang.String key2, java.lang.Object value2, java.lang.String key3, java.lang.Object value3, java.lang.String key4, java.lang.Object value4, java.lang.String key5, java.lang.Object value5)
      Wrap map.
      static <K,​V>
      java.util.Map<K,​V>
      wrap​(java.lang.String key, java.lang.Object value, java.lang.String key2, java.lang.Object value2, java.lang.String key3, java.lang.Object value3, java.lang.String key4, java.lang.Object value4, java.lang.String key5, java.lang.Object value5, java.lang.String key6, java.lang.Object value6)
      Wrap map.
      static <K,​V>
      java.util.Map<K,​V>
      wrap​(java.lang.String key, java.lang.Object value, java.lang.String key2, java.lang.Object value2, java.lang.String key3, java.lang.Object value3, java.lang.String key4, java.lang.Object value4, java.lang.String key5, java.lang.Object value5, java.lang.String key6, java.lang.Object value6, java.lang.String key7, java.lang.Object value7)
      Wrap map.
      static <K,​V>
      java.util.Map<K,​V>
      wrap​(java.lang.String key, java.lang.Object value, java.lang.String key2, java.lang.Object value2, java.lang.String key3, java.lang.Object value3, java.lang.String key4, java.lang.Object value4, java.lang.String key5, java.lang.Object value5, java.lang.String key6, java.lang.Object value6, java.lang.String key7, java.lang.Object value7, java.lang.String key8, java.lang.Object value8)
      Wrap map.
      static <K,​V>
      java.util.Map<K,​V>
      wrap​(java.lang.String key, java.lang.Object value, java.lang.String key2, java.lang.Object value2, java.lang.String key3, java.lang.Object value3, java.lang.String key4, java.lang.Object value4, java.lang.String key5, java.lang.Object value5, java.lang.String key6, java.lang.Object value6, java.lang.String key7, java.lang.Object value7, java.lang.String key8, java.lang.Object value8, java.lang.String key9, java.lang.Object value9)
      Wrap map.
      static <T> java.util.List<T> wrap​(java.util.List<T> source)
      Wraps a possibly null list in an immutable wrapper.
      static <K,​V>
      java.util.Map<K,​V>
      wrap​(java.util.Map<K,​V> source)
      Wraps a possibly null map in an immutable wrapper.
      static <T> java.util.Set<T> wrap​(java.util.Set<T> source)
      Wrap varargs.
      static <T> java.util.List<T> wrap​(T source)
      Wraps a possibly null list in an immutable wrapper.
      static <T> java.util.ArrayList<T> wrapArrayList​(T... source)
      Wrap array list array list.
      static <T> java.util.Collection<T> wrapCollection​(T... source)
      Wrap collection.
      static <T> java.util.HashSet<T> wrapHashSet​(java.util.Collection<T> source)
      Wrap hash set.
      static <T> java.util.HashSet<T> wrapHashSet​(T... source)
      Wrap hash set.
      static <T> java.util.Map<java.lang.String,​T> wrapLinkedHashMap​(java.lang.String key, T source)
      Wrap linked hash map.
      static <T> java.util.List<T> wrapList​(T... source)
      Wrap list.
      static <T> java.util.Set<T> wrapSet​(T source)
      Wrap set set.
      static <T> java.util.Set<T> wrapSet​(T... source)
      Wrap set.
      • Methods inherited from class java.lang.Object

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

      • CollectionUtils

        public CollectionUtils()
    • Method Detail

      • firstElement

        public static java.util.Optional<java.lang.Object> firstElement​(java.lang.Object obj)
        Converts the provided object into a collection and return the first element, or empty.
        Parameters:
        obj - the obj
        Returns:
        the optional
      • firstElement

        public static <T> java.util.Optional<T> firstElement​(java.lang.Object obj,
                                                             java.lang.Class<T> clazz)
        Converts the provided object into a collection and return the first element, or empty.
        Type Parameters:
        T - the type parameter
        Parameters:
        obj - the obj
        clazz - the clazz
        Returns:
        the optional
      • toCollection

        public static <T extends java.util.Collection> T toCollection​(java.lang.Object obj,
                                                                      java.lang.Class<T> clazz)
        To collection t.
        Type Parameters:
        T - the type parameter
        Parameters:
        obj - the obj
        clazz - the clazz
        Returns:
        the t
      • toCollection

        public static java.util.Set<java.lang.Object> toCollection​(java.lang.Object obj)
        Convert the object given into a Collection instead.
        Parameters:
        obj - the object to convert into a collection
        Returns:
        The collection instance containing the object provided
      • wrap

        public static <K,​V> java.util.Map<K,​V> wrap​(com.google.common.collect.Multimap<K,​V> source)
        Wrap map.
        Type Parameters:
        K - the type parameter
        V - the type parameter
        Parameters:
        source - the source
        Returns:
        the map
      • wrap

        public static <K,​V> java.util.Map<K,​V> wrap​(java.util.Map<K,​V> source)
        Wraps a possibly null map in an immutable wrapper.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        source - map to wrap.
        Returns:
        the map
      • wrap

        public static <K,​V> java.util.Map<K,​V> wrap​(java.lang.String key,
                                                                java.lang.Object value)
        Wrap map.
        Type Parameters:
        K - the type parameter
        V - the type parameter
        Parameters:
        key - the key
        value - the value
        Returns:
        the map
      • wrap

        public static <K extends java.lang.String,​V> java.util.Map<K,​V> wrap​(java.lang.String key,
                                                                                         java.lang.Object value,
                                                                                         java.lang.String key2,
                                                                                         java.lang.Object value2)
        Wrap map.
        Type Parameters:
        K - the type parameter
        V - the type parameter
        Parameters:
        key - the key
        value - the value
        key2 - the key 2
        value2 - the value 2
        Returns:
        the map
      • wrap

        public static <K,​V> java.util.Map<K,​V> wrap​(java.lang.String key,
                                                                java.lang.Object value,
                                                                java.lang.String key2,
                                                                java.lang.Object value2,
                                                                java.lang.String key3,
                                                                java.lang.Object value3)
        Wrap map.
        Type Parameters:
        K - the type parameter
        V - the type parameter
        Parameters:
        key - the key
        value - the value
        key2 - the key 2
        value2 - the value 2
        key3 - the key 3
        value3 - the value 3
        Returns:
        the map
      • wrap

        public static <K,​V> java.util.Map<K,​V> wrap​(java.lang.String key,
                                                                java.lang.Object value,
                                                                java.lang.String key2,
                                                                java.lang.Object value2,
                                                                java.lang.String key3,
                                                                java.lang.Object value3,
                                                                java.lang.String key4,
                                                                java.lang.Object value4)
        Wrap map.
        Type Parameters:
        K - the type parameter
        V - the type parameter
        Parameters:
        key - the key
        value - the value
        key2 - the key 2
        value2 - the value 2
        key3 - the key 3
        value3 - the value 3
        key4 - the key 4
        value4 - the value 4
        Returns:
        the map
      • wrap

        public static <K,​V> java.util.Map<K,​V> wrap​(java.lang.String key,
                                                                java.lang.Object value,
                                                                java.lang.String key2,
                                                                java.lang.Object value2,
                                                                java.lang.String key3,
                                                                java.lang.Object value3,
                                                                java.lang.String key4,
                                                                java.lang.Object value4,
                                                                java.lang.String key5,
                                                                java.lang.Object value5)
        Wrap map.
        Type Parameters:
        K - the type parameter
        V - the type parameter
        Parameters:
        key - the key
        value - the value
        key2 - the key 2
        value2 - the value 2
        key3 - the key 3
        value3 - the value 3
        key4 - the key 4
        value4 - the value 4
        key5 - the key 5
        value5 - the value 5
        Returns:
        the map
      • wrap

        public static <K,​V> java.util.Map<K,​V> wrap​(java.lang.String key,
                                                                java.lang.Object value,
                                                                java.lang.String key2,
                                                                java.lang.Object value2,
                                                                java.lang.String key3,
                                                                java.lang.Object value3,
                                                                java.lang.String key4,
                                                                java.lang.Object value4,
                                                                java.lang.String key5,
                                                                java.lang.Object value5,
                                                                java.lang.String key6,
                                                                java.lang.Object value6)
        Wrap map.
        Type Parameters:
        K - the type parameter
        V - the type parameter
        Parameters:
        key - the key
        value - the value
        key2 - the key 2
        value2 - the value 2
        key3 - the key 3
        value3 - the value 3
        key4 - the key 4
        value4 - the value 4
        key5 - the key 5
        value5 - the value 5
        key6 - the key 6
        value6 - the value 6
        Returns:
        the map
      • wrap

        public static <K,​V> java.util.Map<K,​V> wrap​(java.lang.String key,
                                                                java.lang.Object value,
                                                                java.lang.String key2,
                                                                java.lang.Object value2,
                                                                java.lang.String key3,
                                                                java.lang.Object value3,
                                                                java.lang.String key4,
                                                                java.lang.Object value4,
                                                                java.lang.String key5,
                                                                java.lang.Object value5,
                                                                java.lang.String key6,
                                                                java.lang.Object value6,
                                                                java.lang.String key7,
                                                                java.lang.Object value7)
        Wrap map.
        Type Parameters:
        K - the type parameter
        V - the type parameter
        Parameters:
        key - the key
        value - the value
        key2 - the key 2
        value2 - the value 2
        key3 - the key 3
        value3 - the value 3
        key4 - the key 4
        value4 - the value 4
        key5 - the key 5
        value5 - the value 5
        key6 - the key 6
        value6 - the value 6
        key7 - the key 7
        value7 - the value 7
        Returns:
        the map
      • wrap

        public static <K,​V> java.util.Map<K,​V> wrap​(java.lang.String key,
                                                                java.lang.Object value,
                                                                java.lang.String key2,
                                                                java.lang.Object value2,
                                                                java.lang.String key3,
                                                                java.lang.Object value3,
                                                                java.lang.String key4,
                                                                java.lang.Object value4,
                                                                java.lang.String key5,
                                                                java.lang.Object value5,
                                                                java.lang.String key6,
                                                                java.lang.Object value6,
                                                                java.lang.String key7,
                                                                java.lang.Object value7,
                                                                java.lang.String key8,
                                                                java.lang.Object value8)
        Wrap map.
        Type Parameters:
        K - the type parameter
        V - the type parameter
        Parameters:
        key - the key
        value - the value
        key2 - the key 2
        value2 - the value 2
        key3 - the key 3
        value3 - the value 3
        key4 - the key 4
        value4 - the value 4
        key5 - the key 5
        value5 - the value 5
        key6 - the key 6
        value6 - the value 6
        key7 - the key 7
        value7 - the value 7
        key8 - the key 8
        value8 - the value 8
        Returns:
        the map
      • wrap

        public static <K,​V> java.util.Map<K,​V> wrap​(java.lang.String key,
                                                                java.lang.Object value,
                                                                java.lang.String key2,
                                                                java.lang.Object value2,
                                                                java.lang.String key3,
                                                                java.lang.Object value3,
                                                                java.lang.String key4,
                                                                java.lang.Object value4,
                                                                java.lang.String key5,
                                                                java.lang.Object value5,
                                                                java.lang.String key6,
                                                                java.lang.Object value6,
                                                                java.lang.String key7,
                                                                java.lang.Object value7,
                                                                java.lang.String key8,
                                                                java.lang.Object value8,
                                                                java.lang.String key9,
                                                                java.lang.Object value9)
        Wrap map.
        Type Parameters:
        K - the type parameter
        V - the type parameter
        Parameters:
        key - the key
        value - the value
        key2 - the key 2
        value2 - the value 2
        key3 - the key 3
        value3 - the value 3
        key4 - the key 4
        value4 - the value 4
        key5 - the key 5
        value5 - the value 5
        key6 - the key 6
        value6 - the value 6
        key7 - the key 7
        value7 - the value 7
        key8 - the key 8
        value8 - the value 8
        key9 - the key 9
        value9 - the value 9
        Returns:
        the map
      • wrap

        public static <T> java.util.List<T> wrap​(T source)
        Wraps a possibly null list in an immutable wrapper.
        Type Parameters:
        T - the type parameter
        Parameters:
        source - list to wrap.
        Returns:
        the list
      • wrap

        public static <T> java.util.List<T> wrap​(java.util.List<T> source)
        Wraps a possibly null list in an immutable wrapper.
        Type Parameters:
        T - the type parameter
        Parameters:
        source - list to wrap.
        Returns:
        the list
      • wrap

        public static <T> java.util.Set<T> wrap​(java.util.Set<T> source)
        Wrap varargs.
        Type Parameters:
        T - the type parameter
        Parameters:
        source - the source
        Returns:
        the set
      • wrapSet

        public static <T> java.util.Set<T> wrapSet​(T source)
        Wrap set set.
        Type Parameters:
        T - the type parameter
        Parameters:
        source - the source
        Returns:
        the set
      • wrapSet

        public static <T> java.util.Set<T> wrapSet​(T... source)
        Wrap set.
        Type Parameters:
        T - the type parameter
        Parameters:
        source - the source
        Returns:
        the set
      • wrapHashSet

        public static <T> java.util.HashSet<T> wrapHashSet​(T... source)
        Wrap hash set.
        Type Parameters:
        T - the type parameter
        Parameters:
        source - the source
        Returns:
        the set
      • wrapHashSet

        public static <T> java.util.HashSet<T> wrapHashSet​(java.util.Collection<T> source)
        Wrap hash set.
        Type Parameters:
        T - the type parameter
        Parameters:
        source - the source
        Returns:
        the set
      • wrapList

        public static <T> java.util.List<T> wrapList​(T... source)
        Wrap list.
        Type Parameters:
        T - the type parameter
        Parameters:
        source - the source
        Returns:
        the set
      • wrapArrayList

        public static <T> java.util.ArrayList<T> wrapArrayList​(T... source)
        Wrap array list array list.
        Type Parameters:
        T - the type parameter
        Parameters:
        source - the source
        Returns:
        the array list
      • wrapLinkedHashMap

        public static <T> java.util.Map<java.lang.String,​T> wrapLinkedHashMap​(java.lang.String key,
                                                                                    T source)
        Wrap linked hash map.
        Type Parameters:
        T - the type parameter
        Parameters:
        key - the key
        source - the source
        Returns:
        the array list
      • asMultiValueMap

        public static org.springframework.util.MultiValueMap asMultiValueMap​(java.util.Map innerMap)
        As multi value map.
        Parameters:
        innerMap - the inner map
        Returns:
        the multi value map
      • asMultiValueMap

        public static org.springframework.util.MultiValueMap asMultiValueMap​(java.lang.String key,
                                                                             java.lang.Object value)
        As multi value map.
        Parameters:
        key - the key
        value - the value
        Returns:
        the multi value map
      • asMultiValueMap

        public static org.springframework.util.MultiValueMap asMultiValueMap​(java.lang.String key1,
                                                                             java.lang.Object value1,
                                                                             java.lang.String key2,
                                                                             java.lang.Object value2)
        As multi value map.
        Parameters:
        key1 - the key 1
        value1 - the value 1
        key2 - the key 2
        value2 - the value 2
        Returns:
        the multi value map
      • convertDirectedListToMap

        public static java.util.Map<java.lang.String,​java.lang.String> convertDirectedListToMap​(java.util.Collection<java.lang.String> inputList)
        Convert directed list to map.
        Parameters:
        inputList - the input list
        Returns:
        the map
      • wrapCollection

        public static <T> java.util.Collection<T> wrapCollection​(T... source)
        Wrap collection.
        Type Parameters:
        T - the type parameter
        Parameters:
        source - the source
        Returns:
        the collection
      • merge

        public static java.util.Map<java.lang.String,​java.lang.Object> merge​(java.util.Map<java.lang.String,​?>... attributes)
        Merge map.
        Parameters:
        attributes - the attributes
        Returns:
        the map