org.omnaest.utils.structure.map.decorator
Class LockingMapDecorator<K,V>

java.lang.Object
  extended by org.omnaest.utils.structure.map.decorator.MapDecorator<K,V>
      extended by org.omnaest.utils.structure.map.decorator.LockingMapDecorator<K,V>
Type Parameters:
K -
V -
All Implemented Interfaces:
Serializable, Map<K,V>

public class LockingMapDecorator<K,V>
extends MapDecorator<K,V>

MapDecorator which uses a Lock instance to synchronize every method invocation. This allows to make not thread safe Maps thread safe.

Child Collections like keySet() as well as values() and entrySet() are using this Lock, too.

Author:
Omnaest
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
protected  Lock lock
           
 
Fields inherited from class org.omnaest.utils.structure.map.decorator.MapDecorator
map
 
Constructor Summary
LockingMapDecorator(Map<K,V> map)
          As default a new ReentrantLock instance is created
LockingMapDecorator(Map<K,V> map, Lock lock)
           
 
Method Summary
 void clear()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set<Map.Entry<K,V>> entrySet()
           
 boolean equals(Object obj)
           
 V get(Object key)
           
 int hashCode()
           
 boolean isEmpty()
           
 Set<K> keySet()
           
 V put(K key, V value)
           
 void putAll(Map<? extends K,? extends V> m)
           
 V remove(Object key)
           
 int size()
           
 String toString()
           
 Collection<V> values()
           
 
Methods inherited from class org.omnaest.utils.structure.map.decorator.MapDecorator
getMap, setMap
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

lock

protected final Lock lock
Constructor Detail

LockingMapDecorator

public LockingMapDecorator(Map<K,V> map,
                           Lock lock)
Parameters:
map -
lock -
See Also:
LockingMapDecorator

LockingMapDecorator

public LockingMapDecorator(Map<K,V> map)
As default a new ReentrantLock instance is created

Parameters:
map -
See Also:
LockingMapDecorator
Method Detail

size

public int size()
Specified by:
size in interface Map<K,V>
Overrides:
size in class MapDecorator<K,V>
See Also:
Map.size()

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<K,V>
Overrides:
isEmpty in class MapDecorator<K,V>
See Also:
Map.isEmpty()

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<K,V>
Overrides:
containsKey in class MapDecorator<K,V>
See Also:
Map.containsKey(java.lang.Object)

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map<K,V>
Overrides:
containsValue in class MapDecorator<K,V>
See Also:
Map.containsValue(java.lang.Object)

get

public V get(Object key)
Specified by:
get in interface Map<K,V>
Overrides:
get in class MapDecorator<K,V>
See Also:
Map.get(java.lang.Object)

put

public V put(K key,
             V value)
Specified by:
put in interface Map<K,V>
Overrides:
put in class MapDecorator<K,V>
See Also:
Map.put(java.lang.Object, java.lang.Object)

remove

public V remove(Object key)
Specified by:
remove in interface Map<K,V>
Overrides:
remove in class MapDecorator<K,V>
See Also:
Map.remove(java.lang.Object)

putAll

public void putAll(Map<? extends K,? extends V> m)
Specified by:
putAll in interface Map<K,V>
Overrides:
putAll in class MapDecorator<K,V>
See Also:
Map.putAll(java.util.Map)

clear

public void clear()
Specified by:
clear in interface Map<K,V>
Overrides:
clear in class MapDecorator<K,V>
See Also:
Map.clear()

keySet

public Set<K> keySet()
Specified by:
keySet in interface Map<K,V>
Overrides:
keySet in class MapDecorator<K,V>
See Also:
Map.keySet()

values

public Collection<V> values()
Specified by:
values in interface Map<K,V>
Overrides:
values in class MapDecorator<K,V>
See Also:
Map.values()

entrySet

public Set<Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface Map<K,V>
Overrides:
entrySet in class MapDecorator<K,V>
See Also:
Map.entrySet()

equals

public boolean equals(Object obj)
Specified by:
equals in interface Map<K,V>
Overrides:
equals in class MapDecorator<K,V>

hashCode

public int hashCode()
Specified by:
hashCode in interface Map<K,V>
Overrides:
hashCode in class MapDecorator<K,V>

toString

public String toString()
Overrides:
toString in class MapDecorator<K,V>


Copyright © 2013. All Rights Reserved.