org.codehaus.plexus.util

Class CollectionUtils

public class CollectionUtils extends Object

Method Summary
static MapgetCardinalityMap(Collection col)
Returns a {@link Map} mapping each unique element in the given {@link Collection} to an {@link Integer} representing the number of occurances of that element in the {@link Collection}.
static intgetFreq(Object obj, Map freqMap)
static Collectionintersection(Collection a, Collection b)
Returns a {@link Collection} containing the intersection of the given {@link Collection}s.
static ListiteratorToList(Iterator it)
static MapmergeMaps(Map dominantMap, Map 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 MapmergeMaps(Map[] maps)
Take a series of Maps and merge them where the ordering of the array from 0..n is the dominant order.
static Collectionsubtract(Collection a, Collection b)
Returns a {@link Collection} containing a - b.

Method Detail

getCardinalityMap

public static Map getCardinalityMap(Collection col)
Returns a {@link Map} mapping each unique element in the given {@link Collection} to an {@link Integer} representing the number of occurances of that element in the {@link Collection}. An entry that maps to null indicates that the element does not appear in the given {@link Collection}.

getFreq

private static final int getFreq(Object obj, Map freqMap)

intersection

public static Collection intersection(Collection a, Collection b)
Returns a {@link Collection} containing the intersection of the given {@link Collection}s.

The cardinality of each element in the returned {@link Collection} will be equal to the minimum of the cardinality of that element in the two given {@link Collection}s.

See Also: Collection#retainAll

iteratorToList

public static List iteratorToList(Iterator it)

mergeMaps

public static Map mergeMaps(Map dominantMap, Map 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 Map mergeMaps(Map[] 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.

subtract

public static Collection subtract(Collection a, Collection b)
Returns a {@link Collection} containing a - b. The cardinality of each element e in the returned {@link Collection} will be the cardinality of e in a minus the cardinality of e in b, or zero, whichever is greater.

See Also: Collection#removeAll