Java Map Remove removeAndCleanFromCollectionMap(KeyT key, ValT toBeRemoved, Map> map)

Here you can find the source of removeAndCleanFromCollectionMap(KeyT key, ValT toBeRemoved, Map> map)

Description

NOTE Same as removeObjectFromCollectionMap but remove key if Collection is empty.

License

Open Source License

Parameter

Parameter Description
key point to the collection in which we must rmove an element
toBeRemoved the object to removed in collection refered by key
map the map of collection in which to do removal

Return

true if after removal collection rezfered to is empty

Declaration

public static <KeyT, ValT> boolean removeAndCleanFromCollectionMap(KeyT key, ValT toBeRemoved,
        Map<KeyT, Collection<ValT>> map) 

Method Source Code

//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

import java.util.Collection;

import java.util.Map;

public class Main {
    /**//from  w  w w. ja  va  2s. com
     * NOTE Same as removeObjectFromCollectionMap but remove key if Collection is empty.
     * 
     * @param key point to the collection in which we must rmove an element
     * @param toBeRemoved the object to removed in collection refered by key
     * @param map the map of collection in which to do removal
     * @return true if after removal collection rezfered to is empty
     * @see MultiMapHelper#removeObjectFromCollectionMap(Object, Object, Map)
     */
    public static <KeyT, ValT> boolean removeAndCleanFromCollectionMap(KeyT key, ValT toBeRemoved,
            Map<KeyT, Collection<ValT>> map) {
        Collection<ValT> obj = map.get(key);
        if (obj == null) {
            return false;
        }
        // else
        Collection<ValT> coll = obj;
        final boolean ret = coll.remove(toBeRemoved);
        if (coll.isEmpty()) {
            map.remove(key);
        }
        return ret;
    }
}

Related

  1. remove(Map map, K key)
  2. removeAll(final Map target, final Iterable keys, Collection values)
  3. removeAll(Map map, Set keys)
  4. removeAllFromCollection(Map> map, Object key, Collection values)
  5. removeAllNullValueEntry(Map source)
  6. removeApiUuidMap(String apiName)
  7. removeClassFromMap(final Map the_map, final String the_class_name)
  8. removeColor(Map windowColorCountMap, int windowColorCount, int lastColor)
  9. removeDefaultAnnotationPackage(final String packageName, final Map context)