-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConcurrentHashMapWithNullSupport.java
More file actions
111 lines (102 loc) · 1.92 KB
/
Copy pathConcurrentHashMapWithNullSupport.java
File metadata and controls
111 lines (102 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import java.io.Serializable;
public class ConcurrentHashMapWithNullSupport<K, V> extends ForwardingConcurrentMap<K, V> implements Serializable
{
private static final long serialVersionUID = 1L;
private ConcurrentMap<K,V> m_delegate = new ConcurrentHashMap<K, V>();
private final K nullKey;
private final V nullValue;
public ConcurrentHashMapWithNullSupport(K nullKey, V nullValue)
{
this.nullKey = nullKey;
this.nullValue = nullValue;
}
@SuppressWarnings("unchecked")
public ConcurrentHashMapWithNullSupport()
{
this.nullKey = (K) "nullKey";
this.nullValue = (V) "nullValue";
}
@Override
public V get(Object key)
{
V value;
if (null == key)
{
value = super.get(nullKey);
}
else
{
value = super.get(key);
}
if (value == nullValue)
{
return null;
}
return value;
}
@Override
public V put(K key, V value)
{
K updatedKey = key;
V updatedValue = value;
if (null == updatedKey)
{
updatedKey = nullKey;
}
if (null == updatedValue)
{
updatedValue = nullValue;
}
return super.put(updatedKey, updatedValue);
}
@Override
public V remove(Object key)
{
V $ = null;
if (null == key)
{
$ = super.remove(nullKey);
}
else
{
$ = super.remove(key);
}
if (nullValue == $)
{
return null;
}
return $;
}
@SuppressWarnings("unchecked")
@Override
public boolean remove(Object key, Object value)
{
K updatedKey = (K)key;
V updatedValue = (V)value;
if (null == updatedKey)
{
updatedKey = nullKey;
}
if (null == updatedValue)
{
updatedValue = nullValue;
}
return super.remove(updatedKey, updatedValue);
}
@Override
public boolean containsKey(Object key)
{
if (null == key)
{
return super.containsKey(nullKey);
}
return super.containsKey(key);
}
@Override
public void putAll(Map<? extends K, ? extends V> map)
{
for (Entry<? extends K, ? extends V> e : map.entrySet())
{
put(e.getKey(), e.getValue());
}
}