| java.util.TreeMap
TreeMap | public class TreeMap extends AbstractMap implements SortedMap<K, V>,Cloneable,Serializable(Code) | | TreeMap is an implementation of SortedMap. All optional operations are
supported, adding and removing. The values can be any objects. The keys can
be any objects which are comparable to each other either using their natural
order or a specified Comparator.
since: 1.2 |
Inner Class :static class Node implements Cloneable | |
Inner Class :static class AbstractMapIterator | |
Inner Class :static class UnboundedEntryIterator extends AbstractMapIterator implements Iterator<Map.Entry<K, V>> | |
Inner Class :static class UnboundedKeyIterator extends AbstractMapIterator implements Iterator<K> | |
Inner Class :static class UnboundedValueIterator extends AbstractMapIterator implements Iterator<V> | |
Inner Class :static class BoundedMapIterator extends AbstractMapIterator | |
Inner Class :static class BoundedEntryIterator extends BoundedMapIterator implements Iterator<Map.Entry<K, V>> | |
Inner Class :static class BoundedKeyIterator extends BoundedMapIterator implements Iterator<K> | |
Inner Class :static class BoundedValueIterator extends BoundedMapIterator implements Iterator<V> | |
Inner Class :static class SubMapEntrySet extends AbstractSet> implements Set<Map.Entry<K, V>> | |
Inner Class :static class SubMapKeySet extends AbstractSet implements Set<K> | |
Inner Class :static class SubMapValuesCollection extends AbstractCollection | |
Constructor Summary | |
public | TreeMap() Constructs a new empty instance of spec.TreeMap. | public | TreeMap(Comparator<? super K> comparator) Constructs a new empty instance of spec.TreeMap which uses the specified
Comparator. | public | TreeMap(Map<? extends K, ? extends V> map) Constructs a new instance of spec.TreeMap containing the mappings from the
specified Map and using the natural ordering. | public | TreeMap(SortedMap<K, ? extends V> map) Constructs a new instance of spec.TreeMap containing the mappings from the
specified SortedMap and using the same Comparator. |
Method Summary | |
Node<K, V> | addToLast(Node<K, V> last, K key, V value) | void | balance(Node<K, V> x) | public void | clear() Removes all mappings from this spec.TreeMap, leaving it empty. | public Object | clone() Answers a new spec.TreeMap with the same mappings, size and comparator as this
spec.TreeMap. | public Comparator<? super K> | comparator() Answers the Comparator used to compare elements in this spec.TreeMap. | public boolean | containsKey(Object key) Searches this spec.TreeMap for the specified key. | public boolean | containsValue(Object value) Searches this spec.TreeMap for the specified value. | public Set<Map.Entry<K, V>> | entrySet() Answers a Set of the mappings contained in this spec.TreeMap. | public K | firstKey() Answers the first sorted key in this spec.TreeMap. | public V | get(Object key) Answers the value of the mapping with the specified key. | public SortedMap<K, V> | headMap(K endKey) Answers a SortedMap of the specified portion of this spec.TreeMap which
contains keys less than the end key. | public Set<K> | keySet() Answers a Set of the keys contained in this spec.TreeMap. | public K | lastKey() Answer the last sorted key in this spec.TreeMap. | static Node<K, V> | maximum(Node<K, V> x) | static Node<K, V> | minimum(Node<K, V> x) | public V | put(K key, V value) Maps the specified key to the specified value. | public void | putAll(Map<? extends K, ? extends V> map) Copies every mapping in the specified Map to this spec.TreeMap. | public V | remove(Object key) Removes a mapping with the specified key from this spec.TreeMap. | void | removeFromIterator(Node<K, V> node, int index) | void | removeLeftmost(Node<K, V> node) | void | removeMiddleElement(Node<K, V> node, int index) | void | removeRightmost(Node<K, V> node) | public int | size() Answers the number of mappings in this spec.TreeMap. | public SortedMap<K, V> | subMap(K startKey, K endKey) Answers a SortedMap of the specified portion of this spec.TreeMap which
contains keys greater or equal to the start key but less than the end
key. | public SortedMap<K, V> | tailMap(K startKey) Answers a SortedMap of the specified portion of this spec.TreeMap which
contains keys greater or equal to the start key. | public Collection<V> | values() Answers a Collection of the values contained in this spec.TreeMap. |
modCount | transient int modCount(Code) | | |
root | transient Node<K, V> root(Code) | | |
TreeMap | public TreeMap()(Code) | | Constructs a new empty instance of spec.TreeMap.
|
TreeMap | public TreeMap(Comparator<? super K> comparator)(Code) | | Constructs a new empty instance of spec.TreeMap which uses the specified
Comparator.
Parameters: comparator - the Comparator |
TreeMap | public TreeMap(Map<? extends K, ? extends V> map)(Code) | | Constructs a new instance of spec.TreeMap containing the mappings from the
specified Map and using the natural ordering.
Parameters: map - the mappings to add throws: ClassCastException - when a key in the Map does not implement the Comparableinterface, or they keys in the Map cannot be compared |
TreeMap | public TreeMap(SortedMap<K, ? extends V> map)(Code) | | Constructs a new instance of spec.TreeMap containing the mappings from the
specified SortedMap and using the same Comparator.
Parameters: map - the mappings to add |
addToLast | Node<K, V> addToLast(Node<K, V> last, K key, V value)(Code) | | |
balance | void balance(Node<K, V> x)(Code) | | |
clone | public Object clone()(Code) | | Answers a new spec.TreeMap with the same mappings, size and comparator as this
spec.TreeMap.
a shallow copy of this spec.TreeMap See Also: java.lang.Cloneable |
comparator | public Comparator<? super K> comparator()(Code) | | Answers the Comparator used to compare elements in this spec.TreeMap.
a Comparator or null if the natural ordering is used |
containsKey | public boolean containsKey(Object key)(Code) | | Searches this spec.TreeMap for the specified key.
Parameters: key - the object to search for true if key is a key of this spec.TreeMap, falseotherwise throws: ClassCastException - when the key cannot be compared with the keys in thisspec.TreeMap throws: NullPointerException - when the key is null and the comparator cannot handle null |
containsValue | public boolean containsValue(Object value)(Code) | | Searches this spec.TreeMap for the specified value.
Parameters: value - the object to search for true if value is a value of this spec.TreeMap, falseotherwise |
entrySet | public Set<Map.Entry<K, V>> entrySet()(Code) | | Answers a Set of the mappings contained in this spec.TreeMap. Each element in
the set is a Map.Entry. The set is backed by this spec.TreeMap so changes to
one are reflected by the other. The set does not support adding.
a Set of the mappings |
firstKey | public K firstKey()(Code) | | Answers the first sorted key in this spec.TreeMap.
the first sorted key throws: NoSuchElementException - when this spec.TreeMap is empty |
get | public V get(Object key)(Code) | | Answers the value of the mapping with the specified key.
Parameters: key - the key the value of the mapping with the specified key throws: ClassCastException - when the key cannot be compared with the keys in thisspec.TreeMap throws: NullPointerException - when the key is null and the comparator cannot handle null |
headMap | public SortedMap<K, V> headMap(K endKey)(Code) | | Answers a SortedMap of the specified portion of this spec.TreeMap which
contains keys less than the end key. The returned SortedMap is backed by
this spec.TreeMap so changes to one are reflected by the other.
Parameters: endKey - the end key a sub-map where the keys are less than endKey throws: ClassCastException - when the end key cannot be compared with the keys in thisspec.TreeMap throws: NullPointerException - when the end key is null and the comparator cannot handlenull |
keySet | public Set<K> keySet()(Code) | | Answers a Set of the keys contained in this spec.TreeMap. The set is backed by
this spec.TreeMap so changes to one are reflected by the other. The set does
not support adding.
a Set of the keys |
lastKey | public K lastKey()(Code) | | Answer the last sorted key in this spec.TreeMap.
the last sorted key throws: NoSuchElementException - when this spec.TreeMap is empty |
maximum | static Node<K, V> maximum(Node<K, V> x)(Code) | | |
minimum | static Node<K, V> minimum(Node<K, V> x)(Code) | | |
put | public V put(K key, V value)(Code) | | Maps the specified key to the specified value.
Parameters: key - the key Parameters: value - the value the value of any previous mapping with the specified key or nullif there was no mapping throws: ClassCastException - when the key cannot be compared with the keys in thisspec.TreeMap throws: NullPointerException - when the key is null and the comparator cannot handle null |
putAll | public void putAll(Map<? extends K, ? extends V> map)(Code) | | Copies every mapping in the specified Map to this spec.TreeMap.
Parameters: map - the Map to copy mappings from throws: ClassCastException - when a key in the Map cannot be compared with the keys inthis spec.TreeMap throws: NullPointerException - when a key in the Map is null and the comparator cannothandle null |
remove | public V remove(Object key)(Code) | | Removes a mapping with the specified key from this spec.TreeMap.
Parameters: key - the key of the mapping to remove the value of the removed mapping or null if key is not a key inthis spec.TreeMap throws: ClassCastException - when the key cannot be compared with the keys in thisspec.TreeMap throws: NullPointerException - when the key is null and the comparator cannot handle null |
removeFromIterator | void removeFromIterator(Node<K, V> node, int index)(Code) | | |
removeLeftmost | void removeLeftmost(Node<K, V> node)(Code) | | |
removeMiddleElement | void removeMiddleElement(Node<K, V> node, int index)(Code) | | |
removeRightmost | void removeRightmost(Node<K, V> node)(Code) | | |
size | public int size()(Code) | | Answers the number of mappings in this spec.TreeMap.
the number of mappings in this spec.TreeMap |
subMap | public SortedMap<K, V> subMap(K startKey, K endKey)(Code) | | Answers a SortedMap of the specified portion of this spec.TreeMap which
contains keys greater or equal to the start key but less than the end
key. The returned SortedMap is backed by this spec.TreeMap so changes to one
are reflected by the other.
Parameters: startKey - the start key Parameters: endKey - the end key a sub-map where the keys are greater or equal tostartKey and less than endKey throws: ClassCastException - when the start or end key cannot be compared with the keysin this spec.TreeMap throws: NullPointerException - when the start or end key is null and the comparatorcannot handle null |
tailMap | public SortedMap<K, V> tailMap(K startKey)(Code) | | Answers a SortedMap of the specified portion of this spec.TreeMap which
contains keys greater or equal to the start key. The returned SortedMap
is backed by this spec.TreeMap so changes to one are reflected by the other.
Parameters: startKey - the start key a sub-map where the keys are greater or equal tostartKey throws: ClassCastException - when the start key cannot be compared with the keys inthis spec.TreeMap throws: NullPointerException - when the start key is null and the comparator cannothandle null |
values | public Collection<V> values()(Code) | | Answers a Collection of the values contained in this spec.TreeMap. The
collection is backed by this spec.TreeMap so changes to one are reflected by
the other. The collection does not support adding.
a Collection of the values |
|
|