Class CollectionUtils


  • public final class CollectionUtils
    extends Object
    • Method Detail

      • zipMap

        public static <T,​U> Map<T,​U> zipMap​(T[] keys,
                                                        U[] values)
        Takes an array of keys and an array of values and constructs a map. Both key and value arrays must be the same length and non-null.
        Type Parameters:
        T - the key type
        U - the value type
        Parameters:
        keys - the keys. Cannot be null
        values - the values. Cannot be null
        Returns:
        a map. cannot return null
        Throws:
        IllegalArgumentException - if either argument is null or the arrays aren't the same length
      • entry

        public static <K,​V> Map.Entry<K,​V> entry​(K key,
                                                             V value)
        Creates an entry from a key and value.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        key - the key. Can be null.
        value - the value. Can be null.
        Returns:
        a Map.Entry
      • entriesToMap

        public static <K,​U> Collector<Map.Entry<K,​U>,​?,​Map<K,​U>> entriesToMap()
        Convenience method to a return a Collector that converts an Map.Entry to a Map.
        Type Parameters:
        K - the key type
        U - the value type
        Returns:
        A Collector from Map.Entry to Map
      • entriesToConcurrentMap

        public static <K,​U> Collector<Map.Entry<K,​U>,​?,​ConcurrentMap<K,​U>> entriesToConcurrentMap()
        Convenience method to a return a Collector that converts an Map.Entry to a ConcurrentMap.
        Type Parameters:
        K - the key type
        U - the value type
        Returns:
        A Collector from Map.Entry to ConcurrentMap
      • unsafeCast

        public static <K,​V> Map.Entry<K,​V> unsafeCast​(Map.Entry entry)
        This method takes a raw Map.Entry and casts it to a generic kind.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        entry - the entry to cast
        Returns:
        the passed in entry casted