Skip navigation links

Oracle® Coherence Java API Reference
Release 3.6.0.0

E15725-01


com.tangosol.util
Class SafeSortedMap.ViewMap

java.lang.Object
  extended by java.util.AbstractMap
      extended by com.tangosol.util.SafeSortedMap.ViewMap

All Implemented Interfaces:
Map, SortedMap
Enclosing class:
SafeSortedMap

protected class SafeSortedMap.ViewMap
extends AbstractMap
implements SortedMap

ViewMap provides a SortedMap view over a subset of the SafeSortedMap. A ViewMap may have an inclusive lower and/or an exclusive upper bound. <p/> For example, a ViewMap defined on an SafeSortedMap of Integer keys with lower bound 3 and upper bound 7 would contain any keys in the underlying SafeSortedMap in the range [3, 7).


Nested Class Summary
protected  class SafeSortedMap.ViewMap.EntryIterator
          An Iterator over the Entries backed by this ViewMap.
protected  class SafeSortedMap.ViewMap.EntrySet
          A Set of Entries backed by this ViewMap.

 

Nested classes/interfaces inherited from interface java.util.Map
Map.Entry

 

Field Summary
protected  Object m_oKeyLower
          The key that this ViewMap is (inclusively) lower-bounded by, or null for no lower-bound.
protected  Object m_oKeyUpper
          The key that this ViewMap is (exclusively) upper-bounded by, or null for no upper-bound

 

Constructor Summary
protected SafeSortedMap.ViewMap(Object oKeyLower, Object oKeyUpper)
          Create a new ViewMap over the SafeSortedMap bounded by the specified keys, or null for no-bound.

 

Method Summary
 Comparator comparator()
          Returns the comparator associated with this sorted map, or null if it uses its keys' natural ordering.
 boolean containsKey(Object oKey)
          Returns true if this map contains a mapping for the specified key.
 Set entrySet()
          Returns a set view of the mappings contained in this map.
 Object firstKey()
          Returns the first (lowest) key currently in this sorted map.
protected  SafeSortedMap.EntryNode firstNode()
          Return the first Node in this ViewMap, or null if there are none.
 Object get(Object oKey)
          Returns the value to which this map maps the specified key.
protected  Object getLowerBound()
          Return the lower bound of this ViewMap.
protected  Object getUpperBound()
          Return the upper bound of this ViewMap.
 SortedMap headMap(Object toKey)
          Returns a view of the portion of this sorted map whose keys are strictly less than toKey.
protected  boolean inRange(Object oKey)
          Is the specified key in the range represented by this ViewMap?
 Object lastKey()
          Returns the last (highest) key currently in this sorted map.
protected  SafeSortedMap.EntryNode lastNode()
          Return the last SkipNode in this ViewMap, or null if there are none.
 Object put(Object oKey, Object oValue)
          Associates the specified value with the specified key in this map (optional operation).
 Object remove(Object oKey)
          Removes the mapping for this key from this map if present (optional operation).
 SortedMap subMap(Object fromKey, Object toKey)
          Returns a view of the portion of this sorted map whose keys range from fromKey, inclusive, to toKey, exclusive.
 SortedMap tailMap(Object fromKey)
          Returns a view of the portion of this sorted map whose keys are greater than or equal to fromKey.

 

Methods inherited from class java.util.AbstractMap
clear, clone, containsValue, equals, hashCode, isEmpty, keySet, putAll, size, toString, values

 

Methods inherited from interface java.util.Map
clear, containsValue, equals, hashCode, isEmpty, keySet, putAll, size, values

 

Field Detail

m_oKeyLower

protected final Object m_oKeyLower
The key that this ViewMap is (inclusively) lower-bounded by, or null for no lower-bound.

m_oKeyUpper

protected final Object m_oKeyUpper
The key that this ViewMap is (exclusively) upper-bounded by, or null for no upper-bound

Constructor Detail

SafeSortedMap.ViewMap

protected SafeSortedMap.ViewMap(Object oKeyLower,
                                Object oKeyUpper)
Create a new ViewMap over the SafeSortedMap bounded by the specified keys, or null for no-bound.
Parameters:
oKeyLower - the (inclusive) lower-bound key, or null
oKeyUpper - the (exclusive) upper-bound key, or null

Method Detail

entrySet

public Set entrySet()
Returns a set view of the mappings contained in this map. Each element in this set is a Map.Entry. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. (If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined.) The set supports element removal, which removes the corresponding entry from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.
Specified by:
entrySet in interface Map
Specified by:
entrySet in class AbstractMap
Returns:
a set view of the mappings contained in this map.

put

public Object put(Object oKey,
                  Object oValue)
Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for this key, the old value is replaced.

This implementation always throws an UnsupportedOperationException.

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

get

public Object get(Object oKey)
Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key. A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

This implementation iterates over entrySet() searching for an entry with the specified key. If such an entry is found, the entry's value is returned. If the iteration terminates without finding such an entry, null is returned. Note that this implementation requires linear time in the size of the map; many implementations will override this method.

Specified by:
get in interface Map
Overrides:
get in class AbstractMap
Parameters:
oKey - key whose associated value is to be returned.
Returns:
the value to which this map maps the specified key.
See Also:
AbstractMap.containsKey(Object)

containsKey

public boolean containsKey(Object oKey)
Returns true if this map contains a mapping for the specified key.

This implementation iterates over entrySet() searching for an entry with the specified key. If such an entry is found, true is returned. If the iteration terminates without finding such an entry, false is returned. Note that this implementation requires linear time in the size of the map; many implementations will override this method.

Specified by:
containsKey in interface Map
Overrides:
containsKey in class AbstractMap
Parameters:
oKey - key whose presence in this map is to be tested.
Returns:
true if this map contains a mapping for the specified key.

remove

public Object remove(Object oKey)
Removes the mapping for this key from this map if present (optional operation).

This implementation iterates over entrySet() searching for an entry with the specified key. If such an entry is found, its value is obtained with its getValue operation, the entry is removed from the Collection (and the backing map) with the iterator's remove operation, and the saved value is returned. If the iteration terminates without finding such an entry, null is returned. Note that this implementation requires linear time in the size of the map; many implementations will override this method.

Note that this implementation throws an UnsupportedOperationException if the entrySet iterator does not support the remove method and this map contains a mapping for the specified key.

Specified by:
remove in interface Map
Overrides:
remove in class AbstractMap
Parameters:
oKey - key whose mapping is to be removed from the map.
Returns:
previous value associated with specified key, or null if there was no entry for key. (A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.)

comparator

public Comparator comparator()
Returns the comparator associated with this sorted map, or null if it uses its keys' natural ordering.
Specified by:
comparator in interface SortedMap
Returns:
the comparator associated with this sorted map, or null if it uses its keys' natural ordering.

subMap

public SortedMap subMap(Object fromKey,
                        Object toKey)
Returns a view of the portion of this sorted map whose keys range from fromKey, inclusive, to toKey, exclusive. (If fromKey and toKey are equal, the returned sorted map is empty.) The returned sorted map is backed by this sorted map, so changes in the returned sorted map are reflected in this sorted map, and vice-versa. The returned Map supports all optional map operations that this sorted map supports.

The map returned by this method will throw an IllegalArgumentException if the user attempts to insert a key outside the specified range.

Note: this method always returns a half-open range (which includes its low endpoint but not its high endpoint). If you need a closed range (which includes both endpoints), and the key type allows for calculation of the successor a given key, merely request the subrange from lowEndpoint to successor(highEndpoint). For example, suppose that m is a map whose keys are strings. The following idiom obtains a view containing all of the key-value mappings in m whose keys are between low and high, inclusive:

    Map sub = m.subMap(low, high+"\0");
A similarly technique can be used to generate an open range (which contains neither endpoint). The following idiom obtains a view containing all of the key-value mappings in m whose keys are between low and high, exclusive:
    Map sub = m.subMap(low+"\0", high);
Specified by:
subMap in interface SortedMap
Parameters:
fromKey - low endpoint (inclusive) of the subMap.
toKey - high endpoint (exclusive) of the subMap.
Returns:
a view of the specified range within this sorted map.

headMap

public SortedMap headMap(Object toKey)
Returns a view of the portion of this sorted map whose keys are strictly less than toKey. The returned sorted map is backed by this sorted map, so changes in the returned sorted map are reflected in this sorted map, and vice-versa. The returned map supports all optional map operations that this sorted map supports.

The map returned by this method will throw an IllegalArgumentException if the user attempts to insert a key outside the specified range.

Note: this method always returns a view that does not contain its (high) endpoint. If you need a view that does contain this endpoint, and the key type allows for calculation of the successor a given key, merely request a headMap bounded by successor(highEndpoint). For example, suppose that suppose that m is a map whose keys are strings. The following idiom obtains a view containing all of the key-value mappings in m whose keys are less than or equal to high:

    Map head = m.headMap(high+"\0");
Specified by:
headMap in interface SortedMap
Parameters:
toKey - high endpoint (exclusive) of the subMap.
Returns:
a view of the specified initial range of this sorted map.

tailMap

public SortedMap tailMap(Object fromKey)
Returns a view of the portion of this sorted map whose keys are greater than or equal to fromKey. The returned sorted map is backed by this sorted map, so changes in the returned sorted map are reflected in this sorted map, and vice-versa. The returned map supports all optional map operations that this sorted map supports.

The map returned by this method will throw an IllegalArgumentException if the user attempts to insert a key outside the specified range.

Note: this method always returns a view that contains its (low) endpoint. If you need a view that does not contain this endpoint, and the element type allows for calculation of the successor a given value, merely request a tailMap bounded by successor(lowEndpoint). For example, suppose that suppose that m is a map whose keys are strings. The following idiom obtains a view containing all of the key-value mappings in m whose keys are strictly greater than low:

    Map tail = m.tailMap(low+"\0");
Specified by:
tailMap in interface SortedMap
Parameters:
fromKey - low endpoint (inclusive) of the tailMap.
Returns:
a view of the specified final range of this sorted map.

firstKey

public Object firstKey()
Returns the first (lowest) key currently in this sorted map.
Specified by:
firstKey in interface SortedMap
Returns:
the first (lowest) key currently in this sorted map.

lastKey

public Object lastKey()
Returns the last (highest) key currently in this sorted map.
Specified by:
lastKey in interface SortedMap
Returns:
the last (highest) key currently in this sorted map.

getLowerBound

protected Object getLowerBound()
Return the lower bound of this ViewMap.
Returns:
the lower bound of this ViewMap

getUpperBound

protected Object getUpperBound()
Return the upper bound of this ViewMap.
Returns:
the upper bound of this ViewMap

inRange

protected boolean inRange(Object oKey)
Is the specified key in the range represented by this ViewMap?
Parameters:
oKey - the key to test for
Returns:
true iff the specified key is in the range represented by this ViewMap

firstNode

protected SafeSortedMap.EntryNode firstNode()
Return the first Node in this ViewMap, or null if there are none.
Returns:
the first Node or null if empty, or null

lastNode

protected SafeSortedMap.EntryNode lastNode()
Return the last SkipNode in this ViewMap, or null if there are none.
Returns:
the last SkipNode in this ViewMap, or null

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.6.0.0

E15725-01


Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.