/** * Save the state of the <tt>Map</tt> instance 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<K,V> n = findFirst(); n != null; n = n.next) { V v = n.getValidValue(); if (v != null) { s.writeObject(n.key); s.writeObject(v); } } s.writeObject(null); }
public boolean containsValue(Object value) { if (value == null) throw new NullPointerException(); for (ConcurrentSkipListMap.Node<K,V> n = firstNode(); isBeforeEnd(n); n = n.next) { V 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 value is <tt>null</tt>. */ public boolean containsValue(Object value) { if (value == null) throw new NullPointerException(); for (Node<K,V> n = findFirst(); n != null; n = n.next) { V v = n.getValidValue(); if (v != null && value.equals(v)) return true; } return false; }
/** * Return SnapshotEntry or key for results of findNear ofter screening * to ensure result is in given range. Needed by submaps. * @param kkey the key * @param rel the relation -- OR'ed combination of EQ, LT, GT * @param least minimum allowed key value * @param fence key greater than maximum allowed key value * @param keyOnly if true return key, else return SnapshotEntry * @return Key or Entry fitting relation, or <tt>null</tt> if no such */ Object getNear(K kkey, int rel, K least, K fence, boolean keyOnly) { K key = kkey; // Don't return keys less than least if ((rel & LT) == 0) { if (compare(key, least) < 0) { key = least; rel = rel | EQ; } } for (;;) { Node<K,V> n = findNear(key, rel); if (n == null || !inHalfOpenRange(n.key, least, fence)) return null; K k = n.key; V v = n.getValidValue(); if (v != null) return keyOnly? k : new SnapshotEntry<K,V>(k, v); } }
/** * Returns the number of elements 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<K,V> n = findFirst(); n != null; n = n.next) { if (n.getValidValue() != null) ++count; } return (count >= Integer.MAX_VALUE)? Integer.MAX_VALUE : (int)count; }
/** * Create and return a new SnapshotEntry holding current * mapping if this node holds a valid value, else null * @return new entry or null */ SnapshotEntry<K,V> createSnapshot() { V v = getValidValue(); if (v == null) return null; return new SnapshotEntry(key, v); } }
public void clear() { for (ConcurrentSkipListMap.Node<K,V> n = firstNode(); isBeforeEnd(n); n = n.next) { if (n.getValidValue() != null) m.remove(n.key); } }
public int size() { long count = 0; for (ConcurrentSkipListMap.Node<K,V> n = firstNode(); isBeforeEnd(n); n = n.next) { if (n.getValidValue() != null) ++count; } return count >= Integer.MAX_VALUE? Integer.MAX_VALUE : (int)count; }