|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.beanlib.utils.range.AbstractMap<K,V> net.sf.beanlib.utils.range.ExtensibleTreeMap<K,V>
public abstract class ExtensibleTreeMap<K,V>
Basically cloned from and identical to TreeMap
,
except
Nested Class Summary | |
---|---|
private class |
ExtensibleTreeMap.EntryIterator
|
private class |
ExtensibleTreeMap.KeyIterator
|
(package private) static class |
ExtensibleTreeMap.NodeEntry<K,V>
Node in the Tree. |
private class |
ExtensibleTreeMap.PrivateEntryIterator<T>
TreeMap Iterator. |
private class |
ExtensibleTreeMap.SubMap
|
private class |
ExtensibleTreeMap.SubMapEntryIterator
|
private class |
ExtensibleTreeMap.ValueIterator
|
Nested classes/interfaces inherited from class net.sf.beanlib.utils.range.AbstractMap |
---|
AbstractMap.SimpleEntry<K,V> |
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry<K,V> |
Field Summary | |
---|---|
private static boolean |
BLACK
|
private Comparator<? super K> |
comparator
The Comparator used to maintain order in this TreeMap, or null if this TreeMap uses its elements natural ordering. |
private Set<Map.Entry<K,V>> |
entrySet
This field is initialized to contain an instance of the entry set view the first time this view is requested. |
private int |
modCount
The number of structural modifications to the tree. |
private static boolean |
RED
|
protected ExtensibleTreeMap.NodeEntry<K,V> |
root
|
private static long |
serialVersionUID
|
private int |
size
The number of entries in the tree |
Fields inherited from class net.sf.beanlib.utils.range.AbstractMap |
---|
keySet, values |
Constructor Summary | |
---|---|
ExtensibleTreeMap()
Constructs a new, empty map, sorted according to the keys' natural order. |
|
ExtensibleTreeMap(Comparator<? super K> c)
Constructs a new, empty map, sorted according to the given comparator. |
|
ExtensibleTreeMap(Map<? extends K,? extends V> m)
Constructs a new map containing the same mappings as the given map, sorted according to the keys' natural order. |
|
ExtensibleTreeMap(SortedMap<K,? extends V> m)
Constructs a new map containing the same mappings as the given SortedMap, sorted according to the same ordering. |
Method Summary | ||
---|---|---|
(package private) void |
addAllForTreeSet(SortedSet<Map.Entry<K,V>> set,
V defaultVal)
Intended to be called only from TreeSet.addAll * |
|
private ExtensibleTreeMap.NodeEntry<K,V> |
buildFromSorted(int level,
int lo,
int hi,
int redLevel,
Iterator it,
ObjectInputStream str,
V defaultVal)
Recursive "helper method" that does the real work of the of the previous method. |
|
private void |
buildFromSorted(int size,
Iterator it,
ObjectInputStream str,
V defaultVal)
Linear time tree building algorithm from sorted data. |
|
void |
clear()
Removes all mappings from this TreeMap. |
|
Object |
clone()
Returns a shallow copy of this TreeMap instance. |
|
private static
|
colorOf(ExtensibleTreeMap.NodeEntry<K,V> p)
Balancing operations. |
|
Comparator<? super K> |
comparator()
Returns the comparator used to order this map, or null if this map uses its keys' natural order. |
|
private int |
compare(K k1,
K k2)
Compares two keys using the correct comparison method for this TreeMap. |
|
private static int |
computeRedLevel(int sz)
Find the level down to which to assign all nodes BLACK. |
|
boolean |
containsKey(Object key)
Returns true if this map contains a mapping for the specified key. |
|
boolean |
containsValue(Object value)
Returns true if this map maps one or more keys to the specified value. |
|
private void |
decrementSize()
|
|
private void |
deleteEntry(ExtensibleTreeMap.NodeEntry<K,V> p)
Delete node p, and then rebalance the tree. |
|
Set<Map.Entry<K,V>> |
entrySet()
Returns a set view of the mappings contained in this map. |
|
private ExtensibleTreeMap.NodeEntry<K,V> |
firstEntry()
Returns the first Entry in the TreeMap (according to the TreeMap's key-sort function). |
|
K |
firstKey()
Returns the first (lowest) key currently in this sorted map. |
|
private void |
fixAfterDeletion(ExtensibleTreeMap.NodeEntry<K,V> x)
From CLR * |
|
private void |
fixAfterInsertion(ExtensibleTreeMap.NodeEntry<K,V> x)
From CLR * |
|
V |
get(Object key)
Returns the value to which this map maps the specified key. |
|
private ExtensibleTreeMap.NodeEntry<K,V> |
getCeilEntry(K key)
Gets the entry corresponding to the specified key; if no such entry exists, returns the entry for the least key greater than the specified key; if no such entry exists (i.e., the greatest key in the Tree is less than the specified key), returns null. |
|
private ExtensibleTreeMap.NodeEntry<K,V> |
getEntry(Object key)
Returns this map's entry for the given key, or null if the map does not contain an entry for the key. |
|
private ExtensibleTreeMap.NodeEntry<K,V> |
getPrecedingEntry(K key)
Returns the entry for the greatest key less than the specified key; if no such entry exists (i.e., the least key in the Tree is greater than the specified key), returns null. |
|
SortedMap<K,V> |
headMap(K toKey)
Returns a view of the portion of this map whose keys are strictly less than toKey. |
|
private void |
incrementSize()
|
|
private static
|
key(ExtensibleTreeMap.NodeEntry<K,?> e)
Returns the key corresponding to the specified Entry. |
|
Set<K> |
keySet()
Returns a Set view of the keys contained in this map. |
|
private ExtensibleTreeMap.NodeEntry<K,V> |
lastEntry()
Returns the last Entry in the TreeMap (according to the TreeMap's key-sort function). |
|
K |
lastKey()
Returns the last (highest) key currently in this sorted map. |
|
private static
|
leftOf(ExtensibleTreeMap.NodeEntry<K,V> p)
|
|
private static
|
parentOf(ExtensibleTreeMap.NodeEntry<K,V> p)
|
|
V |
put(K key,
V value)
Associates the specified value with the specified key in this map. |
|
void |
putAll(Map<? extends K,? extends V> map)
Copies all of the mappings from the specified map to this map. |
|
private void |
readObject(ObjectInputStream s)
Reconstitute the TreeMap instance from a stream (i.e., deserialize it). |
|
(package private) void |
readTreeSet(int size,
ObjectInputStream s,
V defaultVal)
Intended to be called only from TreeSet.readObject * |
|
V |
remove(Object key)
Removes the mapping for this key from this TreeMap if present. |
|
private static
|
rightOf(ExtensibleTreeMap.NodeEntry<K,V> p)
|
|
private void |
rotateLeft(ExtensibleTreeMap.NodeEntry<K,V> p)
From CLR * |
|
private void |
rotateRight(ExtensibleTreeMap.NodeEntry<K,V> p)
From CLR * |
|
private static
|
setColor(ExtensibleTreeMap.NodeEntry<K,V> p,
boolean c)
|
|
int |
size()
Returns the number of key-value mappings in this map. |
|
SortedMap<K,V> |
subMap(K fromKey,
K toKey)
Returns a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive. |
|
private ExtensibleTreeMap.NodeEntry<K,V> |
successor(ExtensibleTreeMap.NodeEntry<K,V> t)
Returns the successor of the specified Entry, or null if no such. |
|
SortedMap<K,V> |
tailMap(K fromKey)
Returns a view of the portion of this map whose keys are greater than or equal to fromKey. |
|
private static boolean |
valEquals(Object o1,
Object o2)
Test two values for equality. |
|
Collection<V> |
values()
Returns a collection view of the values contained in this map. |
|
private boolean |
valueSearchNonNull(ExtensibleTreeMap.NodeEntry n,
Object value)
|
|
private boolean |
valueSearchNull(ExtensibleTreeMap.NodeEntry n)
|
|
private void |
writeObject(ObjectOutputStream s)
Save the state of the TreeMap instance to a stream (i.e., serialize it). |
Methods inherited from class net.sf.beanlib.utils.range.AbstractMap |
---|
equals, hashCode, isEmpty, 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 |
Field Detail |
---|
private Comparator<? super K> comparator
protected transient ExtensibleTreeMap.NodeEntry<K,V> root
private transient int size
private transient int modCount
private transient volatile Set<Map.Entry<K,V>> entrySet
private static final boolean RED
private static final boolean BLACK
private static final long serialVersionUID
Constructor Detail |
---|
public ExtensibleTreeMap()
Comparable
public ExtensibleTreeMap(Comparator<? super K> c)
c
- the comparator that will be used to sort this map. A
null value indicates that the keys' natural
ordering should be used.public ExtensibleTreeMap(Map<? extends K,? extends V> m)
m
- the map whose mappings are to be placed in this map.
ClassCastException
- the keys in t are not Comparable, or are not mutually
comparable.
NullPointerException
- if the specified map is null.public ExtensibleTreeMap(SortedMap<K,? extends V> m)
m
- the sorted map whose mappings are to be placed in this map,
and whose comparator is to be used to sort this map.
NullPointerException
- if the specified sorted map is null.Method Detail |
---|
private void incrementSize()
private void decrementSize()
public int size()
size
in interface Map<K,V>
size
in class AbstractMap<K,V>
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
containsKey
in class AbstractMap<K,V>
key
- key whose presence in this map is to be tested.
ClassCastException
- if the key cannot be compared with the keys currently in the
map.
NullPointerException
- key is null and this map uses natural ordering, or
its comparator does not tolerate null keys.public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
containsValue
in class AbstractMap<K,V>
value
- value whose presence in this Map is to be tested.
private boolean valueSearchNull(ExtensibleTreeMap.NodeEntry n)
private boolean valueSearchNonNull(ExtensibleTreeMap.NodeEntry n, Object value)
public V get(Object key)
get
in interface Map<K,V>
get
in class AbstractMap<K,V>
key
- key whose associated value is to be returned.
ClassCastException
- key cannot be compared with the keys currently in the map.
NullPointerException
- key is null and this map uses natural ordering, or
its comparator does not tolerate null keys.containsKey(Object)
public Comparator<? super K> comparator()
comparator
in interface SortedMap<K,V>
public K firstKey()
firstKey
in interface SortedMap<K,V>
NoSuchElementException
- Map is empty.public K lastKey()
lastKey
in interface SortedMap<K,V>
NoSuchElementException
- Map is empty.public void putAll(Map<? extends K,? extends V> map)
putAll
in interface Map<K,V>
putAll
in class AbstractMap<K,V>
map
- mappings to be stored in this map.
ClassCastException
- class of a key or value in the specified map prevents it from
being stored in this map.
NullPointerException
- if the given map is null or this map does not
permit null keys and a key in the specified map is
null.private ExtensibleTreeMap.NodeEntry<K,V> getEntry(Object key)
ClassCastException
- if the key cannot be compared with the keys currently in the
map.
NullPointerException
- key is null and this map uses natural order, or
its comparator does not tolerate * null keys.private ExtensibleTreeMap.NodeEntry<K,V> getCeilEntry(K key)
private ExtensibleTreeMap.NodeEntry<K,V> getPrecedingEntry(K key)
private static <K> K key(ExtensibleTreeMap.NodeEntry<K,?> e)
public V put(K key, V value)
put
in interface Map<K,V>
put
in class AbstractMap<K,V>
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.
ClassCastException
- key cannot be compared with the keys currently in the map.
NullPointerException
- key is null and this map uses natural order, or
its comparator does not tolerate null keys.public V remove(Object key)
remove
in interface Map<K,V>
remove
in class AbstractMap<K,V>
key
- key for which mapping should be removed
ClassCastException
- key cannot be compared with the keys currently in the map.
NullPointerException
- key is null and this map uses natural order, or
its comparator does not tolerate null keys.public void clear()
clear
in interface Map<K,V>
clear
in class AbstractMap<K,V>
public Object clone()
clone
in class AbstractMap<K,V>
public Set<K> keySet()
keySet
in interface Map<K,V>
keySet
in class AbstractMap<K,V>
public Collection<V> values()
values
in interface Map<K,V>
values
in class AbstractMap<K,V>
public Set<Map.Entry<K,V>> entrySet()
entrySet
in interface Map<K,V>
entrySet
in class AbstractMap<K,V>
public SortedMap<K,V> subMap(K fromKey, K toKey)
The sorted map returned by this method will throw an IllegalArgumentException if the user attempts to insert a key less than fromKey or greater than or equal to toKey.
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 sorted 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:
SortedMap sub = m.submap(low, high + "\0");A similar 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:
SortedMap sub = m.subMap(low + "\0", high);
subMap
in interface SortedMap<K,V>
fromKey
- low endpoint (inclusive) of the subMap.toKey
- high endpoint (exclusive) of the subMap.
ClassCastException
- if fromKey and toKey cannot be compared
to one another using this map's comparator (or, if the map
has no comparator, using natural ordering).
IllegalArgumentException
- if fromKey is greater than toKey.
NullPointerException
- if fromKey or toKey is null
and this map uses natural order, or its comparator does not
tolerate null keys.public SortedMap<K,V> headMap(K toKey)
The sorted map returned by this method will throw an IllegalArgumentException if the user attempts to insert a key greater than or equal to toKey.
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 sorted 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:
SortedMap head = m.headMap(high + "\0");
headMap
in interface SortedMap<K,V>
toKey
- high endpoint (exclusive) of the headMap.
ClassCastException
- if toKey is not compatible with this map's
comparator (or, if the map has no comparator, if
toKey does not implement Comparable).
IllegalArgumentException
- if this map is itself a subMap, headMap, or tailMap, and
toKey is not within the specified range of the
subMap, headMap, or tailMap.
NullPointerException
- if toKey is null and this map uses
natural order, or its comparator does not tolerate
null keys.public SortedMap<K,V> tailMap(K fromKey)
The sorted map returned by this method will throw an IllegalArgumentException if the user attempts to insert a key less than fromKey.
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 m is a sorted 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:
SortedMap tail = m.tailMap(low + "\0");
tailMap
in interface SortedMap<K,V>
fromKey
- low endpoint (inclusive) of the tailMap.
ClassCastException
- if fromKey is not compatible with this map's
comparator (or, if the map has no comparator, if
fromKey does not implement Comparable).
IllegalArgumentException
- if this map is itself a subMap, headMap, or tailMap, and
fromKey is not within the specified range of the
subMap, headMap, or tailMap.
NullPointerException
- if fromKey is null and this map uses
natural order, or its comparator does not tolerate
null keys.private int compare(K k1, K k2)
private static boolean valEquals(Object o1, Object o2)
private ExtensibleTreeMap.NodeEntry<K,V> firstEntry()
private ExtensibleTreeMap.NodeEntry<K,V> lastEntry()
private ExtensibleTreeMap.NodeEntry<K,V> successor(ExtensibleTreeMap.NodeEntry<K,V> t)
private static <K,V> boolean colorOf(ExtensibleTreeMap.NodeEntry<K,V> p)
private static <K,V> ExtensibleTreeMap.NodeEntry<K,V> parentOf(ExtensibleTreeMap.NodeEntry<K,V> p)
private static <K,V> void setColor(ExtensibleTreeMap.NodeEntry<K,V> p, boolean c)
private static <K,V> ExtensibleTreeMap.NodeEntry<K,V> leftOf(ExtensibleTreeMap.NodeEntry<K,V> p)
private static <K,V> ExtensibleTreeMap.NodeEntry<K,V> rightOf(ExtensibleTreeMap.NodeEntry<K,V> p)
private void rotateLeft(ExtensibleTreeMap.NodeEntry<K,V> p)
private void rotateRight(ExtensibleTreeMap.NodeEntry<K,V> p)
private void fixAfterInsertion(ExtensibleTreeMap.NodeEntry<K,V> x)
private void deleteEntry(ExtensibleTreeMap.NodeEntry<K,V> p)
private void fixAfterDeletion(ExtensibleTreeMap.NodeEntry<K,V> x)
private void writeObject(ObjectOutputStream s) throws IOException
IOException
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
void readTreeSet(int size, ObjectInputStream s, V defaultVal) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
void addAllForTreeSet(SortedSet<Map.Entry<K,V>> set, V defaultVal)
private void buildFromSorted(int size, Iterator it, ObjectInputStream str, V defaultVal) throws IOException, ClassNotFoundException
size
- the number of keys (or key-value pairs) to be read from the
iterator or stream.it
- If non-null, new entries are created from entries or keys read
from this iterator.str
- If non-null, new entries are created from keys and possibly
values read from this stream in serialized form. Exactly one
of it and str should be non-null.defaultVal
- if non-null, this default value is used for each value in the
map. If null, each value is read from iterator or stream, as
described above.
IOException
- propagated from stream reads. This cannot occur if str is
null.
ClassNotFoundException
- propagated from readObject. This cannot occur if str is null.private final ExtensibleTreeMap.NodeEntry<K,V> buildFromSorted(int level, int lo, int hi, int redLevel, Iterator it, ObjectInputStream str, V defaultVal) throws IOException, ClassNotFoundException
level
- the current level of tree. Initial call should be 0.lo
- the first element index of this subtree. Initial should be 0.hi
- the last element index of this subtree. Initial should be
size-1.redLevel
- the level at which nodes should be red. Must be equal to
computeRedLevel for tree of this size.
IOException
ClassNotFoundException
private static int computeRedLevel(int sz)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |