ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ConcurrentHashMap.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ConcurrentHashMap.java (file contents):
Revision 1.31 by dl, Fri Nov 28 12:37:00 2003 UTC vs.
Revision 1.32 by dl, Wed Dec 3 21:07:44 2003 UTC

# Line 305 | Line 305 | public class ConcurrentHashMap<K, V> ext
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
# Line 318 | Line 320 | public class ConcurrentHashMap<K, V> ext
320              }
321          }
322  
323 +
324          V put(K key, int hash, V value, boolean onlyIfAbsent) {
325              lock();
326              try {
# Line 824 | Line 827 | public class ConcurrentHashMap<K, V> ext
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
# Line 848 | Line 852 | public class ConcurrentHashMap<K, V> ext
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.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines