sos.dated.util
Class TreeMapByDate

java.lang.Object
  |
  +--sos.dated.util.AbstractDatedObject
        |
        +--sos.dated.util.AbstractDatedMap
              |
              +--sos.dated.util.AbstractMapByDate
                    |
                    +--sos.dated.util.TreeMapByDate
All Implemented Interfaces:
java.lang.Cloneable, DatedMap, DatedObject, DatedSortedMap, java.io.Serializable

public class TreeMapByDate
extends AbstractMapByDate
implements DatedSortedMap, java.io.Serializable, java.lang.Cloneable

An implementation of DatedSortedMap that maintains a java.util.TreeMap at each date where a change occurs, yielding fast date iterations and logarithmic retrievals.

This implementation is serializable and cloneable; however, it is not synchronized. To use it safely in a multi-threaded situation, wrap an instance of the dated map with a call to DatedCollections.synchronizedDatedMap.

Since:
1.0
See Also:
TreeMapByKey, HashMapByDate, DatedMap, DatedCollections.synchronizedDatedMap(DatedMap)

Nested Class Summary
 
Nested classes inherited from class sos.dated.util.DatedMap
DatedMap.Entry
 
Field Summary
 
Fields inherited from interface sos.dated.util.DatedObject
MAX_DATE, MIN_DATE
 
Constructor Summary
TreeMapByDate()
          Constructs a new instance of TreeMapByDate that uses the natural ordering of keys.
TreeMapByDate(java.util.Comparator comparator)
          Constructs a new instance of TreeMapByDate that uses the specified comparator to order the keys.
TreeMapByDate(DatedMap datedMap)
          Constructs a new instance of TreeMapByDate that uses the natural ordering of keys and initially contains the mappings of datedMap.
TreeMapByDate(DatedSortedMap datedSortedMap)
          Constructs a new TreeMapByDate that initially contains the mappings of datedSortedMap.
 
Method Summary
 java.lang.Object clone()
          Creates and returns a copy of this object.
 java.util.Comparator comparator()
          Returns the comparator used to sorted the keys of this dated map.
protected  java.util.Map copyMap(java.util.Map map)
          Returns a new TreeMap initialized with the mappings of map.
protected  java.util.Map createMap()
          Returns a freshly created, empty TreeMap.
 java.lang.Object firstKey(java.util.Date date)
          Returns the smallest key in this dated map at the specified date.
 DatedSortedMap headMap(java.lang.Object toKey)
          Returns a view of this dated map of all mappings whose keys precede toKey.
 java.lang.Object lastKey(java.util.Date date)
          Returns the largest key in this dated map at the specified date.
 DatedSortedMap subMap(java.lang.Object fromKey, java.lang.Object toKey)
          Returns a view of this dated map of all mappings whose keys fall between fromKey (inclusive) and toKey (exclusive).
 DatedSortedMap tailMap(java.lang.Object fromKey)
          Returns a view of this dated map of all mappings whose keys are greater than or equal to toKey.
 
Methods inherited from class sos.dated.util.AbstractMapByDate
checkForComodification, containsKey, containsValue, dateIterator, entrySet, modCount, put, remove, upModCount
 
Methods inherited from class sos.dated.util.AbstractDatedMap
clear, containsKeyThroughout, containsValueThroughout, equals, excludesKeyThroughout, excludesValueThroughout, get, get, hashCode, hasSizeThroughout, isEmpty, isEmptyThroughout, keySet, putAll, size, toString, values
 
Methods inherited from class sos.dated.util.AbstractDatedObject
dateIterator, equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface sos.dated.util.DatedMap
clear, containsKey, containsKeyThroughout, containsValue, containsValueThroughout, entrySet, equals, excludesKeyThroughout, excludesValueThroughout, get, get, hashCode, hasSizeThroughout, isEmpty, isEmptyThroughout, keySet, put, putAll, remove, size, values
 
Methods inherited from interface sos.dated.util.DatedObject
dateIterator, dateIterator, equals, hashCode, toString
 

Constructor Detail

TreeMapByDate

public TreeMapByDate()
Constructs a new instance of TreeMapByDate that uses the natural ordering of keys. All keys placed in this map must implement the Comparable interface.


TreeMapByDate

public TreeMapByDate(DatedMap datedMap)
Constructs a new instance of TreeMapByDate that uses the natural ordering of keys and initially contains the mappings of datedMap. All keys laced in this map must implement the Comparable interface.

Parameters:
datedMap - dated map with which to initialize this TreeMapByDate
Throws:
java.lang.NullPointerException - if datedMap is null.

TreeMapByDate

public TreeMapByDate(java.util.Comparator comparator)
Constructs a new instance of TreeMapByDate that uses the specified comparator to order the keys. The comparator should not throw an exception for any key placed in this map. A comparator with the value null causes this map to rely on the natural ordering of the keys.

Parameters:
comparator - object used to order the keys (may be null)

TreeMapByDate

public TreeMapByDate(DatedSortedMap datedSortedMap)
Constructs a new TreeMapByDate that initially contains the mappings of datedSortedMap. This map uses the specified dated map's comparator to order the keys.

Parameters:
datedSortedMap - dated sorted map with which to initialize this TreeMapByDate
Throws:
java.lang.NullPointerException - if datedSortedMap is null.
Method Detail

clone

public java.lang.Object clone()
Description copied from class: AbstractDatedMap
Creates and returns a copy of this object. Subclasses that wish to be cloneable should override this method but first call their parent's clone method.

Overrides:
clone in class AbstractMapByDate
Returns:
a copy of this dated map

comparator

public java.util.Comparator comparator()
Description copied from interface: DatedSortedMap
Returns the comparator used to sorted the keys of this dated map. A returned null value indicates that this dated map uses the keys' natural ordering.

Specified by:
comparator in interface DatedSortedMap
Returns:
the comparator that orders the keys (may be null)

createMap

protected java.util.Map createMap()
Returns a freshly created, empty TreeMap.

Specified by:
createMap in class AbstractMapByDate
Returns:
a freshly created, empty TreeMap.

copyMap

protected java.util.Map copyMap(java.util.Map map)
Returns a new TreeMap initialized with the mappings of map.

Overrides:
copyMap in class AbstractMapByDate
Parameters:
map - mappings to be included in the new map
Returns:
a new TreeMap initialized with the mappings of map.

firstKey

public java.lang.Object firstKey(java.util.Date date)
Description copied from interface: DatedSortedMap
Returns the smallest key in this dated map at the specified date.

Specified by:
firstKey in interface DatedSortedMap
Parameters:
date - date for which to find the smallest key
Returns:
the smallest key at date

headMap

public DatedSortedMap headMap(java.lang.Object toKey)
Description copied from interface: DatedSortedMap
Returns a view of this dated map of all mappings whose keys precede toKey. The key toKey does not have to appear in this dated map nor will it ever appear in the returned map. The returned map is a fully functional dated sorted map that is tied to this map. Changes to either will be reflected in the other. Any attempt to add a key greater than or equal to toKey will throw an IllegalArgumentException.

Specified by:
headMap in interface DatedSortedMap
Parameters:
toKey - upper bound of the keys of the returned map (exclusive)
Returns:
the front portion of this ordered dated map up to, but not including, the specified key

lastKey

public java.lang.Object lastKey(java.util.Date date)
Description copied from interface: DatedSortedMap
Returns the largest key in this dated map at the specified date.

Specified by:
lastKey in interface DatedSortedMap
Parameters:
date - date for which to find the largest key
Returns:
the largest key at date

subMap

public DatedSortedMap subMap(java.lang.Object fromKey,
                             java.lang.Object toKey)
Description copied from interface: DatedSortedMap
Returns a view of this dated map of all mappings whose keys fall between fromKey (inclusive) and toKey (exclusive). Neither key has to appear in this dated map. The returned map is a fully functional dated sorted map that is closely tied to this map. Changes to either will be reflected in the other. Any attempt to add a key outside the specified key range will throw an IllegalArgumentException.

Specified by:
subMap in interface DatedSortedMap
Parameters:
fromKey - lower bound of the keys of the returned map (inclusive)
toKey - upper bound of the keys of the returned map (exclusive)
Returns:
the middle portion of this ordered dated map from fromKey (inclusive) to toKey (exclusive)

tailMap

public DatedSortedMap tailMap(java.lang.Object fromKey)
Description copied from interface: DatedSortedMap
Returns a view of this dated map of all mappings whose keys are greater than or equal to toKey. The key toKey does not have to appear in this dated map. The returned map is a fully functional dated sorted map that is closely tied to this map. Changes to either will be reflected in the other. Any attempt to add a key less than fromKey will throw an IllegalArgumentException.

Specified by:
tailMap in interface DatedSortedMap
Parameters:
fromKey - lower bound of the keys of the returned map (inclusive)
Returns:
the front portion of this ordered dated map up to, but not including, the specified key


Copyright 2003 Side of Software (SOS). All rights reserved.