net.sf.beanlib.utils.range
Class RangeTreeMap<T,K extends RangeBoundable<T>,V>

java.lang.Object
  extended by net.sf.beanlib.utils.range.AbstractMap<K,V>
      extended by net.sf.beanlib.utils.range.ExtensibleTreeMap<K,V>
          extended by net.sf.beanlib.utils.range.RangeTreeMap<T,K,V>
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>, SortedMap<K,V>, SortedRangeMap<T,K,V>

public class RangeTreeMap<T,K extends RangeBoundable<T>,V>
extends ExtensibleTreeMap<K,V>
implements SortedRangeMap<T,K,V>

Range Tree Map that supports retrieval by using a point that falls within the range of a key which implements RangeBoundable.

Author:
Joe D. Velopar
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.beanlib.utils.range.ExtensibleTreeMap
ExtensibleTreeMap.NodeEntry<K,V>
 
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 long serialVersionUID
           
 
Fields inherited from class net.sf.beanlib.utils.range.ExtensibleTreeMap
root
 
Fields inherited from class net.sf.beanlib.utils.range.AbstractMap
keySet, values
 
Constructor Summary
RangeTreeMap()
           
RangeTreeMap(Comparator<? super K> c)
           
RangeTreeMap(Map<? extends K,? extends V> m)
           
RangeTreeMap(SortedMap<K,? extends V> m)
           
RangeTreeMap(SortedRangeMap<T,K,? extends V> m)
           
 
Method Summary
private  int comparePointToRange(Comparable<T> point, RangeBoundable<T> range)
          Compares a point to a range.
 boolean containsKeyPoint(Comparable<T> point)
          Returns true if this map contains a mapping of a key with a range that the specified point falls within.
 V getByPoint(Comparable<T> point)
          Returns the value to which this map maps a key with a range that the specified point falls within.
private  ExtensibleTreeMap.NodeEntry<K,V> getEntryByPoint(Comparable<T> point)
           
 
Methods inherited from class net.sf.beanlib.utils.range.ExtensibleTreeMap
addAllForTreeSet, clear, clone, comparator, containsKey, containsValue, entrySet, firstKey, get, headMap, keySet, lastKey, put, putAll, readTreeSet, remove, size, subMap, tailMap, values
 
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.SortedMap
comparator, firstKey, headMap, lastKey, subMap, tailMap
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

RangeTreeMap

public RangeTreeMap()

RangeTreeMap

public RangeTreeMap(Comparator<? super K> c)

RangeTreeMap

public RangeTreeMap(Map<? extends K,? extends V> m)

RangeTreeMap

public RangeTreeMap(SortedMap<K,? extends V> m)

RangeTreeMap

public RangeTreeMap(SortedRangeMap<T,K,? extends V> m)
Method Detail

getByPoint

public V getByPoint(Comparable<T> point)
Description copied from interface: SortedRangeMap
Returns the value to which this map maps a key with a range that the specified point falls within. Returns null if the map contains no mapping for any key with such range. A return value of null does not necessarily indicate that the map contains no mapping for a key with such range; it's also possible that the map explicitly maps the key with such range to null. The containsKeyPoint operation may be used to distinguish these two cases.

Specified by:
getByPoint in interface SortedRangeMap<T,K extends RangeBoundable<T>,V>
Parameters:
point - the point that falls within the range of a key whose associated value is to be returned.
Returns:
the value to which this map maps a key with a range that the specified point falls within, or null if the map contains no mapping for any key with such range.
See Also:
SortedRangeMap.containsKeyPoint(Comparable)

getEntryByPoint

private ExtensibleTreeMap.NodeEntry<K,V> getEntryByPoint(Comparable<T> point)

containsKeyPoint

public boolean containsKeyPoint(Comparable<T> point)
Description copied from interface: SortedRangeMap
Returns true if this map contains a mapping of a key with a range that the specified point falls within.

Specified by:
containsKeyPoint in interface SortedRangeMap<T,K extends RangeBoundable<T>,V>
Parameters:
point - point to be tested.
Returns:
true if this map contains a mapping of a key with a range that the specified point falls within.

comparePointToRange

private int comparePointToRange(Comparable<T> point,
                                RangeBoundable<T> range)
Compares a point to a range.

Parameters:
point - given point
range - given range
Returns:
zero if the given point is within the given range (inclusive); less than zero if the point is below the range; or greater than zero if the point is above the range.