305 |
|
e = e.next; |
306 |
|
} |
307 |
|
|
308 |
< |
V v = e.value; |
309 |
< |
if (v == null || !oldValue.equals(v)) |
310 |
< |
return false; |
308 |
> |
if (oldValue != null) { |
309 |
> |
V v = e.value; |
310 |
> |
if (v == null || !oldValue.equals(v)) |
311 |
> |
return false; |
312 |
> |
} |
313 |
|
|
314 |
|
e.value = newValue; |
315 |
|
count = c; // write-volatile |
320 |
|
} |
321 |
|
} |
322 |
|
|
323 |
+ |
|
324 |
|
V put(K key, int hash, V value, boolean onlyIfAbsent) { |
325 |
|
lock(); |
326 |
|
try { |
827 |
|
return segmentFor(hash).remove(key, hash, value) != null; |
828 |
|
} |
829 |
|
|
830 |
+ |
|
831 |
|
/** |
832 |
|
* Replace entry for key only if currently mapped to given value. |
833 |
|
* Acts as |
852 |
|
return segmentFor(hash).replace(key, hash, oldValue, newValue); |
853 |
|
} |
854 |
|
|
855 |
+ |
/** |
856 |
+ |
* Replace entry for key only if key is currently mapped. |
857 |
+ |
* Acts as |
858 |
+ |
* <pre> |
859 |
+ |
* if ((map.containsKey(key)) { |
860 |
+ |
* map.put(key, value); |
861 |
+ |
* return true; |
862 |
+ |
* } else return false; |
863 |
+ |
* </pre> |
864 |
+ |
* except that the action is performed atomically. |
865 |
+ |
* @param key key with which the specified value is associated. |
866 |
+ |
* @param value value to be associated with the specified key. |
867 |
+ |
* @return true if the value was replaced |
868 |
+ |
* @throws NullPointerException if the specified key or value is |
869 |
+ |
* <tt>null</tt>. |
870 |
+ |
*/ |
871 |
+ |
public boolean replace(K key, V value) { |
872 |
+ |
if (value == null) |
873 |
+ |
throw new NullPointerException(); |
874 |
+ |
int hash = hash(key); |
875 |
+ |
return segmentFor(hash).replace(key, hash, null, value); |
876 |
+ |
} |
877 |
+ |
|
878 |
|
|
879 |
|
/** |
880 |
|
* Removes all mappings from this map. |