edu.neu.ccs.quick
Class QuickTreeMap

java.lang.Object
  extended byjava.util.AbstractMap
      extended byjava.util.TreeMap
          extended byedu.neu.ccs.quick.QuickTreeMap
All Implemented Interfaces:
Cloneable, Map, Serializable, SortedMap

public class QuickTreeMap
extends TreeMap

QuickTreeMap extends TreeMap by adding two constructors and three methods putPairs, setPairs, and removeKeys that handle an array of Object at once.

In addition, symmetric methods are added that will hash both a key to its value and a value to its key. Valid use of these symmetric methods requires that keys and values be comparable.

All constructors of the original TreeMap class are provided as well.

The only inherited methods that are overridden are those that will throw an exception on null arguments. In this class, such methods will handle null in a sensible fashion.

Since:
2.3
Version:
2.3
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.TreeMap
 
Nested classes inherited from class java.util.AbstractMap
 
Field Summary
 
Fields inherited from class java.util.TreeMap
 
Fields inherited from class java.util.AbstractMap
 
Constructor Summary
QuickTreeMap()
          A constructor that delegates to class TreeMap.
QuickTreeMap(Comparator c)
          A constructor that delegates to class TreeMap.
QuickTreeMap(Comparator c, Object[][] pairs)
          Constructor that sets the Comparator and then adds the given 2-dimensional array of key-value pairs one-by-one to the tree map.
QuickTreeMap(Map m)
          A constructor that delegates to class TreeMap.
QuickTreeMap(Object[][] pairs)
          Constructor that adds the given 2-dimensional array of key-value pairs one-by-one to the tree map.
QuickTreeMap(SortedMap m)
          A constructor that delegates to class TreeMap.
 
Method Summary
 boolean containsKey(Object key)
          Returns true if the map contains the key.
 Object get(Object key)
          Returns the value to which the map maps the specified key.
 SortedMap headMap(Object key)
          Returns a view of the portion of this map whose keys are strictly less than the key.
 Object put(Object key, Object value)
          Associates the specified value with the specified key in this map.
 void putPairs(Object[][] pairs)
          Method that adds the given 2-dimensional array of key-value pairs one-by-one to the tree map.
 void putPairsSymmetric(Object[][] pairs)
          Method that adds the given 2-dimensional array of key-value pairs one-by-one symmetrically to the tree map.
 void putSymmetric(Object key, Object value)
          Method that adds the key-value pair symmetrically to the tree map, that is, the key maps to the value and the value maps to the key.
 Object remove(Object key)
          Removes the mapping for this key from this map if present.
 void removeKeys(Object[] keys)
          Method that removes the given array of keys one-by-one from the tree map.
 void setPairs(Object[][] pairs)
          Method that first clears this tree map of any existing pairs and then adds the given array of pairs one-by-one to the tree map.
 void setPairsSymmetric(Object[][] pairs)
          Method that first clears this tree map of any existing pairs and then adds the given array of pairs one-by-one symmetrically to the tree map.
 SortedMap subMap(Object lower, Object upper)
          Returns a view of the portion of this map whose keys are greater than or equal to lower and strictly less than upper.
 SortedMap tailMap(Object key)
          Returns a view of the portion of this map whose keys are greater than or equal to the key.
 
Methods inherited from class java.util.TreeMap
clear, clone, comparator, containsValue, entrySet, firstKey, keySet, lastKey, putAll, size, values
 
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
 

Constructor Detail

QuickTreeMap

public QuickTreeMap()
A constructor that delegates to class TreeMap.


QuickTreeMap

public QuickTreeMap(Comparator c)
A constructor that delegates to class TreeMap.


QuickTreeMap

public QuickTreeMap(Map m)
A constructor that delegates to class TreeMap.


QuickTreeMap

public QuickTreeMap(SortedMap m)
A constructor that delegates to class TreeMap.


QuickTreeMap

public QuickTreeMap(Object[][] pairs)

Constructor that adds the given 2-dimensional array of key-value pairs one-by-one to the tree map.

Parameters:
pairs - the array of pairs to add to this tree map
See Also:
QuickTreeMap(Comparator, Object[][]), putPairs(Object[][])

QuickTreeMap

public QuickTreeMap(Comparator c,
                    Object[][] pairs)

Constructor that sets the Comparator and then adds the given 2-dimensional array of key-value pairs one-by-one to the tree map.

Parameters:
c - the comparator
pairs - the array of pairs to add to this tree map
See Also:
QuickTreeMap(Object[][]), putPairs(Object[][])
Method Detail

put

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.

If the key is null, then simply returns null.

Parameters:
key - the key associated with the specified value
value - the value to be associated with the specified key
Returns:
previous value associated with specified key, or null if there was no mapping for key; a null return can also indicate that the map previously associated null with the specified key
See Also:
TreeMap.put(Object, Object)

get

public Object get(Object key)

Returns the value to which the map maps the specified key. Returns null if the map contains no mapping for the key. A return value of null does not necessarily indicate that the map contains no mapping for the key. It is also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

If the key is null, then simply returns null.

Parameters:
key - the key whose associated value is to be returned
Returns:
the value to which the map maps the specified key, or null if the map contains no mapping for the key
See Also:
TreeMap.get(Object)

remove

public Object remove(Object key)

Removes the mapping for this key from this map if present.

If the key is null, then simply returns null.

Parameters:
key - the key whose mapping should be removed
Returns:
previous value associated with specified key, or null if there was no mapping for key; a null return can also indicate that the map previously associated null with the specified key.
See Also:
TreeMap.remove(Object)

containsKey

public boolean containsKey(Object key)

Returns true if the map contains the key.

If the key is null, then simply returns false.

Parameters:
key - the key whose presence in the map is to be tested
Returns:
true if the key is non-null and is a key in the map
See Also:
TreeMap.containsKey(Object)

headMap

public SortedMap headMap(Object key)

Returns a view of the portion of this map whose keys are strictly less than the key. The returned sorted map is backed by this map, so changes in the returned sorted map are reflected in this map, and vice-versa.

The sorted map returned by this method will throw an IllegalArgumentException if the user attempts to insert a key greater than or equal to the given key.

If key is null, then simply returns null.

Parameters:
key - the strict upper bound for the keys in the returned map
Returns:
the submap with keys strictly less than the given key
See Also:
TreeMap.headMap(Object)

tailMap

public SortedMap tailMap(Object key)

Returns a view of the portion of this map whose keys are greater than or equal to the key. The returned sorted map is backed by this map, so changes in the returned sorted map are reflected in this map, and vice-versa.

The sorted map returned by this method will throw an IllegalArgumentException if the user attempts to insert a key less than the given element.

If key is null, then simply returns null.

Parameters:
key - the lower bound for the keys in the returned map
Returns:
the submap with keys greater than or equal to the given key
See Also:
TreeMap.tailMap(Object)

subMap

public SortedMap subMap(Object lower,
                        Object upper)

Returns a view of the portion of this map whose keys are greater than or equal to lower and strictly less than upper. The returned sorted map is backed by this map, so changes in the returned sorted map are reflected in this map, and vice-versa.

The sorted map returned by this method will throw an IllegalArgumentException if the user attempts to insert a key less than lower or greater than or equal to upper.

If either lower or upper is null, then simply returns null.

Parameters:
lower - the lower bound for the keys in the returned map
upper - the strict upper bound for the keys in the returned map
Returns:
the submap with keys greater than or equal to lower and less than upper
See Also:
TreeMap.subMap(Object, Object)

putPairs

public void putPairs(Object[][] pairs)

Method that adds the given 2-dimensional array of key-value pairs one-by-one to the tree map.

If pairs is null, then does nothing.

Ignores any subarray pairs[i] that is null or not of length 2.

Ignores key-value pairs in which the key is null.

Parameters:
pairs - the array of pairs to add to this tree map
See Also:
QuickTreeMap(Object[][]), QuickTreeMap(Comparator, Object[][]), setPairs(Object[][]), removeKeys(Object[]), putSymmetric(Object, Object), putPairsSymmetric(Object[][]), setPairsSymmetric(Object[][])

setPairs

public void setPairs(Object[][] pairs)

Method that first clears this tree map of any existing pairs and then adds the given array of pairs one-by-one to the tree map.

If pairs is null, then this method is equivalent to the inherited method clear.

Ignores any subarray pairs[i] that is null or not of length 2.

Ignores key-value pairs in which the key is null.

Parameters:
pairs - the array of pairs to add to this tree map after clearance
See Also:
putPairs(Object[][]), removeKeys(Object[]), putSymmetric(Object, Object), putPairsSymmetric(Object[][]), setPairsSymmetric(Object[][])

removeKeys

public void removeKeys(Object[] keys)

Method that removes the given array of keys one-by-one from the tree map.

If keys is null, then does nothing.

Ignores key items that are null.

Parameters:
keys - the array of keys to remove from this tree map
See Also:
putPairs(Object[][]), setPairs(Object[][]), putSymmetric(Object, Object), putPairsSymmetric(Object[][]), setPairsSymmetric(Object[][])

putSymmetric

public void putSymmetric(Object key,
                         Object value)

Method that adds the key-value pair symmetrically to the tree map, that is, the key maps to the value and the value maps to the key.

Does nothing if either the key or the value is null.

Valid use of this method requires that keys and values be comparable.

Parameters:
key - the key in the key-value pair
value - the value in the key-value pair
See Also:
putPairs(Object[][]), setPairs(Object[][]), removeKeys(Object[]), putPairsSymmetric(Object[][]), setPairsSymmetric(Object[][])

putPairsSymmetric

public void putPairsSymmetric(Object[][] pairs)

Method that adds the given 2-dimensional array of key-value pairs one-by-one symmetrically to the tree map.

If pairs is null, then does nothing.

Ignores any subarray pairs[i] that is null or not of length 2.

Ignores key-value pairs in which either item is null.

Valid use of this method requires that keys and values be comparable.

Parameters:
pairs - the array of pairs to add symmetrically to this tree map
See Also:
putPairs(Object[][]), setPairs(Object[][]), removeKeys(Object[]), putSymmetric(Object, Object), setPairsSymmetric(Object[][])

setPairsSymmetric

public void setPairsSymmetric(Object[][] pairs)

Method that first clears this tree map of any existing pairs and then adds the given array of pairs one-by-one symmetrically to the tree map.

If pairs is null, then this method is equivalent to the inherited method clear.

Ignores any subarray pairs[i] that is null or not of length 2.

Ignores key-value pairs in which either item is null.

Valid use of this method requires that keys and values be comparable.

Parameters:
pairs - the array of pairs to add symmetrically to this tree map after clearance
See Also:
putPairs(Object[][]), setPairs(Object[][]), removeKeys(Object[]), putSymmetric(Object, Object), putPairsSymmetric(Object[][])