mirror of
https://github.com/apache/commons-collections.git
synced 2025-02-17 15:35:00 +00:00
[COLLECTIONS-466] Replaced Collection with Iterable in MapUtils.populateMap methods.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1480230 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
54bbca8904
commit
1fe64733a2
@ -102,7 +102,7 @@ New methods in *Utils
|
||||
o [COLLECTIONS-286] CollectionUtils#extractSingleton(Collection). Thanks to Geoffrey De Smet.
|
||||
o [COLLECTIONS-263] MapUtils#populateMap(MultiMap, ...) to support also "MultiMap" instances as input. Thanks to John Hunsley.
|
||||
o [COLLECTIONS-235] ListUtils#indexOf(List, Predicate). Thanks to Nathan Egge.
|
||||
o [COLLECTIONS-194] MapUtils#populateMap(Map, Collection, Transformer, ...). Thanks to Dave Meikle.
|
||||
o [COLLECTIONS-194] MapUtils#populateMap(Map, Iterable, Transformer, ...). Thanks to Dave Meikle.
|
||||
|
||||
|
||||
New features
|
||||
|
@ -454,7 +454,7 @@
|
||||
Added support for resettable iterators in "IteratorIterable".
|
||||
</action>
|
||||
<action issue="COLLECTIONS-194" dev="bayard" type="add" due-to="Dave Meikle">
|
||||
Added methods "MapUtils#populateMap(Map, Collection, Transformer, ...)".
|
||||
Added methods "MapUtils#populateMap(Map, Iterable, Transformer, ...)".
|
||||
</action>
|
||||
<action issue="COLLECTIONS-182" dev="mbenson" type="update" due-to="Jim Cakalic">
|
||||
"CollectionUtils#forAllDo(Collection, Closure)" now returns the provided closure.
|
||||
|
@ -1666,38 +1666,38 @@ public class MapUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates a Map using the supplied <code>Transformer</code> to transform the collection
|
||||
* values into keys, using the unaltered collection value as the value in the <code>Map</code>.
|
||||
* Populates a Map using the supplied <code>Transformer</code> to transform the elements
|
||||
* into keys, using the unaltered element as the value in the <code>Map</code>.
|
||||
*
|
||||
* @param <K> the key type
|
||||
* @param <V> the value type
|
||||
* @param map the <code>Map</code> to populate.
|
||||
* @param collection the <code>Collection</code> to use as input values for the map.
|
||||
* @param keyTransformer the <code>Transformer</code> used to transform the collection value into a key value
|
||||
* @throws NullPointerException if the map, collection or transformer are null
|
||||
* @param elements the <code>Iterable</code> containing the input values for the map.
|
||||
* @param keyTransformer the <code>Transformer</code> used to transform the element into a key value
|
||||
* @throws NullPointerException if the map, elements or transformer are null
|
||||
*/
|
||||
public static <K, V> void populateMap(final Map<K, V> map, final Collection<? extends V> collection,
|
||||
public static <K, V> void populateMap(final Map<K, V> map, final Iterable<? extends V> elements,
|
||||
final Transformer<V, K> keyTransformer) {
|
||||
populateMap(map, collection, keyTransformer, TransformerUtils.<V>nopTransformer());
|
||||
populateMap(map, elements, keyTransformer, TransformerUtils.<V>nopTransformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates a Map using the supplied <code>Transformer</code>s to transform the collection
|
||||
* values into keys and values.
|
||||
* Populates a Map using the supplied <code>Transformer</code>s to transform the elements
|
||||
* into keys and values.
|
||||
*
|
||||
* @param <K> the key type
|
||||
* @param <V> the value type
|
||||
* @param <E> the type of object contained in the {@link Collection}
|
||||
* @param <E> the type of object contained in the {@link Iterable}
|
||||
* @param map the <code>Map</code> to populate.
|
||||
* @param collection the <code>Collection</code> to use as input values for the map.
|
||||
* @param keyTransformer the <code>Transformer</code> used to transform the collection value into a key value
|
||||
* @param valueTransformer the <code>Transformer</code> used to transform the collection value into a value
|
||||
* @throws NullPointerException if the map, collection or transformers are null
|
||||
* @param elements the <code>Iterable</code> containing the input values for the map.
|
||||
* @param keyTransformer the <code>Transformer</code> used to transform the element into a key value
|
||||
* @param valueTransformer the <code>Transformer</code> used to transform the element into a value
|
||||
* @throws NullPointerException if the map, elements or transformers are null
|
||||
*/
|
||||
public static <K, V, E> void populateMap(final Map<K, V> map, final Collection<? extends E> collection,
|
||||
public static <K, V, E> void populateMap(final Map<K, V> map, final Iterable<? extends E> elements,
|
||||
final Transformer<E, K> keyTransformer,
|
||||
final Transformer<E, V> valueTransformer) {
|
||||
final Iterator<? extends E> iter = collection.iterator();
|
||||
final Iterator<? extends E> iter = elements.iterator();
|
||||
while (iter.hasNext()) {
|
||||
final E temp = iter.next();
|
||||
map.put(keyTransformer.transform(temp), valueTransformer.transform(temp));
|
||||
@ -1705,38 +1705,38 @@ public class MapUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates a MultiMap using the supplied <code>Transformer</code> to transform the collection
|
||||
* values into keys, using the unaltered collection value as the value in the <code>MultiMap</code>.
|
||||
* Populates a MultiMap using the supplied <code>Transformer</code> to transform the elements
|
||||
* into keys, using the unaltered element as the value in the <code>MultiMap</code>.
|
||||
*
|
||||
* @param <K> the key type
|
||||
* @param <V> the value type
|
||||
* @param map the <code>MultiMap</code> to populate.
|
||||
* @param collection the <code>Collection</code> to use as input values for the map.
|
||||
* @param keyTransformer the <code>Transformer</code> used to transform the collection value into a key value
|
||||
* @throws NullPointerException if the map, collection or transformer are null
|
||||
* @param elements the <code>Iterable</code> to use as input values for the map.
|
||||
* @param keyTransformer the <code>Transformer</code> used to transform the element into a key value
|
||||
* @throws NullPointerException if the map, elements or transformer are null
|
||||
*/
|
||||
public static <K, V> void populateMap(final MultiMap<K, V> map, final Collection<? extends V> collection,
|
||||
public static <K, V> void populateMap(final MultiMap<K, V> map, final Iterable<? extends V> elements,
|
||||
final Transformer<V, K> keyTransformer) {
|
||||
populateMap(map, collection, keyTransformer, TransformerUtils.<V>nopTransformer());
|
||||
populateMap(map, elements, keyTransformer, TransformerUtils.<V>nopTransformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates a MultiMap using the supplied <code>Transformer</code>s to transform the collection
|
||||
* values into keys and values.
|
||||
* Populates a MultiMap using the supplied <code>Transformer</code>s to transform the elements
|
||||
* into keys and values.
|
||||
*
|
||||
* @param <K> the key type
|
||||
* @param <V> the value type
|
||||
* @param <E> the type of object contained in the {@link Collection}
|
||||
* @param <E> the type of object contained in the {@link Iterable}
|
||||
* @param map the <code>MultiMap</code> to populate.
|
||||
* @param collection the <code>Collection</code> to use as input values for the map.
|
||||
* @param keyTransformer the <code>Transformer</code> used to transform the collection value into a key value
|
||||
* @param valueTransformer the <code>Transformer</code> used to transform the collection value into a value
|
||||
* @param elements the <code>Iterable</code> containing the input values for the map.
|
||||
* @param keyTransformer the <code>Transformer</code> used to transform the element into a key value
|
||||
* @param valueTransformer the <code>Transformer</code> used to transform the element into a value
|
||||
* @throws NullPointerException if the map, collection or transformers are null
|
||||
*/
|
||||
public static <K, V, E> void populateMap(final MultiMap<K, V> map, final Collection<? extends E> collection,
|
||||
public static <K, V, E> void populateMap(final MultiMap<K, V> map, final Iterable<? extends E> elements,
|
||||
final Transformer<E, K> keyTransformer,
|
||||
final Transformer<E, V> valueTransformer) {
|
||||
final Iterator<? extends E> iter = collection.iterator();
|
||||
final Iterator<? extends E> iter = elements.iterator();
|
||||
while (iter.hasNext()) {
|
||||
final E temp = iter.next();
|
||||
map.put(keyTransformer.transform(temp), valueTransformer.transform(temp));
|
||||
|
Loading…
x
Reference in New Issue
Block a user