Permalink
Browse files

NBHM deviated from the ConcurrentMap interface by using == instead of…

… .equals for determining success of replace(k, old, new) and remove(k, value)
  • Loading branch information...
1 parent 7fb8c54 commit c74f61cd5d9b484f6c69c07f224863af094a9173 @moonpolysoft moonpolysoft committed Apr 18, 2011
Showing with 6 additions and 2 deletions.
  1. +6 −2 src/org/cliffc/high_scale_lib/NonBlockingHashMap.java
@@ -329,7 +329,10 @@ private final void initialize( int initial_sz ) {
/** Atomically do a {@link #remove(Object)} if-and-only-if the key is mapped
* to a value which is <code>equals</code> to the given value.
* @throws NullPointerException if the specified key or value is null */
- public boolean remove ( Object key,Object val ) { return putIfMatch( key,TOMBSTONE, val ) == val; }
+ public boolean remove ( Object key,Object val ) {
+ final Object out = putIfMatch(key, TOMBSTONE, val);
+ return (out == null) ? out == val : out.equals(val);
+ }
/** Atomically do a <code>put(key,val)</code> if-and-only-if the key is
* mapped to some value already.
@@ -340,7 +343,8 @@ private final void initialize( int initial_sz ) {
* mapped a value which is <code>equals</code> to <code>oldValue</code>.
* @throws NullPointerException if the specified key or value is null */
public boolean replace ( TypeK key, TypeV oldValue, TypeV newValue ) {
- return putIfMatch( key, newValue, oldValue ) == oldValue;
+ final Object out = putIfMatch(key, newValue, oldValue);
+ return (out == null) ? out == oldValue : out.equals(oldValue);
}
private final TypeV putIfMatch( Object key, Object newVal, Object oldVal ) {

0 comments on commit c74f61c

Please sign in to comment.