Package org.codehaus.plexus.util
Class CollectionUtils
java.lang.Object
org.codehaus.plexus.util.CollectionUtils
- Author:
- olamy
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetCardinalityMap
(Collection<E> col) Returns aMap
mapping each unique element in the givenCollection
to anInteger
representing the number of occurrences of that element in theCollection
.static <E> Collection<E>
intersection
(Collection<E> a, Collection<E> b) Returns aCollection
containing the intersection of the givenCollection
s.static <E> List<E>
iteratorToList
(Iterator<E> it) static <K,
V> Map<K, V> Take a series ofMap
s and merge them where the ordering of the array from 0..n is the dominant order.static <K,
V> Map<K, V> 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> Collection<T>
subtract
(Collection<T> a, Collection<T> b) Returns aCollection
containinga - b
.
-
Constructor Details
-
CollectionUtils
public CollectionUtils()
-
-
Method Details
-
mergeMaps
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 }- Type Parameters:
K
- typeV
- type- Parameters:
dominantMap
- Dominant Map.recessiveMap
- Recessive Map.- Returns:
- The result map with combined dominant and recessive values.
-
mergeMaps
Take a series ofMap
s and merge them where the ordering of the array from 0..n is the dominant order.- Type Parameters:
K
- typeV
- type- Parameters:
maps
- An array of Maps to merge.- Returns:
- Map The result Map produced after the merging process.
-
intersection
Returns a
The cardinality of each element in the returnedCollection
containing the intersection of the givenCollection
s.Collection
will be equal to the minimum of the cardinality of that element in the two givenCollection
s.- Type Parameters:
E
- the type- Parameters:
a
- The first collectionb
- The second collection- Returns:
- The intersection of a and b, never null
- See Also:
-
subtract
Returns aCollection
containinga - b
. The cardinality of each element e in the returnedCollection
will be the cardinality of e in a minus the cardinality of e in b, or zero, whichever is greater.- Type Parameters:
T
- the type- Parameters:
a
- The start collectionb
- The collection that will be subtracted- Returns:
- The result of the subtraction
- See Also:
-
getCardinalityMap
Returns aMap
mapping each unique element in the givenCollection
to anInteger
representing the number of occurrences of that element in theCollection
. An entry that maps tonull
indicates that the element does not appear in the givenCollection
.- Type Parameters:
E
- the type- Parameters:
col
- The collection to count cardinalities for- Returns:
- A map of counts, indexed on each element in the collection
-
iteratorToList
-