Class CollectionUtils


  • public class CollectionUtils
    extends java.lang.Object
    Version:
    $Id$
    • Constructor Summary

      Constructors 
      Constructor Description
      CollectionUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <E> java.util.Map<E,​java.lang.Integer> getCardinalityMap​(java.util.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.
      private static <E> int getFreq​(E obj, java.util.Map<E,​java.lang.Integer> freqMap)  
      static <E> java.util.Collection<E> intersection​(java.util.Collection<E> a, java.util.Collection<E> b)
      Returns a Collection containing the intersection of the given Collections.
      static <E> java.util.List<E> iteratorToList​(java.util.Iterator<E> it)  
      static <K,​V>
      java.util.Map<K,​V>
      mergeMaps​(java.util.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.
      static <K,​V>
      java.util.Map<K,​V>
      mergeMaps​(java.util.Map<K,​V> dominantMap, java.util.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.
      static <T> java.util.Collection<T> subtract​(java.util.Collection<T> a, java.util.Collection<T> b)
      Returns a Collection containing a - b.
      • 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

      • mergeMaps

        public static <K,​V> java.util.Map<K,​V> mergeMaps​(java.util.Map<K,​V> dominantMap,
                                                                     java.util.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> java.util.Map<K,​V> mergeMaps​(java.util.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.
      • intersection

        public static <E> java.util.Collection<E> intersection​(java.util.Collection<E> a,
                                                               java.util.Collection<E> b)
        Returns a Collection containing the intersection of the given Collections.

        The cardinality of each element in the returned Collection will be equal to the minimum of the cardinality of that element in the two given Collections.

        Parameters:
        a - The first collection
        b - The second collection
        Returns:
        The intersection of a and b, never null
        See Also:
        Collection.retainAll(java.util.Collection<?>)
      • subtract

        public static <T> java.util.Collection<T> subtract​(java.util.Collection<T> a,
                                                           java.util.Collection<T> b)
        Returns a Collection containing a - b. The cardinality of each element e in the returned Collection will be the cardinality of e in a minus the cardinality of e in b, or zero, whichever is greater.
        Parameters:
        a - The start collection
        b - The collection that will be subtracted
        Returns:
        The result of the subtraction
        See Also:
        Collection.removeAll(java.util.Collection<?>)
      • getCardinalityMap

        public static <E> java.util.Map<E,​java.lang.Integer> getCardinalityMap​(java.util.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> java.util.List<E> iteratorToList​(java.util.Iterator<E> it)
      • getFreq

        private static <E> int getFreq​(E obj,
                                       java.util.Map<E,​java.lang.Integer> freqMap)