public void clear() { for (ConcurrentSkipListMap.Node<K,V> n = firstNode(); isBeforeEnd(n); n = n.next) { if (n.getValidValue() != null) m.remove(n.key); } }
/** * Creates a new set with the same contents as the given set. * * @param s the set */ public ConcurrentReferenceHashSet(Set<? extends E> s) { super(new ConcurrentReferenceHashMap<E, Object>()); addAll(s); } }
final Object newKeyReference(K key, ReferenceType keyType, ReferenceQueue<Object> refQueue) { if (keyType == ReferenceType.WEAK) return new WeakKeyReference<K>(key, hash, refQueue); if (keyType == ReferenceType.SOFT) return new SoftKeyReference<K>(key, hash, refQueue); return key; }
/** * Remove and return the first object in the queue. * * @return Dequeued object. * * @exception EmptyCollectionException The queue is empty. */ public E remove() throws EmptyCollectionException { if (isEmpty()) throw new EmptyCollectionException(); return removeFirst(); }
public Map.Entry<K,V> lastEntry() { for (;;) { ConcurrentSkipListMap.Node<K,V> n = lastNode(); if (n == null || !inHalfOpenRange(n.key)) return null; Map.Entry<K,V> e = n.createSnapshot(); if (e != null) return e; } }
/** * {@inheritDoc} * * @throws NullPointerException if the specified key is null */ public boolean remove(Object key, Object value) { int hash = hashOf(key); if (value == null) return false; return segmentFor(hash).remove(key, hash, value, false) != null; }
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; }
public Map.Entry<K,V> firstEntry() { for (;;) { ConcurrentSkipListMap.Node<K,V> n = firstNode(); if (!isBeforeEnd(n)) return null; Map.Entry<K,V> e = n.createSnapshot(); if (e != null) return e; } }
/** * Tests if the specified object is a key in this table. * * @param key possible key * @return <tt>true</tt> if and only if the specified object * is a key in this table, as determined by the * <tt>equals</tt> method; <tt>false</tt> otherwise. * @throws NullPointerException if the specified key is null */ public boolean containsKey(Object key) { int hash = hashOf(key); return segmentFor(hash).containsKey(key, hash); }
public boolean remove(Object key, Object value) { K k = (K)key; return inHalfOpenRange(k) && m.remove(k, value); }
public V get(Object key) { K k = (K)key; return ((!inHalfOpenRange(k)) ? null : m.get(k)); }
final Object newValueReference(V value, ReferenceType valueType, ReferenceQueue<Object> refQueue) { if (valueType == ReferenceType.WEAK) return new WeakValueReference<V>(value, keyRef, hash, refQueue); if (valueType == ReferenceType.SOFT) return new SoftValueReference<V>(value, keyRef, hash, refQueue); return value; }
/** * 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); } }
@Override public Set<Entry<K,V>> entrySet() { processQueue(); return new EntrySet(); }
public boolean containsKey(Object key) { K k = (K)key; return inHalfOpenRange(k) && m.containsKey(k); }
public V putIfAbsent(K key, V value) { checkKey(key); return m.putIfAbsent(key, value); }