/** * Save the state of this map to a stream. * * @serialData The key (Object) and value (Object) for each * key-value mapping represented by the map, followed by * <tt>null</tt>. The key-value mappings are emitted in key-order * (as determined by the Comparator, or by the keys' natural * ordering if no Comparator). */ private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { // Write out the Comparator and any hidden stuff s.defaultWriteObject(); // Write out keys and values (alternating) for (Node n = findFirst(); n != null; n = n.next) { Object v = n.getValidValue(); if (v != null) { s.writeObject(n.key); s.writeObject(v); } } s.writeObject(null); }
/** * Save the state of this map to a stream. * * @serialData The key (Object) and value (Object) for each * key-value mapping represented by the map, followed by * <tt>null</tt>. The key-value mappings are emitted in key-order * (as determined by the Comparator, or by the keys' natural * ordering if no Comparator). */ private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { // Write out the Comparator and any hidden stuff s.defaultWriteObject(); // Write out keys and values (alternating) for (Node n = findFirst(); n != null; n = n.next) { Object v = n.getValidValue(); if (v != null) { s.writeObject(n.key); s.writeObject(v); } } s.writeObject(null); }
/** * Save the state of this map to a stream. * * @serialData The key (Object) and value (Object) for each * key-value mapping represented by the map, followed by * <tt>null</tt>. The key-value mappings are emitted in key-order * (as determined by the Comparator, or by the keys' natural * ordering if no Comparator). */ private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { // Write out the Comparator and any hidden stuff s.defaultWriteObject(); // Write out keys and values (alternating) for (Node n = findFirst(); n != null; n = n.next) { Object v = n.getValidValue(); if (v != null) { s.writeObject(n.key); s.writeObject(v); } } s.writeObject(null); }
/** * Submap version of ConcurrentSkipListMap.getNearEntry */ private Map.Entry getNearEntry(Object key, int rel) { if (isDescending) { // adjust relation for direction if ((rel & m.LT) == 0) rel |= m.LT; else rel &= ~m.LT; } if (tooLow(key)) return ((rel & m.LT) != 0)? null : lowestEntry(); if (tooHigh(key)) return ((rel & m.LT) != 0)? highestEntry() : null; for (;;) { Node n = m.findNear(key, rel); if (n == null || !inBounds(n.key)) return null; Object k = n.key; Object v = n.getValidValue(); if (v != null) return new AbstractMap.SimpleImmutableEntry(k, v); } }
/** * Returns the number of key-value mappings in this map. If this map * contains more than <tt>Integer.MAX_VALUE</tt> elements, it * returns <tt>Integer.MAX_VALUE</tt>. * * <p>Beware that, unlike in most collections, this method is * <em>NOT</em> a constant-time operation. Because of the * asynchronous nature of these maps, determining the current * number of elements requires traversing them all to count them. * Additionally, it is possible for the size to change during * execution of this method, in which case the returned result * will be inaccurate. Thus, this method is typically not very * useful in concurrent applications. * * @return the number of elements in this map */ public int size() { long count = 0; for (Node n = findFirst(); n != null; n = n.next) { if (n.getValidValue() != null) ++count; } return (count >= Integer.MAX_VALUE)? Integer.MAX_VALUE : (int)count; }
/** * Returns <tt>true</tt> if this map maps one or more keys to the * specified value. This operation requires time linear in the * map size. * * @param value value whose presence in this map is to be tested * @return <tt>true</tt> if a mapping to <tt>value</tt> exists; * <tt>false</tt> otherwise * @throws NullPointerException if the specified value is null */ public boolean containsValue(Object value) { if (value == null) throw new NullPointerException(); for (Node n = findFirst(); n != null; n = n.next) { Object v = n.getValidValue(); if (v != null && value.equals(v)) return true; } return false; }
/** * Returns <tt>true</tt> if this map maps one or more keys to the * specified value. This operation requires time linear in the * map size. * * @param value value whose presence in this map is to be tested * @return <tt>true</tt> if a mapping to <tt>value</tt> exists; * <tt>false</tt> otherwise * @throws NullPointerException if the specified value is null */ public boolean containsValue(Object value) { if (value == null) throw new NullPointerException(); for (Node n = findFirst(); n != null; n = n.next) { Object v = n.getValidValue(); if (v != null && value.equals(v)) return true; } return false; }
/** * Returns <tt>true</tt> if this map maps one or more keys to the * specified value. This operation requires time linear in the * map size. * * @param value value whose presence in this map is to be tested * @return <tt>true</tt> if a mapping to <tt>value</tt> exists; * <tt>false</tt> otherwise * @throws NullPointerException if the specified value is null */ public boolean containsValue(Object value) { if (value == null) throw new NullPointerException(); for (Node n = findFirst(); n != null; n = n.next) { Object v = n.getValidValue(); if (v != null && value.equals(v)) return true; } return false; }
public int size() { long count = 0; for (ConcurrentSkipListMap.Node n = loNode(); isBeforeEnd(n); n = n.next) { if (n.getValidValue() != null) ++count; } return count >= Integer.MAX_VALUE? Integer.MAX_VALUE : (int)count; }
public void clear() { for (ConcurrentSkipListMap.Node n = loNode(); isBeforeEnd(n); n = n.next) { if (n.getValidValue() != null) m.remove(n.key); } }
public int size() { long count = 0; for (ConcurrentSkipListMap.Node n = loNode(); isBeforeEnd(n); n = n.next) { if (n.getValidValue() != null) ++count; } return count >= Integer.MAX_VALUE? Integer.MAX_VALUE : (int)count; }
public boolean containsValue(Object value) { if (value == null) throw new NullPointerException(); for (ConcurrentSkipListMap.Node n = loNode(); isBeforeEnd(n); n = n.next) { Object v = n.getValidValue(); if (v != null && value.equals(v)) return true; } return false; }
/** * Creates and returns a new SimpleImmutableEntry holding current * mapping if this node holds a valid value, else null. * @return new entry or null */ AbstractMap.SimpleImmutableEntry createSnapshot() { Object v = getValidValue(); if (v == null) return null; return new AbstractMap.SimpleImmutableEntry(key, v); } }
/** * Creates and returns a new SimpleImmutableEntry holding current * mapping if this node holds a valid value, else null. * @return new entry or null */ AbstractMap.SimpleImmutableEntry createSnapshot() { Object v = getValidValue(); if (v == null) return null; return new AbstractMap.SimpleImmutableEntry(key, v); } }
public void clear() { for (ConcurrentSkipListMap.Node n = loNode(); isBeforeEnd(n); n = n.next) { if (n.getValidValue() != null) m.remove(n.key); } }
/** * Creates and returns a new SimpleImmutableEntry holding current * mapping if this node holds a valid value, else null. * @return new entry or null */ AbstractMap.SimpleImmutableEntry createSnapshot() { Object v = getValidValue(); if (v == null) return null; return new AbstractMap.SimpleImmutableEntry(key, v); } }
public boolean containsValue(Object value) { if (value == null) throw new NullPointerException(); for (ConcurrentSkipListMap.Node n = loNode(); isBeforeEnd(n); n = n.next) { Object v = n.getValidValue(); if (v != null && value.equals(v)) return true; } return false; }
public boolean containsValue(Object value) { if (value == null) throw new NullPointerException(); for (ConcurrentSkipListMap.Node n = loNode(); isBeforeEnd(n); n = n.next) { Object v = n.getValidValue(); if (v != null && value.equals(v)) return true; } return false; }
public void clear() { for (ConcurrentSkipListMap.Node n = loNode(); isBeforeEnd(n); n = n.next) { if (n.getValidValue() != null) m.remove(n.key); } }
public int size() { long count = 0; for (ConcurrentSkipListMap.Node n = loNode(); isBeforeEnd(n); n = n.next) { if (n.getValidValue() != null) ++count; } return count >= Integer.MAX_VALUE? Integer.MAX_VALUE : (int)count; }