|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.AbstractMap | +--org.bibop.utils.OrderedMap
A utility class, to retrieve a list of entries ordered by insertion order.
Nested Class Summary | |
(package private) static class |
OrderedMap.Entry
Node in the Tree. |
private class |
OrderedMap.Iterator
OrderedMap Iterator. |
Field Summary | |
private static int |
ENTRIES
|
private java.util.Set |
entrySet
|
private static int |
KEYS
|
private java.util.Set |
keySet
These fields are initialized to contain an instance of the appropriate view the first time this view is requested. |
private OrderedMap.Entry |
root
|
private int |
size
The number of entries in the tree |
private java.util.Collection |
values
|
private static int |
VALUES
|
Constructor Summary | |
OrderedMap()
Constructs a new, empty map, sorted according to the keys' natural order. |
|
OrderedMap(java.util.Comparator c)
Constructs a new, empty map, sorted according to the given comparator. |
|
OrderedMap(java.util.Map m)
Constructs a new map containing the same mappings as the given map, sorted according to the keys' natural order. |
|
OrderedMap(java.util.SortedMap m)
Constructs a new map containing the same mappings as the given SortedMap, sorted according to the same ordering. |
Method Summary | |
void |
clear()
Removes all mappings from this OrderedMap. |
java.lang.Object |
clone()
Returns a shallow copy of this OrderedMap instance. |
java.util.Comparator |
comparator()
Returns the comparator used to order this map, or null if this map uses its keys' natural order. |
boolean |
containsKey(java.lang.Object key)
Returns true if this map contains a mapping for the specified key. |
boolean |
containsValue(java.lang.Object value)
Returns true if this map maps one or more keys to the specified value. |
private void |
decrementSize()
|
private void |
deleteEntry(OrderedMap.Entry p)
Delete node p, and then rebalance the tree. |
java.util.Set |
entrySet()
Returns a set view of the mappings contained in this map. |
private OrderedMap.Entry |
firstEntry()
Returns the first Entry in the OrderedMap (according to the OrderedMap's key-sort function). |
java.lang.Object |
firstKey()
Returns the first (lowest) key currently in this sorted map. |
java.lang.Object |
get(java.lang.Object key)
Returns the value to which this map maps the specified key. |
private OrderedMap.Entry |
getCeilEntry(java.lang.Object 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 OrderedMap.Entry |
getEntry(java.lang.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 OrderedMap.Entry |
getPrecedingEntry(java.lang.Object 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. |
java.util.SortedMap |
headMap(java.lang.Object toKey)
Returns a view of the portion of this map whose keys are strictly less than toKey. |
private void |
incrementSize()
|
private static java.lang.Object |
key(OrderedMap.Entry e)
Returns the key corresonding to the specified Entry. |
java.util.Set |
keySet()
Returns a Set view of the keys contained in this map. |
private OrderedMap.Entry |
lastEntry()
Returns the last Entry in the OrderedMap (according to the OrderedMap's key-sort function). |
java.lang.Object |
lastKey()
Returns the last (highest) key currently in this sorted map. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Associates the specified value with the specified key in this map. |
void |
putAll(java.util.Map map)
Copies all of the mappings from the specified map to this map. |
java.lang.Object |
remove(java.lang.Object key)
Removes the mapping for this key from this TreeMap if present. |
int |
size()
Returns the number of key-value mappings in this map. |
java.util.SortedMap |
subMap(java.lang.Object fromKey,
java.lang.Object toKey)
Returns a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive. |
private OrderedMap.Entry |
successor(OrderedMap.Entry t)
Returns the successor of the specified Entry, or null if no such. |
java.util.SortedMap |
tailMap(java.lang.Object fromKey)
Returns a view of the portion of this map whose keys are greater than or equal to fromKey. |
private static boolean |
valEquals(java.lang.Object o1,
java.lang.Object o2)
Test two values for equality. |
java.util.Collection |
values()
Returns a collection view of the values contained in this map. |
Methods inherited from class java.util.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 transient OrderedMap.Entry root
private transient int size
private transient java.util.Set keySet
private transient java.util.Set entrySet
private transient java.util.Collection values
private static final int KEYS
private static final int VALUES
private static final int ENTRIES
Constructor Detail |
public OrderedMap()
public OrderedMap(java.util.Comparator c)
public OrderedMap(java.util.Map m)
java.lang.ClassCastException
- the keys in t are not Comparable, or
are not mutually comparable.public OrderedMap(java.util.SortedMap m)
Method Detail |
private void incrementSize()
private void decrementSize()
public int size()
size
in interface java.util.Map
size
in class java.util.AbstractMap
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map
containsKey
in class java.util.AbstractMap
key
- key whose presence in this map is to be tested.
java.lang.ClassCastException
- if the key cannot be compared with the keys
currently in the map.
java.lang.NullPointerException
- key is null and this map uses
natural ordering, or its comparator does not tolerate
null keys.public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map
containsValue
in class java.util.AbstractMap
value
- value whose presence in this Map is to be tested.public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map
get
in class java.util.AbstractMap
key
- key whose associated value is to be returned.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.
java.lang.NullPointerException
- key is null and this map uses
natural ordering, or its comparator does not tolerate
null keys.public java.util.Comparator comparator()
comparator
in interface java.util.SortedMap
public java.lang.Object firstKey()
firstKey
in interface java.util.SortedMap
java.util.NoSuchElementException
- Map is empty.public java.lang.Object lastKey()
lastKey
in interface java.util.SortedMap
java.util.NoSuchElementException
- Map is empty.public void putAll(java.util.Map map)
putAll
in interface java.util.Map
putAll
in class java.util.AbstractMap
java.lang.ClassCastException
- class of a key or value in the specified
map prevents it from being stored in this map.
java.lang.NullPointerException
- this map does not permit null
keys and a specified key is null.private OrderedMap.Entry getEntry(java.lang.Object key)
java.lang.ClassCastException
- if the key cannot be compared with the keys
currently in the map.
java.lang.NullPointerException
- key is null and this map uses
natural order, or its comparator does not tolerate *
null keys.private OrderedMap.Entry getCeilEntry(java.lang.Object key)
private OrderedMap.Entry getPrecedingEntry(java.lang.Object key)
private static java.lang.Object key(OrderedMap.Entry e)
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in interface java.util.Map
put
in class java.util.AbstractMap
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.
java.lang.NullPointerException
- key is null and this map uses
natural order, or its comparator does not tolerate
null keys.public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
remove
in class java.util.AbstractMap
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.
java.lang.NullPointerException
- key is null and this map uses
natural order, or its comparator does not tolerate
null keys.public void clear()
clear
in interface java.util.Map
clear
in class java.util.AbstractMap
public java.lang.Object clone()
clone
in class java.util.AbstractMap
public java.util.Set keySet()
keySet
in interface java.util.Map
keySet
in class java.util.AbstractMap
public java.util.Collection values()
values
in interface java.util.Map
values
in class java.util.AbstractMap
public java.util.Set entrySet()
entrySet
in interface java.util.Map
entrySet
in class java.util.AbstractMap
public java.util.SortedMap subMap(java.lang.Object fromKey, java.lang.Object 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 java.util.SortedMap
fromKey
- low endpoint (inclusive) of the subMap.toKey
- high endpoint (exclusive) of the subMap.
java.lang.NullPointerException
- if fromKey or toKey is
null and this map uses natural order, or its
comparator does not tolerate null keys.
java.lang.IllegalArgumentException
- if fromKey is greater than
toKey.public java.util.SortedMap headMap(java.lang.Object 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 java.util.SortedMap
toKey
- high endpoint (exclusive) of the headMap.
java.lang.NullPointerException
- if toKey is null and
this map uses natural order, or its comparator does * not
tolerate null keys.public java.util.SortedMap tailMap(java.lang.Object 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 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 strictly greater than low:
SortedMap tail = m.tailMap(low+"\0");
tailMap
in interface java.util.SortedMap
fromKey
- low endpoint (inclusive) of the tailMap.
java.lang.NullPointerException
- fromKey is null and this
map uses natural ordering, or its comparator does
not tolerate null keys.private static boolean valEquals(java.lang.Object o1, java.lang.Object o2)
private OrderedMap.Entry firstEntry()
private OrderedMap.Entry lastEntry()
private OrderedMap.Entry successor(OrderedMap.Entry t)
private void deleteEntry(OrderedMap.Entry p)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |