/** * {@inheritDoc} * * @throws ClassCastException if the specified key cannot be compared * with the keys currently in the map * @throws NullPointerException if any of the arguments are null */ public boolean replace(Object key, Object oldValue, Object newValue) { if (oldValue == null || newValue == null) throw new NullPointerException(); Comparable k = comparable(key); for (;;) { Node n = findNode(k); if (n == null) return false; Object v = n.value; if (v != null) { if (!oldValue.equals(v)) return false; if (n.casValue(v, newValue)) return true; } } }
/** * {@inheritDoc} * * @throws ClassCastException if the specified key cannot be compared * with the keys currently in the map * @throws NullPointerException if any of the arguments are null */ public boolean replace(Object key, Object oldValue, Object newValue) { if (oldValue == null || newValue == null) throw new NullPointerException(); Comparable k = comparable(key); for (;;) { Node n = findNode(k); if (n == null) return false; Object v = n.value; if (v != null) { if (!oldValue.equals(v)) return false; if (n.casValue(v, newValue)) return true; } } }
/** * {@inheritDoc} * * @throws ClassCastException if the specified key cannot be compared * with the keys currently in the map * @throws NullPointerException if any of the arguments are null */ public boolean replace(Object key, Object oldValue, Object newValue) { if (oldValue == null || newValue == null) throw new NullPointerException(); Comparable k = comparable(key); for (;;) { Node n = findNode(k); if (n == null) return false; Object v = n.value; if (v != null) { if (!oldValue.equals(v)) return false; if (n.casValue(v, newValue)) return true; } } }
if (!n.casValue(v, null)) break; if (!n.appendMarker(f) || !b.casNext(n, f))
if (!n.casValue(v, null)) break; if (!n.appendMarker(f) || !b.casNext(n, f))
if (onlyIfAbsent || n.casValue(v, value)) return v; else
if (!n.casValue(v, null)) break; if (!n.appendMarker(f) || !b.casNext(n, f))
continue; if (!n.casValue(v, null)) break; Object key = n.key;
if (onlyIfAbsent || n.casValue(v, value)) return v; else
if (onlyIfAbsent || n.casValue(v, value)) return v; else
continue; if (!n.casValue(v, null)) break; Object key = n.key;
continue; if (!n.casValue(v, null)) break; Object key = n.key;
/** * Removes first entry; returns its snapshot. * @return null if empty, else snapshot of first entry */ Map.Entry doRemoveFirstEntry() { for (;;) { Node b = head.node; Node n = b.next; if (n == null) return null; Node f = n.next; if (n != b.next) continue; Object v = n.value; if (v == null) { n.helpDelete(b, f); continue; } if (!n.casValue(v, null)) continue; if (!n.appendMarker(f) || !b.casNext(n, f)) findFirst(); // retry clearIndexToFirst(); return new AbstractMap.SimpleImmutableEntry(n.key, v); } }
/** * Removes first entry; returns its snapshot. * @return null if empty, else snapshot of first entry */ Map.Entry doRemoveFirstEntry() { for (;;) { Node b = head.node; Node n = b.next; if (n == null) return null; Node f = n.next; if (n != b.next) continue; Object v = n.value; if (v == null) { n.helpDelete(b, f); continue; } if (!n.casValue(v, null)) continue; if (!n.appendMarker(f) || !b.casNext(n, f)) findFirst(); // retry clearIndexToFirst(); return new AbstractMap.SimpleImmutableEntry(n.key, v); } }
/** * {@inheritDoc} * * @return the previous value associated with the specified key, * or <tt>null</tt> if there was no mapping for the key * @throws ClassCastException if the specified key cannot be compared * with the keys currently in the map * @throws NullPointerException if the specified key or value is null */ public Object replace(Object key, Object value) { if (value == null) throw new NullPointerException(); Comparable k = comparable(key); for (;;) { Node n = findNode(k); if (n == null) return null; Object v = n.value; if (v != null && n.casValue(v, value)) return v; } }
/** * {@inheritDoc} * * @return the previous value associated with the specified key, * or <tt>null</tt> if there was no mapping for the key * @throws ClassCastException if the specified key cannot be compared * with the keys currently in the map * @throws NullPointerException if the specified key or value is null */ public Object replace(Object key, Object value) { if (value == null) throw new NullPointerException(); Comparable k = comparable(key); for (;;) { Node n = findNode(k); if (n == null) return null; Object v = n.value; if (v != null && n.casValue(v, value)) return v; } }
/** * Removes first entry; returns its snapshot. * @return null if empty, else snapshot of first entry */ Map.Entry doRemoveFirstEntry() { for (;;) { Node b = head.node; Node n = b.next; if (n == null) return null; Node f = n.next; if (n != b.next) continue; Object v = n.value; if (v == null) { n.helpDelete(b, f); continue; } if (!n.casValue(v, null)) continue; if (!n.appendMarker(f) || !b.casNext(n, f)) findFirst(); // retry clearIndexToFirst(); return new AbstractMap.SimpleImmutableEntry(n.key, v); } }
/** * {@inheritDoc} * * @return the previous value associated with the specified key, * or <tt>null</tt> if there was no mapping for the key * @throws ClassCastException if the specified key cannot be compared * with the keys currently in the map * @throws NullPointerException if the specified key or value is null */ public Object replace(Object key, Object value) { if (value == null) throw new NullPointerException(); Comparable k = comparable(key); for (;;) { Node n = findNode(k); if (n == null) return null; Object v = n.value; if (v != null && n.casValue(v, value)) return v; } }