Class CollectionUtils


  • public class CollectionUtils
    extends Object
    Version:
    $Id$
    Author:
    olamy
    • Constructor Detail

      • CollectionUtils

        public CollectionUtils()
    • Method Detail

      • mergeMaps

        public static <K,​V> Map<K,​V> mergeMaps​(Map<K,​V> dominantMap,
                                                           Map<K,​V> recessiveMap)
        Take a dominant and recessive Map and merge the key:value pairs where the recessive Map may add key:value pairs to the dominant Map but may not override any existing key:value pairs. If we have two Maps, a dominant and recessive, and their respective keys are as follows: dominantMapKeys = { a, b, c, d, e, f } recessiveMapKeys = { a, b, c, x, y, z } Then the result should be the following: resultantKeys = { a, b, c, d, e, f, x, y, z }
        Parameters:
        dominantMap - Dominant Map.
        recessiveMap - Recessive Map.
        Returns:
        The result map with combined dominant and recessive values.
      • mergeMaps

        public static <K,​V> Map<K,​V> mergeMaps​(Map<K,​V>[] maps)
        Take a series of Maps and merge them where the ordering of the array from 0..n is the dominant order.
        Parameters:
        maps - An array of Maps to merge.
        Returns:
        Map The result Map produced after the merging process.
      • getCardinalityMap

        public static <E> Map<E,​Integer> getCardinalityMap​(Collection<E> col)
        Returns a Map mapping each unique element in the given Collection to an Integer representing the number of occurrences of that element in the Collection. An entry that maps to null indicates that the element does not appear in the given Collection.
        Parameters:
        col - The collection to count cardinalities for
        Returns:
        A map of counts, indexed on each element in the collection
      • iteratorToList

        public static <E> List<E> iteratorToList​(Iterator<E> it)