Here you can find the source of removeAndCleanFromCollectionMap(KeyT key, ValT toBeRemoved, Map
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 |
public static <KeyT, ValT> boolean removeAndCleanFromCollectionMap(KeyT key, ValT toBeRemoved, Map<KeyT, Collection<ValT>> map)
//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; } }