| java.lang.Object com.jofti.util.AbstractMap com.jofti.util.ValueTreeMap
ValueTreeMap | public class ValueTreeMap extends AbstractMap implements Cloneable,java.io.Serializable(Code) | | This class is a modified version of the TreeMap class from the
Java Collections Framework.
The changes are to allow SQL type multi-attribute sorting by ordering the entries based on a
modified comparator/search method that allows value ordering as well as key ordering. However, this slightly breaks
the Map semantics as it enables two objects with the same key to be placed in the Map. As this class is not desgned as a general
Map this is not a problem as it should be used as am immutable result Map. This may be formalised more closely later on.
author: Steve Woodcock author: Josh Bloch and Doug Lea version: 1.56, 01/23/03 See Also: Map See Also: HashMap See Also: Hashtable See Also: Comparable See Also: Comparator See Also: Collection See Also: Collections.synchronizedMap(Map) since: 1.2 |
Inner Class :static class Entry implements Map.Entry | |
Inner Class :class DefaultComparator implements Comparator | |
Constructor Summary | |
public | ValueTreeMap() Constructs a new, empty map, sorted according to the keys' natural
order. | public | ValueTreeMap(Comparator c) Constructs a new, empty map, sorted according to the given comparator.
All keys inserted into the map must be mutually comparable by
the given comparator: comparator.compare(k1, k2) must not
throw a ClassCastException for any keys k1 and
k2 in the map. | public | ValueTreeMap(Map m) Constructs a new map containing the same mappings as the given map,
sorted according to the keys' natural order. | public | ValueTreeMap(SortedMap m) Constructs a new map containing the same mappings as the given
SortedMap, sorted according to the same ordering. |
Method Summary | |
void | addAllForTreeSet(SortedSet set, Object defaultVal) | public void | clear() Removes all mappings from this TreeMap. | public Object | clone() Returns a shallow copy of this TreeMap instance. | public Comparator | comparator() Returns the comparator used to order this map, or null if this
map uses its keys' natural order. | public boolean | containsKey(Object key) Returns true if this map contains a mapping for the specified
key.
Parameters: key - key whose presence in this map is to be tested. | public boolean | containsValue(Object value) Returns true if this map maps one or more keys to the
specified value. | public Set | entrySet() Returns a set view of the mappings contained in this map. | public Object | firstKey() Returns the first (lowest) key currently in this sorted map. | public Object | get(Object key) Returns the value to which this map maps the specified key. | public Map | getSubMap(int startEntry, int maxNumber) | public Set | keySet() Returns a Set view of the keys contained in this map. | public Object | lastKey() Returns the last (highest) key currently in this sorted map. | public Object | put(Object key, Object value) Associates the specified value with the specified key in this map.
If the map previously contained a mapping for this key, the old
value is replaced.
Parameters: key - key with which the specified value is to be associated. Parameters: value - value to be associated with the specified key. | public void | putAll(Map map) | void | readTreeSet(int size, java.io.ObjectInputStream s, Object defaultVal) | public Object | remove(Object key) Removes the mapping for this key from this TreeMap if present.
Parameters: key - key for which mapping should be removed previous value associated with specified key, or nullif there was no mapping for key. | public Object | removeEntry(Object key, Object value) | public int | size() Returns the number of key-value mappings in this map. | public Collection | values() Returns a collection view of the values contained in this map. |
ValueTreeMap | public ValueTreeMap()(Code) | | Constructs a new, empty map, sorted according to the keys' natural
order. All keys inserted into the map must implement the
Comparable interface. Furthermore, all such keys must be
mutually comparable: k1.compareTo(k2) must not throw a
ClassCastException for any elements k1 and k2 in the
map. If the user attempts to put a key into the map that violates this
constraint (for example, the user attempts to put a string key into a
map whose keys are integers), the put(Object key, Object
value) call will throw a ClassCastException.
See Also: Comparable |
ValueTreeMap | public ValueTreeMap(Comparator c)(Code) | | Constructs a new, empty map, sorted according to the given comparator.
All keys inserted into the map must be mutually comparable by
the given comparator: comparator.compare(k1, k2) must not
throw a ClassCastException for any keys k1 and
k2 in the map. If the user attempts to put a key into the
map that violates this constraint, the put(Object key, Object
value) call will throw a ClassCastException.
Parameters: c - the comparator that will be used to sort this map. Anull value indicates that the keys' naturalordering should be used. |
ValueTreeMap | public ValueTreeMap(Map m)(Code) | | Constructs a new map containing the same mappings as the given map,
sorted according to the keys' natural order. All keys inserted
into the new map must implement the Comparable interface.
Furthermore, all such keys must be mutually comparable:
k1.compareTo(k2) must not throw a ClassCastException
for any elements k1 and k2 in the map. This method
runs in n*log(n) time.
Parameters: m - the map whose mappings are to be placed in this map. throws: ClassCastException - the keys in t are not Comparable, orare not mutually comparable. throws: NullPointerException - if the specified map is null. |
ValueTreeMap | public ValueTreeMap(SortedMap m)(Code) | | Constructs a new map containing the same mappings as the given
SortedMap, sorted according to the same ordering. This method
runs in linear time.
Parameters: m - the sorted map whose mappings are to be placed in this map,and whose comparator is to be used to sort this map. throws: NullPointerException - if the specified sorted map is null. |
addAllForTreeSet | void addAllForTreeSet(SortedSet set, Object defaultVal)(Code) | | Intended to be called only from TreeSet.addAll *
|
clear | public void clear()(Code) | | Removes all mappings from this TreeMap.
|
clone | public Object clone()(Code) | | Returns a shallow copy of this TreeMap instance. (The keys and
values themselves are not cloned.)
a shallow copy of this Map. |
comparator | public Comparator comparator()(Code) | | Returns the comparator used to order this map, or null if this
map uses its keys' natural order.
the comparator associated with this sorted map, ornull if it uses its keys' natural sort method. |
containsKey | public boolean containsKey(Object key)(Code) | | Returns true if this map contains a mapping for the specified
key.
Parameters: key - key whose presence in this map is to be tested. true if this map contains a mapping for thespecified key. throws: ClassCastException - if the key cannot be compared with the keyscurrently in the map. throws: NullPointerException - key is null and this map usesnatural ordering, or its comparator does not toleratenull keys. |
containsValue | public boolean containsValue(Object value)(Code) | | Returns true if this map maps one or more keys to the
specified value. More formally, returns true if and only if
this map contains at least one mapping to a value v such
that (value==null ? v==null : value.equals(v)). This
operation will probably require time linear in the Map size for most
implementations of Map.
Parameters: value - value whose presence in this Map is to be tested. true if a mapping to value exists;false otherwise. since: 1.2 |
entrySet | public Set entrySet()(Code) | | Returns a set view of the mappings contained in this map. The set's
iterator returns the mappings in ascending key order. Each element in
the returned set is a Map.Entry. The set is backed by this
map, so changes to this map are reflected in the set, and vice-versa.
The set supports element removal, which removes the corresponding
mapping from the TreeMap, through the Iterator.remove,
Set.remove, removeAll, retainAll and
clear operations. It does not support the add or
addAll operations.
a set view of the mappings contained in this map. See Also: Map.Entry |
firstKey | public Object firstKey()(Code) | | Returns the first (lowest) key currently in this sorted map.
the first (lowest) key currently in this sorted map. throws: NoSuchElementException - Map is empty. |
get | public Object get(Object key)(Code) | | Returns the value to which this map maps the specified key. Returns
null if the map contains no mapping for this key. A return
value of null does not necessarily indicate that the
map contains no mapping for the key; it's also possible that the map
explicitly maps the key to null. The containsKey
operation may be used to distinguish these two cases.
Parameters: key - key whose associated value is to be returned. the value to which this map maps the specified key, ornull if the map contains no mapping for the key. throws: ClassCastException - key cannot be compared with the keyscurrently in the map. throws: NullPointerException - key is null and this map usesnatural ordering, or its comparator does not toleratenull keys. See Also: ValueTreeMap.containsKey(Object) |
getSubMap | public Map getSubMap(int startEntry, int maxNumber)(Code) | | |
keySet | public Set keySet()(Code) | | Returns a Set view of the keys contained in this map. The set's
iterator will return the keys in ascending order. The map is backed by
this TreeMap instance, so changes to this map are reflected in
the Set, and vice-versa. The Set supports element removal, which
removes the corresponding mapping from the map, via the
Iterator.remove, Set.remove, removeAll,
retainAll, and clear operations. It does not support
the add or addAll operations.
a set view of the keys contained in this TreeMap. |
lastKey | public Object lastKey()(Code) | | Returns the last (highest) key currently in this sorted map.
the last (highest) key currently in this sorted map. throws: NoSuchElementException - Map is empty. |
put | public Object put(Object key, Object value)(Code) | | Associates the specified value with the specified key in this map.
If the map previously contained a mapping for this key, the old
value is replaced.
Parameters: key - key with which the specified value is to be associated. Parameters: value - value to be associated with the specified key. previous value associated with specified key, or nullif there was no mapping for key. A null return canalso indicate that the map previously associated nullwith the specified key. throws: ClassCastException - key cannot be compared with the keyscurrently in the map. throws: NullPointerException - key is null and this map usesnatural order, or its comparator does not toleratenull keys. |
remove | public Object remove(Object key)(Code) | | Removes the mapping for this key from this TreeMap if present.
Parameters: key - key for which mapping should be removed previous value associated with specified key, or nullif there was no mapping for key. A null return canalso indicate that the map previously associatednull with the specified key. throws: ClassCastException - key cannot be compared with the keyscurrently in the map. throws: NullPointerException - key is null and this map usesnatural order, or its comparator does not toleratenull keys. |
size | public int size()(Code) | | Returns the number of key-value mappings in this map.
the number of key-value mappings in this map. |
values | public Collection values()(Code) | | Returns a collection view of the values contained in this map. The
collection's iterator will return the values in the order that their
corresponding keys appear in the tree. The collection is backed by
this TreeMap instance, so changes to this map are reflected in
the collection, and vice-versa. The collection supports element
removal, which removes the corresponding mapping from the map through
the Iterator.remove, Collection.remove,
removeAll, retainAll, and clear operations.
It does not support the add or addAll operations.
a collection view of the values contained in this map. |
Methods inherited from com.jofti.util.AbstractMap | protected int chooseGrowCapacity(int size, double minLoad, double maxLoad)(Code)(Java Doc) protected int chooseHighWaterMark(int capacity, double maxLoad)(Code)(Java Doc) protected int chooseLowWaterMark(int capacity, double minLoad)(Code)(Java Doc) protected int chooseMeanCapacity(int size, double minLoad, double maxLoad)(Code)(Java Doc) protected int chooseShrinkCapacity(int size, double minLoad, double maxLoad)(Code)(Java Doc) abstract public void clear()(Code)(Java Doc) abstract public void ensureCapacity(int minCapacity)(Code)(Java Doc) public boolean isEmpty()(Code)(Java Doc) protected int nextPrime(int desiredCapacity)(Code)(Java Doc) protected void setUp(int initialCapacity, double minLoadFactor, double maxLoadFactor)(Code)(Java Doc) public int size()(Code)(Java Doc) abstract public void trimToSize()(Code)(Java Doc)
|
|
|