/** * Returns a view of the portion of this map whose keys range from * <tt>fromKey</tt>, inclusive, to <tt>toKey</tt>, exclusive. (If * <tt>fromKey</tt> and <tt>toKey</tt> are equal, the returned sorted map * is empty.) The returned sorted map is backed by this map, so changes * in the returned sorted map are reflected in this map, and vice-versa. * @param fromKey low endpoint (inclusive) of the subMap. * @param toKey high endpoint (exclusive) of the subMap. * * @return a view of the portion of this map whose keys range from * <tt>fromKey</tt>, inclusive, to <tt>toKey</tt>, exclusive. * * @throws ClassCastException if <tt>fromKey</tt> and <tt>toKey</tt> * cannot be compared to one another using this map's comparator * (or, if the map has no comparator, using natural ordering). * @throws IllegalArgumentException if <tt>fromKey</tt> is greater than * <tt>toKey</tt>. * @throws NullPointerException if <tt>fromKey</tt> or <tt>toKey</tt> is * <tt>null</tt>. */ public ConcurrentNavigableMap<K,V> subMap(K fromKey, K toKey) { if (fromKey == null || toKey == null) throw new NullPointerException(); return new ConcurrentSkipListSubMap(this, fromKey, toKey); }
public K firstKey() { ConcurrentSkipListMap.Node<K,V> n = firstNode(); if (isBeforeEnd(n)) return n.key; else throw new NoSuchElementException(); }
void checkKey(K key) throws IllegalArgumentException { if (!inHalfOpenRange(key)) throw new IllegalArgumentException("key out of range"); }
/** * Returns a view of the portion of this map whose keys are * greater than or equal to <tt>fromKey</tt>. The returned sorted * map is backed by this map, so changes in the returned sorted * map are reflected in this map, and vice-versa. * @param fromKey low endpoint (inclusive) of the tailMap. * @return a view of the portion of this map whose keys are * greater than or equal to <tt>fromKey</tt>. * @throws ClassCastException if <tt>fromKey</tt> is not * compatible with this map's comparator (or, if the map has no * comparator, if <tt>fromKey</tt> does not implement * <tt>Comparable</tt>). * @throws NullPointerException if <tt>fromKey</tt> is <tt>null</tt>. */ public ConcurrentNavigableMap<K,V> tailMap(K fromKey) { if (fromKey == null) throw new NullPointerException(); return new ConcurrentSkipListSubMap(this, fromKey, null); }
/** * Returns a view of the portion of this map whose keys are * strictly less than <tt>toKey</tt>. The returned sorted map is * backed by this map, so changes in the returned sorted map are * reflected in this map, and vice-versa. * @param toKey high endpoint (exclusive) of the headMap. * @return a view of the portion of this map whose keys are * strictly less than <tt>toKey</tt>. * * @throws ClassCastException if <tt>toKey</tt> is not compatible * with this map's comparator (or, if the map has no comparator, * if <tt>toKey</tt> does not implement <tt>Comparable</tt>). * @throws NullPointerException if <tt>toKey</tt> is <tt>null</tt>. */ public ConcurrentNavigableMap<K,V> headMap(K toKey) { if (toKey == null) throw new NullPointerException(); return new ConcurrentSkipListSubMap(this, null, toKey); }
public V replace(K key, V value) { checkKey(key); return m.replace(key, value); }
public boolean replace(K key, V oldValue, V newValue) { checkKey(key); return m.replace(key, oldValue, newValue); }
public V putIfAbsent(K key, V value) { checkKey(key); return m.putIfAbsent(key, value); }
public boolean remove(Object key, Object value) { K k = (K)key; return inHalfOpenRange(k) && m.remove(k, value); }
public boolean containsKey(Object key) { K k = (K)key; return inHalfOpenRange(k) && m.containsKey(k); }
public boolean isEmpty() { return !isBeforeEnd(firstNode()); }
public V remove(Object key) { K k = (K)key; return (!inHalfOpenRange(k))? null : m.remove(k); }
public V get(Object key) { K k = (K)key; return ((!inHalfOpenRange(k)) ? null : m.get(k)); }
public V put(K key, V value) { checkKey(key); return m.put(key, value); }
public ConcurrentNavigableMap<K,V> tailMap(K fromKey) { if (fromKey == null) throw new NullPointerException(); if (!inOpenRange(fromKey)) throw new IllegalArgumentException("key out of range"); return new ConcurrentSkipListSubMap(m, fromKey, fence); }
public ConcurrentNavigableMap<K,V> headMap(K toKey) { if (toKey == null) throw new NullPointerException(); if (!inOpenRange(toKey)) throw new IllegalArgumentException("key out of range"); return new ConcurrentSkipListSubMap(m, least, toKey); }
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; } }
public ConcurrentNavigableMap<K,V> subMap(K fromKey, K toKey) { if (fromKey == null || toKey == null) throw new NullPointerException(); if (!inOpenRange(fromKey) || !inOpenRange(toKey)) throw new IllegalArgumentException("key out of range"); return new ConcurrentSkipListSubMap(m, fromKey, toKey); }
public void clear() { for (ConcurrentSkipListMap.Node<K,V> n = firstNode(); isBeforeEnd(n); n = n.next) { if (n.getValidValue() != null) m.remove(n.key); } }
public K lastKey() { ConcurrentSkipListMap.Node<K,V> n = lastNode(); if (n != null) { K last = n.key; if (inHalfOpenRange(last)) return last; } throw new NoSuchElementException(); }