public class TreeMap extends AbstractMap implements SortedMap, java.lang.Cloneable, java.io.Serializable, Rollbackable
This implementation is not synchronized. If you need to share this between
multiple threads, do something like:
SortedMap m
= Collections.synchronizedSortedMap(new TreeMap(...));
The iterators are fail-fast, meaning that any structural
modification, except for remove()
called on the iterator
itself, cause the iterator to throw a
ConcurrentModificationException
rather than exhibit
non-deterministic behavior.
Map
,
HashMap
,
Hashtable
,
LinkedHashMap
,
Comparable
,
Comparator
,
Collection
,
Collections.synchronizedSortedMap(SortedMap)
,
Serialized Form$CHECKPOINT, $RECORD$$CHECKPOINT
Constructor and Description |
---|
TreeMap()
Instantiate a new TreeMap with no elements, using the keys' natural
ordering to sort.
|
TreeMap(java.util.Comparator c)
Instantiate a new TreeMap with no elements, using the provided comparator
to sort.
|
TreeMap(Map map)
Instantiate a new TreeMap, initializing it with all of the elements in
the provided Map.
|
TreeMap(SortedMap sm)
Instantiate a new TreeMap, initializing it with all of the elements in
the provided SortedMap.
|
Modifier and Type | Method and Description |
---|---|
void |
$COMMIT(long timestamp)
Commit changes up to the given timestamp, but not including changes
made at timestamp and afterward.
|
void |
$RESTORE(long timestamp,
boolean trim)
Restore a previous state to all the private fields of this rollbackable
object.
|
void |
clear()
Clears the Map so it has no keys.
|
java.lang.Object |
clone()
Returns a shallow clone of this TreeMap.
|
java.util.Comparator |
comparator()
Return the comparator used to sort this map, or null if it is by
natural order.
|
boolean |
containsKey(java.lang.Object key)
Returns true if the map contains a mapping for the given key.
|
boolean |
containsValue(java.lang.Object value)
Returns true if the map contains at least one mapping to the given value.
|
Set |
entrySet()
Returns a "set view" of this TreeMap's entries.
|
java.lang.Object |
firstKey()
Returns the first (lowest) key in the map.
|
java.lang.Object |
get(java.lang.Object key)
Return the value in this TreeMap associated with the supplied key,
or
null if the key maps to nothing. |
SortedMap |
headMap(java.lang.Object toKey)
Returns a view of this Map including all entries with keys less than
toKey . |
Set |
keySet()
Returns a "set view" of this TreeMap's keys.
|
java.lang.Object |
lastKey()
Returns the last (highest) key in the map.
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Puts the supplied value into the Map, mapped by the supplied key.
|
void |
putAll(Map m)
Copies all elements of the given map into this TreeMap.
|
java.lang.Object |
remove(java.lang.Object key)
Removes from the TreeMap and returns the value which is mapped by the
supplied key.
|
int |
size()
Returns the number of key-value mappings currently in this Map.
|
SortedMap |
subMap(java.lang.Object fromKey,
java.lang.Object toKey)
Returns a view of this Map including all entries with keys greater or
equal to
fromKey and less than toKey (a
half-open interval). |
SortedMap |
tailMap(java.lang.Object fromKey)
Returns a view of this Map including all entries with keys greater or
equal to
fromKey . |
Collection |
values()
Returns a "collection view" (or "bag view") of this TreeMap's values.
|
$GET$CHECKPOINT, $SET$CHECKPOINT, equals, hashCode, isEmpty, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
$GET$CHECKPOINT, $SET$CHECKPOINT
public TreeMap()
Comparable
public TreeMap(java.util.Comparator c)
c
- the sort order for the keys of this map, or null
for the natural orderpublic TreeMap(Map map)
map
- a Map, whose entries will be put into this TreeMapjava.lang.ClassCastException
- if the keys in the provided Map are not
comparablejava.lang.NullPointerException
- if map is nullComparable
public TreeMap(SortedMap sm)
sm
- a SortedMap, whose entries will be put into this TreeMapjava.lang.NullPointerException
- if sm is nullpublic void clear()
clear
in interface Map
clear
in class AbstractMap
Set.clear()
public java.lang.Object clone()
clone
in class AbstractMap
Cloneable
,
Object.clone()
public java.util.Comparator comparator()
comparator
in interface SortedMap
public boolean containsKey(java.lang.Object key)
containsKey
in interface Map
containsKey
in class AbstractMap
key
- the key to look forjava.lang.ClassCastException
- if key is not comparable to map elementsjava.lang.NullPointerException
- if key is null and the comparator is not
tolerant of nullsAbstractMap.containsValue(Object)
public boolean containsValue(java.lang.Object value)
containsValue
in interface Map
containsValue
in class AbstractMap
value
- the value to look forAbstractMap.containsKey(Object)
public Set entrySet()
Note that the iterators for all three views, from keySet(), entrySet(), and values(), traverse the TreeMap in sorted sequence.
public java.lang.Object firstKey()
public java.lang.Object get(java.lang.Object key)
null
if the key maps to nothing. NOTE: Since the value
could also be null, you must use containsKey to see if this key
actually maps to something.get
in interface Map
get
in class AbstractMap
key
- the key for which to fetch an associated valuejava.lang.ClassCastException
- if key is not comparable to elements in the mapjava.lang.NullPointerException
- if key is null but the comparator does not
tolerate nullsput(Object, Object)
,
containsKey(Object)
public SortedMap headMap(java.lang.Object toKey)
toKey
. The returned map is backed by the original, so changes
in one appear in the other. The submap will throw an{headMap
in interface SortedMap
toKey
- the (exclusive) cutoff pointjava.lang.ClassCastException
- if toKey
is not compatible with
the comparator (or is not Comparable, for natural ordering)java.lang.NullPointerException
- if toKey is null, but the comparator does not
tolerate null elementspublic Set keySet()
keySet
in interface Map
keySet
in class AbstractMap
values()
,
entrySet()
public java.lang.Object lastKey()
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
equals()
this key. NOTE: Since the prior value could also be null, you must
first use containsKey if you want to see if you are replacing the
key's mapping.put
in interface Map
put
in class AbstractMap
key
- the key used to locate the valuevalue
- the value to be stored in the Mapjava.lang.ClassCastException
- if key is not comparable to current map keysjava.lang.NullPointerException
- if key is null, but the comparator does
not tolerate nullsget(Object)
,
Object.equals(Object)
public void putAll(Map m)
putAll
in interface Map
putAll
in class AbstractMap
m
- the map to be addedjava.lang.ClassCastException
- if a key in m is not comparable with keys
in the mapjava.lang.NullPointerException
- if a key in m is null, and the comparator
does not tolerate nullsAbstractMap.put(Object, Object)
public java.lang.Object remove(java.lang.Object key)
null
is returned. NOTE: Since the value
could also be null, you must use containsKey to see if you are
actually removing a mapping.remove
in interface Map
remove
in class AbstractMap
key
- the key used to locate the value to removejava.lang.ClassCastException
- if key is not comparable to current map keysjava.lang.NullPointerException
- if key is null, but the comparator does
not tolerate nullsIterator.remove()
public int size()
size
in interface Map
size
in class AbstractMap
Set.size()
public SortedMap subMap(java.lang.Object fromKey, java.lang.Object toKey)
fromKey
and less than toKey
(a
half-open interval). The returned map is backed by the original, so
changes in one appear in the other. The submap will throw an{subMap
in interface SortedMap
fromKey
- the (inclusive) low cutoff pointtoKey
- the (exclusive) high cutoff pointjava.lang.ClassCastException
- if either cutoff is not compatible with
the comparator (or is not Comparable, for natural ordering)java.lang.NullPointerException
- if fromKey or toKey is null, but the
comparator does not tolerate null elementsjava.lang.IllegalArgumentException
- if fromKey is greater than toKeypublic SortedMap tailMap(java.lang.Object fromKey)
fromKey
. The returned map is backed by the
original, so changes in one appear in the other. The submap will throw an{tailMap
in interface SortedMap
fromKey
- the (inclusive) low cutoff pointjava.lang.ClassCastException
- if fromKey
is not compatible with
the comparator (or is not Comparable, for natural ordering)java.lang.NullPointerException
- if fromKey is null, but the comparator
does not tolerate null elementspublic Collection values()
values
in interface Map
values
in class AbstractMap
keySet()
,
entrySet()
public void $COMMIT(long timestamp)
Rollbackable
$COMMIT
in interface Rollbackable
$COMMIT
in interface Map
$COMMIT
in interface SortedMap
$COMMIT
in class AbstractMap
timestamp
- The timestamp.public void $RESTORE(long timestamp, boolean trim)
Rollbackable
$RESTORE
in interface Rollbackable
$RESTORE
in interface Map
$RESTORE
in interface SortedMap
$RESTORE
in class AbstractMap
timestamp
- The timestamp taken at the time when the previous
state was recorded.trim
- Whether to delete the records used for the rollback.Checkpoint.rollback(long, boolean)