Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

java.util
Class TreeMap.SubMap  view TreeMap.SubMap download TreeMap.SubMap.java

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

private final class TreeMap.SubMap
extends AbstractMap
implements SortedMap

Implementation of subMap(Object, Object) 55 and other map ranges. This class provides a view of a portion of the original backing map, and throws java.lang.IllegalArgumentException for attempts to access beyond that range.


Nested Class Summary
 
Nested classes inherited from class java.util.AbstractMap
AbstractMap.BasicMapEntry
 
Nested classes inherited from class java.util.Map
Map.Entry
 
Field Summary
private  Set entries
          The cache for entrySet() 55 .
(package private)  java.lang.Object maxKey
          The upper range of this view, exclusive, or nil for unbounded.
(package private)  java.lang.Object minKey
          The lower range of this view, inclusive, or nil for unbounded.
 
Fields inherited from class java.util.AbstractMap
ENTRIES, keys, KEYS, values, VALUES
 
Constructor Summary
(package private) TreeMap.SubMap(java.lang.Object minKey, java.lang.Object maxKey)
          Create a SubMap representing the elements between minKey (inclusive) and maxKey (exclusive).
 
Method Summary
 void clear()
          Remove all entries from this Map (optional operation).
 Comparator comparator()
          Returns the comparator used in sorting this map, or null if it is the keys' natural ordering.
 boolean containsKey(java.lang.Object key)
          Returns true if this contains a mapping for the given key.
 boolean containsValue(java.lang.Object value)
          Returns true if this contains at least one mapping with the given value.
 Set entrySet()
          Returns a set view of the mappings in this Map.
 java.lang.Object firstKey()
          Returns the first (lowest sorted) key in the map.
 java.lang.Object get(java.lang.Object key)
          Returns the value mapped by the given key.
 SortedMap headMap(java.lang.Object toKey)
          Returns a view of the portion of the map strictly less than toKey.
(package private)  boolean keyInRange(java.lang.Object key)
          Check if "key" is in within the range bounds for this SubMap.
 Set keySet()
          Returns a set view of the keys in this Map.
 java.lang.Object lastKey()
          Returns the last (highest sorted) key in the map.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associates the given key to the given value (optional operation).
 java.lang.Object remove(java.lang.Object key)
          Removes the mapping for this key if present (optional operation).
 int size()
          Returns the number of key-value mappings in the map.
 SortedMap subMap(java.lang.Object fromKey, java.lang.Object toKey)
          Returns a view of the portion of the map greater than or equal to fromKey, and strictly less than toKey.
 SortedMap tailMap(java.lang.Object fromKey)
          Returns a view of the portion of the map greater than or equal to fromKey.
 Collection values()
          Returns a collection (or bag) view of the values in this Map.
 
Methods inherited from class java.util.AbstractMap
clone, equals, equals, hashCode, hashCode, isEmpty, putAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode, isEmpty, putAll
 

Field Detail

minKey

final java.lang.Object minKey
The lower range of this view, inclusive, or nil for unbounded. Package visible for use by nested classes.


maxKey

final java.lang.Object maxKey
The upper range of this view, exclusive, or nil for unbounded. Package visible for use by nested classes.


entries

private Set entries
The cache for entrySet() 55 .

Constructor Detail

TreeMap.SubMap

TreeMap.SubMap(java.lang.Object minKey,
               java.lang.Object maxKey)
Create a SubMap representing the elements between minKey (inclusive) and maxKey (exclusive). If minKey is nil, SubMap has no lower bound (headMap). If maxKey is nil, the SubMap has no upper bound (tailMap).

Method Detail

keyInRange

boolean keyInRange(java.lang.Object key)
Check if "key" is in within the range bounds for this SubMap. The lower ("from") SubMap range is inclusive, and the upper ("to") bound is exclusive. Package visible for use by nested classes.


clear

public void clear()
Description copied from interface: Map
Remove all entries from this Map (optional operation).

Specified by:
clear in interface Map
Overrides:
clear in class AbstractMap

comparator

public Comparator comparator()
Description copied from interface: SortedMap
Returns the comparator used in sorting this map, or null if it is the keys' natural ordering.

Specified by:
comparator in interface SortedMap

containsKey

public boolean containsKey(java.lang.Object key)
Description copied from interface: Map
Returns true if this contains a mapping for the given key.

Specified by:
containsKey in interface Map
Overrides:
containsKey in class AbstractMap

containsValue

public boolean containsValue(java.lang.Object value)
Description copied from interface: Map
Returns true if this contains at least one mapping with the given value. In other words, returns true if a value v exists where (value == null ? v == null : value.equals(v)). This usually requires linear time.

Specified by:
containsValue in interface Map
Overrides:
containsValue in class AbstractMap

entrySet

public Set entrySet()
Description copied from interface: Map
Returns a set view of the mappings in this Map. Each element in the set is a Map.Entry. The set is backed by the map, so that changes in one show up in the other. Modifications made while an iterator is in progress cause undefined behavior. If the set supports removal, these methods remove the underlying mapping from the map: Iterator.remove, Set.remove, removeAll, retainAll, and clear. Element addition, via add or addAll, is not supported via this set.

Specified by:
entrySet in interface Map
Specified by:
entrySet in class AbstractMap

firstKey

public java.lang.Object firstKey()
Description copied from interface: SortedMap
Returns the first (lowest sorted) key in the map.

Specified by:
firstKey in interface SortedMap

get

public java.lang.Object get(java.lang.Object key)
Description copied from interface: Map
Returns the value mapped by the given key. Returns null if there is no mapping. However, in Maps that accept null values, you must rely on containsKey to determine if a mapping exists.

Specified by:
get in interface Map
Overrides:
get in class AbstractMap

headMap

public SortedMap headMap(java.lang.Object toKey)
Description copied from interface: SortedMap
Returns a view of the portion of the map strictly less than toKey. The view is backed by this map, so changes in one show up in the other. The submap supports all optional operations of the original.

The returned map throws an IllegalArgumentException any time a key is used which is out of the range of toKey. Note that the endpoint, toKey, is not included; if you want this value to be included, pass its successor object in to toKey. For example, for Integers, you could request headMap(new Integer(limit.intValue() + 1)).

Specified by:
headMap in interface SortedMap

keySet

public Set keySet()
Description copied from interface: Map
Returns a set view of the keys in this Map. The set is backed by the map, so that changes in one show up in the other. Modifications made while an iterator is in progress cause undefined behavior. If the set supports removal, these methods remove the underlying mapping from the map: Iterator.remove, Set.remove, removeAll, retainAll, and clear. Element addition, via add or addAll, is not supported via this set.

Specified by:
keySet in interface Map
Overrides:
keySet in class AbstractMap

lastKey

public java.lang.Object lastKey()
Description copied from interface: SortedMap
Returns the last (highest sorted) key in the map.

Specified by:
lastKey in interface SortedMap

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Description copied from interface: Map
Associates the given key to the given value (optional operation). If the map already contains the key, its value is replaced. Be aware that in a map that permits null values, a null return does not always imply that the mapping was created.

Specified by:
put in interface Map
Overrides:
put in class AbstractMap

remove

public java.lang.Object remove(java.lang.Object key)
Description copied from interface: Map
Removes the mapping for this key if present (optional operation). If the key is not present, this returns null. Note that maps which permit null values may also return null if the key was removed.

Specified by:
remove in interface Map
Overrides:
remove in class AbstractMap

size

public int size()
Description copied from interface: Map
Returns the number of key-value mappings in the map. If there are more than Integer.MAX_VALUE mappings, return Integer.MAX_VALUE.

Specified by:
size in interface Map
Overrides:
size in class AbstractMap

subMap

public SortedMap subMap(java.lang.Object fromKey,
                        java.lang.Object toKey)
Description copied from interface: SortedMap
Returns a view of the portion of the map greater than or equal to fromKey, and strictly less than toKey. The view is backed by this map, so changes in one show up in the other. The submap supports all optional operations of the original.

The returned map throws an IllegalArgumentException any time a key is used which is out of the range of fromKey and toKey. Note that the lower endpoint is included, but the upper is not; if you want to change the inclusion or exclusion of an endpoint, pass its successor object in instead. For example, for Integers, you could request subMap(new Integer(lowlimit.intValue() + 1), new Integer(highlimit.intValue() + 1)) to reverse the inclusiveness of both endpoints.

Specified by:
subMap in interface SortedMap

tailMap

public SortedMap tailMap(java.lang.Object fromKey)
Description copied from interface: SortedMap
Returns a view of the portion of the map greater than or equal to fromKey. The view is backed by this map, so changes in one show up in the other. The submap supports all optional operations of the original.

The returned map throws an IllegalArgumentException any time a key is used which is out of the range of fromKey. Note that the endpoint, fromKey, is included; if you do not want this value to be included, pass its successor object in to fromKey. For example, for Integers, you could request tailMap(new Integer(limit.intValue() + 1)).

Specified by:
tailMap in interface SortedMap

values

public Collection values()
Description copied from interface: Map
Returns a collection (or bag) view of the values in this Map. The collection is backed by the map, so that changes in one show up in the other. Modifications made while an iterator is in progress cause undefined behavior. If the collection supports removal, these methods remove the underlying mapping from the map: Iterator.remove, Collection.remove, removeAll, retainAll, and clear. Element addition, via add or addAll, is not supported via this collection.

Specified by:
values in interface Map
Overrides:
values in class AbstractMap