All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java.util.concurrent.ConcurrentHashMap Maven / Gradle / Ivy

The newest version!

package java.util.concurrent;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class ConcurrentHashMap extends HashMap implements ConcurrentMap, Serializable
{
	public ConcurrentHashMap()
	{
		super();
	}

	public ConcurrentHashMap(int i)
	{
		super(i);
	}

	public ConcurrentHashMap(Map m)
	{
		super(m);
	}

	public ConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)
	{
		super(initialCapacity);
	}

	private static final long serialVersionUID= 7249069246763182397L;

	public V putIfAbsent(K key, V value)
	{
		if (!containsKey(key))
			return put(key, value);
		else
			return get(key);
	}

	public boolean remove(Object key, Object value)
	{
		if (containsKey(key) && get(key).equals(value))
		{
			remove(key);
			return true;
		}
		else
			return false;
	}

	public boolean replace(K key, V oldValue, V newValue)
	{
		if (containsKey(key) && get(key).equals(oldValue))
		{
			put(key, newValue);
			return true;
		}
		else
			return false;
	}

	public V replace(K key, V value)
	{
		if (containsKey(key))
		{
			return put(key, value);
		}
		else
			return null;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy