Java ConcurrentMap remove(ConcurrentMap map, K key, V value)

Here you can find the source of remove(ConcurrentMap map, K key, V value)

Description

Removes the entry for a key only if currently mapped to a given value.

License

Open Source License

Parameter

Parameter Description
map The map to be operated on.
key The key with which the specified value is associated.
value The value expected to be associated with the specified key.
K The class of keys in this map.
V The class of values in the map.

Return

True if the value was removed.

Declaration

public static <K, V> boolean remove(ConcurrentMap<K, V> map, K key, V value) 

Method Source Code

//package com.java2s;
/*/* www .  j a  v  a 2s .c  o  m*/
 * The MIT License (MIT)
 *
 * Copyright (c) 2016 Lachlan Dowding
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

import java.util.concurrent.ConcurrentMap;

public class Main {
    /**
     * Removes the entry for a key only if currently mapped to a given value.
     *
     * @param map   The map to be operated on.
     * @param key   The key with which the specified value is associated.
     * @param value The value expected to be associated with the specified key.
     * @param <K>   The class of keys in this map.
     * @param <V>   The class of values in the map.
     * @return      True if the value was removed.
     */
    public static <K, V> boolean remove(ConcurrentMap<K, V> map, K key, V value) {
        return map != null && map.remove(key, value);
    }
}

Related

  1. putIfAbsent(ConcurrentMap map, K key, V value)
  2. putIfAbsent(ConcurrentMap map, K key, V value)
  3. putIfAbsent(ConcurrentMap target, K key, V value)
  4. putIfAbsent(final ConcurrentMap map, final K key, final V value)
  5. putIfAbsentAndGet(ConcurrentMap map, K key, V newValue)
  6. remove(K key, ConcurrentMap map, Object value)
  7. removeFromContainedSet(ConcurrentMap> map, K mapKey, V value)