java.util
Class TreeMap.SubMap

java.lang.Object
  extended byjava.util.AbstractMap
      extended byjava.util.TreeMap.SubMap
All Implemented Interfaces:
Map, Serializable, SortedMap
Enclosing class:
TreeMap

private class TreeMap.SubMap
extends AbstractMap
implements SortedMap, Serializable


Nested Class Summary
private  class TreeMap.SubMap.EntrySetView
           
 
Nested classes inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry
 
Nested classes inherited from class java.util.Map
Map.Entry
 
Field Summary
private  Set entrySet
           
private  Object fromKey
           
private  boolean fromStart
          fromKey is significant only if fromStart is false.
private static long serialVersionUID
           
private  boolean toEnd
          fromKey is significant only if fromStart is false.
private  Object toKey
           
 
Fields inherited from class java.util.AbstractMap
keySet, values
 
Constructor Summary
(package private) TreeMap.SubMap(boolean fromStart, Object fromKey, boolean toEnd, Object toKey)
           
(package private) TreeMap.SubMap(Object key, boolean headMap)
           
(package private) TreeMap.SubMap(Object fromKey, Object toKey)
           
 
Method Summary
 Comparator comparator()
          Returns the comparator associated with this sorted map, or null if it uses its keys' natural ordering.
 boolean containsKey(Object key)
          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.
 Object get(Object key)
          Returns the value to which this map maps the specified key.
 SortedMap headMap(Object toKey)
          Returns a view of the portion of this sorted map whose keys are strictly less than toKey.
private  boolean inRange(Object key)
           
private  boolean inRange2(Object key)
           
 boolean isEmpty()
          Returns true if this map contains no key-value mappings.
 Object lastKey()
          Returns the last (highest) key currently in this sorted map.
 Object put(Object key, Object value)
          Associates the specified value with the specified key in this map (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, keySet, putAll, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsValue, equals, hashCode, keySet, putAll, remove, size, values
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

fromStart

private boolean fromStart
fromKey is significant only if fromStart is false. Similarly, toKey is significant only if toStart is false.


toEnd

private boolean toEnd
fromKey is significant only if fromStart is false. Similarly, toKey is significant only if toStart is false.


fromKey

private Object fromKey

toKey

private Object toKey

entrySet

private transient Set entrySet
Constructor Detail

TreeMap.SubMap

TreeMap.SubMap(Object fromKey,
               Object toKey)

TreeMap.SubMap

TreeMap.SubMap(Object key,
               boolean headMap)

TreeMap.SubMap

TreeMap.SubMap(boolean fromStart,
               Object fromKey,
               boolean toEnd,
               Object toKey)
Method Detail

isEmpty

public boolean isEmpty()
Description copied from interface: Map
Returns true if this map contains no key-value mappings.

Specified by:
isEmpty in interface Map
Overrides:
isEmpty in class AbstractMap
Returns:
true if this map contains no key-value mappings.

containsKey

public boolean containsKey(Object key)
Description copied from interface: Map
Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains at a mapping for a key k such that (key==null ? k==null : key.equals(k)). (There can be at most one such mapping.)

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

get

public Object get(Object key)
Description copied from interface: Map
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.

More formally, if this map contains a mapping from a key k to a value v such that (key==null ? k==null : key.equals(k)), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

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

put

public Object put(Object key,
                  Object value)
Description copied from interface: Map
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 by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.))

Specified by:
put in interface Map
Overrides:
put in class AbstractMap
Parameters:
key - key with which the specified value is to be associated.
value - 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.)

comparator

public Comparator comparator()
Description copied from interface: SortedMap
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.

firstKey

public Object firstKey()
Description copied from interface: SortedMap
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()
Description copied from interface: SortedMap
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.

entrySet

public Set entrySet()
Description copied from interface: Map
Returns a set view of the mappings contained in this map. Each element in the returned 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 mapping 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.

subMap

public SortedMap subMap(Object fromKey,
                        Object toKey)
Description copied from interface: SortedMap
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)
Description copied from interface: SortedMap
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)
Description copied from interface: SortedMap
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.

inRange

private boolean inRange(Object key)

inRange2

private boolean inRange2(Object key)