Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.Iterator; import java.util.Map; public class Main { /** * 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); } } }