SafeSortedMap.ViewMap

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 java.util.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.

put

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 java.util.Map

Overrides:

put in class java.util.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 java.lang.Object get(java.lang.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 java.util.Map

Overrides:

get in class java.util.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(java.lang.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 java.util.Map

Overrides:

containsKey in class java.util.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 java.lang.Object remove(java.lang.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 java.util.Map

Overrides:

remove in class java.util.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 java.util.Comparator comparator()

Returns the comparator associated with this sorted map, or null if it uses its keys' natural ordering.

Specified by:

comparator in interface java.util.SortedMap

Returns:

the comparator associated with this sorted map, or null if it uses its keys' natural ordering.

subMap

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 java.util.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 java.util.SortedMap headMap(java.lang.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 java.util.SortedMap

Parameters:

toKey - high endpoint (exclusive) of the subMap.

Returns:

a view of the specified initial range of this sorted map.

tailMap

public java.util.SortedMap tailMap(java.lang.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 java.util.SortedMap

Parameters:

fromKey - low endpoint (inclusive) of the tailMap.

Returns:

a view of the specified final range of this sorted map.

firstKey

public java.lang.Object firstKey()

Returns the first (lowest) key currently in this sorted map.

Specified by:

firstKey in interface java.util.SortedMap

Returns:

the first (lowest) key currently in this sorted map.

lastKey

public java.lang.Object lastKey()

Returns the last (highest) key currently in this sorted map.

Specified by:

lastKey in interface java.util.SortedMap

Returns:

the last (highest) key currently in this sorted map.

getLowerBound

protected java.lang.Object getLowerBound()

Return the lower bound of this ViewMap.

Returns:

the lower bound of this ViewMap

getUpperBound

protected java.lang.Object getUpperBound()

Return the upper bound of this ViewMap.

Returns:

the upper bound of this ViewMap

inRange

protected boolean inRange(java.lang.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