Java Map Remove removeAll(final Map target, final Iterable keys, Collection values)

Here you can find the source of removeAll(final Map target, final Iterable keys, Collection values)

Description

Removes all the given keys from the given map and adds their corresponding values to the given collection.

License

Open Source License

Parameter

Parameter Description
TKey The type of the keys of the map.
TValue The types of the values of the map.
target The map to remove the specified keys from.
keys An iterable providing the keys to be removed.
values A collection where the values corresponding to the given keys are added.

Declaration

public static <TKey, TValue> void removeAll(final Map<TKey, TValue> target, final Iterable<? extends TKey> keys,
        Collection<? super TValue> values) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;

import java.util.Iterator;

import java.util.Map;

public class Main {
    /**//from w ww  .  ja  v  a 2s  .co m
     * Removes all the given keys from the given map.
     *
     * @param <TKey> The type of the keys of the map.
     * @param <TValue> The types of the values of the map.
     * @param target The map to remove the specified keys from.
     * @param keys An iterable providing the keys to be removed.
     * @note In case the target or the keys are not effective, nothing happens.
     */
    public static <TKey, TValue> void removeAll(final Map<TKey, TValue> target,
            final Iterable<? extends TKey> keys) {
        if (keys != null) {
            removeAll(target, keys.iterator());
        }
    }

    /**
     * Removes all the given keys from the given map.
     *
     * @param <TKey> The type of the keys of the map.
     * @param <TValue> The types of the values of the map.
     * @param target The map to remove the specified keys from.
     * @param keys An iterator providing the keys to be removed.
     * @note In case the target or the keys are not effective, nothing happens.
     */
    public static <TKey, TValue> void removeAll(final Map<TKey, TValue> target,
            final Iterator<? extends TKey> keys) {
        if (target != null && keys != null) {
            while (keys.hasNext()) {
                target.remove(keys.next());
            }
        }
    }

    /**
     * Removes all the given keys from the given map and adds their
     * corresponding values to the given collection.
     *
     * @param <TKey> The type of the keys of the map.
     * @param <TValue> The types of the values of the map.
     * @param target The map to remove the specified keys from.
     * @param keys An iterable providing the keys to be removed.
     * @param values A collection where the values corresponding to the given
     * keys are added.
     * @note In case the target or the keys are not effective, nothing happens.
     * @note In case values is not effective, the keys are removed without
     * adding them.
     */
    public static <TKey, TValue> void removeAll(final Map<TKey, TValue> target, final Iterable<? extends TKey> keys,
            Collection<? super TValue> values) {
        if (keys != null) {
            removeAll(target, keys.iterator(), values);
        }
    }

    /**
     * Removes all the given keys from the given map and adds their
     * corresponding values to the given collection.
     *
     * @param <TKey> The type of the keys of the map.
     * @param <TValue> The types of the values of the map.
     * @param target The map to remove the specified keys from.
     * @param keys An iterator providing the keys to be removed.
     * @param values A collection where the values corresponding to the given
     * keys are added.
     * @note In case the target or the keys are not effective, nothing happens.
     * @note In case values is not effective, the keys are removed without
     * adding them.
     */
    public static <TKey, TValue> void removeAll(final Map<TKey, TValue> target, final Iterator<? extends TKey> keys,
            Collection<? super TValue> values) {
        if (values != null) {
            if (target != null && keys != null) {
                while (keys.hasNext()) {
                    values.add(target.remove(keys.next()));
                }
            }
        } else {
            removeAll(target, keys);
        }
    }
}

Related

  1. remove(Map map, String key)
  2. remove(Map> map, K key, V value)
  3. remove(Map map, Collection keys)
  4. remove(Map map, K key)
  5. removeAll(Map map, Set keys)
  6. removeAllFromCollection(Map> map, Object key, Collection values)
  7. removeAllNullValueEntry(Map source)
  8. removeAndCleanFromCollectionMap(KeyT key, ValT toBeRemoved, Map> map)