Java Map Remove removeFromMapValues(final Map map, final Object value)

Here you can find the source of removeFromMapValues(final Map map, final Object value)

Description

Removes the specified reader/writer from the values of the specified reader/writer map.

License

Open Source License

Parameter

Parameter Description
map The map mapping some key to reader/writers.
value The reader/writer to remove.

Return

The key for the object removed, or null if nothing was removed.

Declaration

public static Object removeFromMapValues(final Map map, final Object value) 

Method Source Code


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

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class Main {
    /**/*from  w  w  w  .j  ava2  s.com*/
     * Removes the specified reader/writer from the values of the specified
     * reader/writer map.  Many times classes will contain maps of some key
     * to reader/writers, and this method simply allows those classes to easily
     * remove those values.
     * 
     * @param map The map mapping some key to reader/writers.
     * @param value The reader/writer to remove.
     * @return The key for the object removed, or <code>null</code> if nothing
     * was removed.
     */
    public static Object removeFromMapValues(final Map map, final Object value) {
        synchronized (map) {
            final Collection entries = map.entrySet();
            for (final Iterator iter = entries.iterator(); iter.hasNext();) {
                final Map.Entry entry = (Entry) iter.next();
                if (entry.getValue().equals(value)) {
                    final Object key = entry.getKey();
                    iter.remove();
                    return key;
                }
            }
            return null;
        }
    }
}

Related

  1. removeEmptyArray(Map map)
  2. removeEmptyValues(Map params)
  3. removeExistingItemsFromProvided(Map existingItems, Map providedItems)
  4. removeFrom(Map map, K key)
  5. removeFromMap( Map map, K key, V value)
  6. removeGeneric( List> list)
  7. removeHeader(Map headers, String header)
  8. removeKeyAndConvertToListOfMaps( Object obj, String key)
  9. removeKeys(Collection keys, Map map)