org.compass.core.util.backport.java.util.concurrent
Class ConcurrentSkipListMap.SubMap

java.lang.Object
  extended by java.util.AbstractMap
      extended by org.compass.core.util.backport.java.util.AbstractMap
          extended by org.compass.core.util.backport.java.util.concurrent.ConcurrentSkipListMap.SubMap
All Implemented Interfaces:
Serializable, Cloneable, Map, SortedMap, ConcurrentMap, ConcurrentNavigableMap, NavigableMap
Enclosing class:
ConcurrentSkipListMap

static final class ConcurrentSkipListMap.SubMap
extends AbstractMap
implements ConcurrentNavigableMap, Cloneable, Serializable

Submaps returned by ConcurrentSkipListMap submap operations represent a subrange of mappings of their underlying maps. Instances of this class support all methods of their underlying maps, differing in that mappings outside their range are ignored, and attempts to add mappings outside their ranges result in IllegalArgumentException. Instances of this class are constructed only using the subMap, headMap, and tailMap methods of their underlying maps.

See Also:
Serialized Form

Nested Class Summary
(package private)  class ConcurrentSkipListMap.SubMap.SubMapEntryIterator
           
(package private)  class ConcurrentSkipListMap.SubMap.SubMapIter
          Variant of main Iter class to traverse through submaps.
(package private)  class ConcurrentSkipListMap.SubMap.SubMapKeyIterator
           
(package private)  class ConcurrentSkipListMap.SubMap.SubMapValueIterator
           
 
Nested classes/interfaces inherited from class org.compass.core.util.backport.java.util.AbstractMap
AbstractMap.SimpleEntry, AbstractMap.SimpleImmutableEntry
 
Constructor Summary
ConcurrentSkipListMap.SubMap(ConcurrentSkipListMap map, Object fromKey, boolean fromInclusive, Object toKey, boolean toInclusive, boolean isDescending)
          Creates a new submap, initializing all fields
 
Method Summary
 Map.Entry ceilingEntry(Object key)
          Returns a key-value mapping associated with the least key greater than or equal to the given key, or null if there is no such key.
 Object ceilingKey(Object key)
          Returns the least key greater than or equal to the given key, or null if there is no such key.
 void clear()
           
 Comparator comparator()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 NavigableSet descendingKeySet()
          Returns a reverse order NavigableSet view of the keys contained in this map.
 NavigableMap descendingMap()
          Returns a reverse order view of the mappings contained in this map.
(package private)  Iterator entryIterator()
           
 Set entrySet()
           
 Map.Entry firstEntry()
          Returns a key-value mapping associated with the least key in this map, or null if the map is empty.
 Object firstKey()
           
 Map.Entry floorEntry(Object key)
          Returns a key-value mapping associated with the greatest key less than or equal to the given key, or null if there is no such key.
 Object floorKey(Object key)
          Returns the greatest key less than or equal to the given key, or null if there is no such key.
 Object get(Object key)
           
 SortedMap headMap(Object toKey)
           Equivalent to headMap(toKey, false).
 NavigableMap headMap(Object toKey, boolean inclusive)
          Returns a view of the portion of this map whose keys are less than (or equal to, if inclusive is true) toKey.
 Map.Entry higherEntry(Object key)
          Returns a key-value mapping associated with the least key strictly greater than the given key, or null if there is no such key.
 Object higherKey(Object key)
          Returns the least key strictly greater than the given key, or null if there is no such key.
 boolean isEmpty()
           
(package private)  Iterator keyIterator()
           
 Set keySet()
          
 Map.Entry lastEntry()
          Returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.
 Object lastKey()
           
 Map.Entry lowerEntry(Object key)
          Returns a key-value mapping associated with the greatest key strictly less than the given key, or null if there is no such key.
 Object lowerKey(Object key)
          Returns the greatest key strictly less than the given key, or null if there is no such key.
 NavigableSet navigableKeySet()
          Returns a NavigableSet view of the keys contained in this map.
 Map.Entry pollFirstEntry()
          Removes and returns a key-value mapping associated with the least key in this map, or null if the map is empty.
 Map.Entry pollLastEntry()
          Removes and returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.
 Object put(Object key, Object value)
           
 Object putIfAbsent(Object key, Object value)
          If the specified key is not already associated with a value, associate it with the given value.
 Object remove(Object key)
           
 boolean remove(Object key, Object value)
          Removes the entry for a key only if currently mapped to a given value.
 Object replace(Object key, Object value)
          Replaces the entry for a key only if currently mapped to some value.
 boolean replace(Object key, Object oldValue, Object newValue)
          Replaces the entry for a key only if currently mapped to a given value.
 int size()
           
 NavigableMap subMap(Object fromKey, boolean fromInclusive, Object toKey, boolean toInclusive)
          Returns a view of the portion of this map whose keys range from fromKey to toKey.
 SortedMap subMap(Object fromKey, Object toKey)
           Equivalent to subMap(fromKey, true, toKey, false).
 SortedMap tailMap(Object fromKey)
           Equivalent to tailMap(fromKey, true).
 NavigableMap tailMap(Object fromKey, boolean inclusive)
          Returns a view of the portion of this map whose keys are greater than (or equal to, if inclusive is true) fromKey.
(package private)  Iterator valueIterator()
           
 Collection values()
           
 
Methods inherited from class java.util.AbstractMap
clone, equals, hashCode, putAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConcurrentSkipListMap.SubMap

ConcurrentSkipListMap.SubMap(ConcurrentSkipListMap map,
                             Object fromKey,
                             boolean fromInclusive,
                             Object toKey,
                             boolean toInclusive,
                             boolean isDescending)
Creates a new submap, initializing all fields

Method Detail

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map
Overrides:
containsKey in class AbstractMap

get

public Object get(Object key)
Specified by:
get in interface Map
Overrides:
get in class AbstractMap

put

public Object put(Object key,
                  Object value)
Specified by:
put in interface Map
Overrides:
put in class AbstractMap

remove

public Object remove(Object key)
Specified by:
remove in interface Map
Overrides:
remove in class AbstractMap

size

public int size()
Specified by:
size in interface Map
Overrides:
size in class AbstractMap

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map
Overrides:
isEmpty in class AbstractMap

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map
Overrides:
containsValue in class AbstractMap

clear

public void clear()
Specified by:
clear in interface Map
Overrides:
clear in class AbstractMap

putIfAbsent

public Object putIfAbsent(Object key,
                          Object value)
Description copied from interface: ConcurrentMap
If the specified key is not already associated with a value, associate it with the given value. This is equivalent to
   if (!map.containsKey(key))
       return map.put(key, value);
   else
       return map.get(key);
except that the action is performed atomically.

Specified by:
putIfAbsent in interface ConcurrentMap
Parameters:
key - key with which the specified value is to be associated
value - value to be associated with the specified key
Returns:
the previous value associated with the specified key, or null if there was no mapping for the key. (A null return can also indicate that the map previously associated null with the key, if the implementation supports null values.)

remove

public boolean remove(Object key,
                      Object value)
Description copied from interface: ConcurrentMap
Removes the entry for a key only if currently mapped to a given value. This is equivalent to
   if (map.containsKey(key) && map.get(key).equals(value)) {
       map.remove(key);
       return true;
   } else return false;
except that the action is performed atomically.

Specified by:
remove in interface ConcurrentMap
Parameters:
key - key with which the specified value is associated
value - value expected to be associated with the specified key
Returns:
true if the value was removed

replace

public boolean replace(Object key,
                       Object oldValue,
                       Object newValue)
Description copied from interface: ConcurrentMap
Replaces the entry for a key only if currently mapped to a given value. This is equivalent to
   if (map.containsKey(key) && map.get(key).equals(oldValue)) {
       map.put(key, newValue);
       return true;
   } else return false;
except that the action is performed atomically.

Specified by:
replace in interface ConcurrentMap
Parameters:
key - key with which the specified value is associated
oldValue - value expected to be associated with the specified key
newValue - value to be associated with the specified key
Returns:
true if the value was replaced

replace

public Object replace(Object key,
                      Object value)
Description copied from interface: ConcurrentMap
Replaces the entry for a key only if currently mapped to some value. This is equivalent to
   if (map.containsKey(key)) {
       return map.put(key, value);
   } else return null;
except that the action is performed atomically.

Specified by:
replace in interface ConcurrentMap
Parameters:
key - key with which the specified value is associated
value - value to be associated with the specified key
Returns:
the previous value associated with the specified key, or null if there was no mapping for the key. (A null return can also indicate that the map previously associated null with the key, if the implementation supports null values.)

comparator

public Comparator comparator()
Specified by:
comparator in interface SortedMap

subMap

public NavigableMap subMap(Object fromKey,
                           boolean fromInclusive,
                           Object toKey,
                           boolean toInclusive)
Description copied from interface: NavigableMap
Returns a view of the portion of this map whose keys range from fromKey to toKey. If fromKey and toKey are equal, the returned map is empty unless fromExclusive and toExclusive are both true. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.

The returned map will throw an IllegalArgumentException on an attempt to insert a key outside of its range, or to construct a submap either of whose endpoints lie outside its range.

Specified by:
subMap in interface ConcurrentNavigableMap
Specified by:
subMap in interface NavigableMap
Parameters:
fromKey - low endpoint of the keys in the returned map
fromInclusive - true if the low endpoint is to be included in the returned view
toKey - high endpoint of the keys in the returned map
toInclusive - true if the high endpoint is to be included in the returned view
Returns:
a view of the portion of this map whose keys range from fromKey to toKey

headMap

public NavigableMap headMap(Object toKey,
                            boolean inclusive)
Description copied from interface: NavigableMap
Returns a view of the portion of this map whose keys are less than (or equal to, if inclusive is true) toKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.

The returned map will throw an IllegalArgumentException on an attempt to insert a key outside its range.

Specified by:
headMap in interface ConcurrentNavigableMap
Specified by:
headMap in interface NavigableMap
Parameters:
toKey - high endpoint of the keys in the returned map
inclusive - true if the high endpoint is to be included in the returned view
Returns:
a view of the portion of this map whose keys are less than (or equal to, if inclusive is true) toKey

tailMap

public NavigableMap tailMap(Object fromKey,
                            boolean inclusive)
Description copied from interface: NavigableMap
Returns a view of the portion of this map whose keys are greater than (or equal to, if inclusive is true) fromKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.

The returned map will throw an IllegalArgumentException on an attempt to insert a key outside its range.

Specified by:
tailMap in interface ConcurrentNavigableMap
Specified by:
tailMap in interface NavigableMap
Parameters:
fromKey - low endpoint of the keys in the returned map
inclusive - true if the low endpoint is to be included in the returned view
Returns:
a view of the portion of this map whose keys are greater than (or equal to, if inclusive is true) fromKey

subMap

public SortedMap subMap(Object fromKey,
                        Object toKey)
Description copied from interface: NavigableMap

Equivalent to subMap(fromKey, true, toKey, false).

Specified by:
subMap in interface SortedMap
Specified by:
subMap in interface ConcurrentNavigableMap
Specified by:
subMap in interface NavigableMap

headMap

public SortedMap headMap(Object toKey)
Description copied from interface: NavigableMap

Equivalent to headMap(toKey, false).

Specified by:
headMap in interface SortedMap
Specified by:
headMap in interface ConcurrentNavigableMap
Specified by:
headMap in interface NavigableMap

tailMap

public SortedMap tailMap(Object fromKey)
Description copied from interface: NavigableMap

Equivalent to tailMap(fromKey, true).

Specified by:
tailMap in interface SortedMap
Specified by:
tailMap in interface ConcurrentNavigableMap
Specified by:
tailMap in interface NavigableMap

descendingMap

public NavigableMap descendingMap()
Description copied from interface: ConcurrentNavigableMap
Returns a reverse order view of the mappings contained in this map. The descending map is backed by this map, so changes to the map are reflected in the descending map, and vice-versa.

The returned map has an ordering equivalent to Collections.reverseOrder(comparator()). The expression m.descendingMap().descendingMap() returns a view of m essentially equivalent to m.

Specified by:
descendingMap in interface ConcurrentNavigableMap
Specified by:
descendingMap in interface NavigableMap
Returns:
a reverse order view of this map

ceilingEntry

public Map.Entry ceilingEntry(Object key)
Description copied from interface: NavigableMap
Returns a key-value mapping associated with the least key greater than or equal to the given key, or null if there is no such key.

Specified by:
ceilingEntry in interface NavigableMap
Parameters:
key - the key
Returns:
an entry with the least key greater than or equal to key, or null if there is no such key

ceilingKey

public Object ceilingKey(Object key)
Description copied from interface: NavigableMap
Returns the least key greater than or equal to the given key, or null if there is no such key.

Specified by:
ceilingKey in interface NavigableMap
Parameters:
key - the key
Returns:
the least key greater than or equal to key, or null if there is no such key

lowerEntry

public Map.Entry lowerEntry(Object key)
Description copied from interface: NavigableMap
Returns a key-value mapping associated with the greatest key strictly less than the given key, or null if there is no such key.

Specified by:
lowerEntry in interface NavigableMap
Parameters:
key - the key
Returns:
an entry with the greatest key less than key, or null if there is no such key

lowerKey

public Object lowerKey(Object key)
Description copied from interface: NavigableMap
Returns the greatest key strictly less than the given key, or null if there is no such key.

Specified by:
lowerKey in interface NavigableMap
Parameters:
key - the key
Returns:
the greatest key less than key, or null if there is no such key

floorEntry

public Map.Entry floorEntry(Object key)
Description copied from interface: NavigableMap
Returns a key-value mapping associated with the greatest key less than or equal to the given key, or null if there is no such key.

Specified by:
floorEntry in interface NavigableMap
Parameters:
key - the key
Returns:
an entry with the greatest key less than or equal to key, or null if there is no such key

floorKey

public Object floorKey(Object key)
Description copied from interface: NavigableMap
Returns the greatest key less than or equal to the given key, or null if there is no such key.

Specified by:
floorKey in interface NavigableMap
Parameters:
key - the key
Returns:
the greatest key less than or equal to key, or null if there is no such key

higherEntry

public Map.Entry higherEntry(Object key)
Description copied from interface: NavigableMap
Returns a key-value mapping associated with the least key strictly greater than the given key, or null if there is no such key.

Specified by:
higherEntry in interface NavigableMap
Parameters:
key - the key
Returns:
an entry with the least key greater than key, or null if there is no such key

higherKey

public Object higherKey(Object key)
Description copied from interface: NavigableMap
Returns the least key strictly greater than the given key, or null if there is no such key.

Specified by:
higherKey in interface NavigableMap
Parameters:
key - the key
Returns:
the least key greater than key, or null if there is no such key

firstKey

public Object firstKey()
Specified by:
firstKey in interface SortedMap

lastKey

public Object lastKey()
Specified by:
lastKey in interface SortedMap

firstEntry

public Map.Entry firstEntry()
Description copied from interface: NavigableMap
Returns a key-value mapping associated with the least key in this map, or null if the map is empty.

Specified by:
firstEntry in interface NavigableMap
Returns:
an entry with the least key, or null if this map is empty

lastEntry

public Map.Entry lastEntry()
Description copied from interface: NavigableMap
Returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.

Specified by:
lastEntry in interface NavigableMap
Returns:
an entry with the greatest key, or null if this map is empty

pollFirstEntry

public Map.Entry pollFirstEntry()
Description copied from interface: NavigableMap
Removes and returns a key-value mapping associated with the least key in this map, or null if the map is empty.

Specified by:
pollFirstEntry in interface NavigableMap
Returns:
the removed first entry of this map, or null if this map is empty

pollLastEntry

public Map.Entry pollLastEntry()
Description copied from interface: NavigableMap
Removes and returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.

Specified by:
pollLastEntry in interface NavigableMap
Returns:
the removed last entry of this map, or null if this map is empty

keySet

public Set keySet()
Description copied from class: AbstractMap

Specified by:
keySet in interface Map
Specified by:
keySet in interface ConcurrentNavigableMap
Overrides:
keySet in class AbstractMap
Returns:
a navigable set view of the keys in this map

navigableKeySet

public NavigableSet navigableKeySet()
Description copied from interface: ConcurrentNavigableMap
Returns a NavigableSet view of the keys contained in this map. The set's iterator returns the keys in ascending order. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

The view's iterator is a "weakly consistent" iterator that will never throw ConcurrentModificationException, and guarantees to traverse elements as they existed upon construction of the iterator, and may (but is not guaranteed to) reflect any modifications subsequent to construction.

Specified by:
navigableKeySet in interface ConcurrentNavigableMap
Specified by:
navigableKeySet in interface NavigableMap
Returns:
a navigable set view of the keys in this map

values

public Collection values()
Specified by:
values in interface Map
Overrides:
values in class AbstractMap

entrySet

public Set entrySet()
Specified by:
entrySet in interface Map
Specified by:
entrySet in class AbstractMap

descendingKeySet

public NavigableSet descendingKeySet()
Description copied from interface: ConcurrentNavigableMap
Returns a reverse order NavigableSet view of the keys contained in this map. The set's iterator returns the keys in descending order. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

The view's iterator is a "weakly consistent" iterator that will never throw ConcurrentModificationException, and guarantees to traverse elements as they existed upon construction of the iterator, and may (but is not guaranteed to) reflect any modifications subsequent to construction.

Specified by:
descendingKeySet in interface ConcurrentNavigableMap
Specified by:
descendingKeySet in interface NavigableMap
Returns:
a reverse order navigable set view of the keys in this map

keyIterator

Iterator keyIterator()

valueIterator

Iterator valueIterator()

entryIterator

Iterator entryIterator()


Copyright (c) 2004-2006 The Compass Project.