sos.dated.util
Class AbstractMapByDate

java.lang.Object
  |
  +--sos.dated.util.AbstractDatedObject
        |
        +--sos.dated.util.AbstractDatedMap
              |
              +--sos.dated.util.AbstractMapByDate
All Implemented Interfaces:
DatedMap, DatedObject, java.io.Serializable
Direct Known Subclasses:
HashMapByDate, IdentityHashMapByDate, TreeMapByDate

public abstract class AbstractMapByDate
extends AbstractDatedMap
implements DatedMap, java.io.Serializable

A partial implementation of DatedMap that maintains a complete, non-dated map at each date where a change occurs. This class allows the client to use a custom implementation of java.util.Map inside a date-indexed map with minimal effort. To do so, simply extend this class and implement the abstract createMap method.

Since:
1.0

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
protected AbstractMapByDate()
          No-argument constructor available only to subclasses.
 
Method Summary
protected  void checkForComodification(int expectedModCount, java.util.Date date)
          Throws a ConcurrentModificationException if the expected modification count does not equal the actual modification count for the specified date.
protected  java.lang.Object clone()
          Creates and returns a copy of this object.
 boolean containsKey(java.lang.Object key, java.util.Date date)
          Returns true if this dated map contains the specified key at the specified date.
 boolean containsValue(java.lang.Object value, java.util.Date date)
          Returns true if any key maps to the specified value at the specified date.
protected  java.util.Map copyMap(java.util.Map map)
          Returns a fresh map equivalent to the specified map.
protected abstract  java.util.Map createMap()
           
 DateIterator dateIterator(java.util.Date date)
          Returns an iterator of the dates of when this dated type has changed.
 DatedSet entrySet()
          Returns a modifiable view of the mappings of this dated map.
protected  int modCount(java.util.Date date)
           
 DatedValue put(java.lang.Object key, java.lang.Object value, java.util.Date from, java.util.Date to)
          Associates key with value in this dated map during the specified date range.
 DatedValue remove(java.lang.Object key, java.util.Date from, java.util.Date to)
          Removes any values associated with the specified key in the specified date range.
protected  void upModCount(java.util.Date from, java.util.Date to)
           
 
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, containsKeyThroughout, containsValueThroughout, equals, excludesKeyThroughout, excludesValueThroughout, get, get, hashCode, hasSizeThroughout, isEmpty, isEmptyThroughout, keySet, putAll, size, values
 
Methods inherited from interface sos.dated.util.DatedObject
dateIterator, equals, hashCode, toString
 

Constructor Detail

AbstractMapByDate

protected AbstractMapByDate()
No-argument constructor available only to subclasses.

Method Detail

checkForComodification

protected void checkForComodification(int expectedModCount,
                                      java.util.Date date)
Throws a ConcurrentModificationException if the expected modification count does not equal the actual modification count for the specified date.

Parameters:
expectedModCount - the caller's expected modification count
date - the date in question
Throws:
java.util.ConcurrentModificationException - if the expected modification count does not equal the actual modification count for the specified date

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException
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 AbstractDatedMap
Returns:
a copy of this dated map
Throws:
java.lang.CloneNotSupportedException - if this object's class does not support the Cloneable interface.

containsKey

public boolean containsKey(java.lang.Object key,
                           java.util.Date date)
Description copied from interface: DatedMap
Returns true if this dated map contains the specified key at the specified date.

Specified by:
containsKey in interface DatedMap
Overrides:
containsKey in class AbstractDatedMap
Parameters:
key - key whose presence is to be tested
date - date at which this map is to be queried
Returns:
true if this dated map contains the specified key at the specified date

containsValue

public boolean containsValue(java.lang.Object value,
                             java.util.Date date)
Description copied from interface: DatedMap
Returns true if any key maps to the specified value at the specified date.

Specified by:
containsValue in interface DatedMap
Overrides:
containsValue in class AbstractDatedMap
Parameters:
value - value whose presence is to be tested
date - date at which this map is to be queried
Returns:
true if any key maps to the specified value at the specified date

copyMap

protected java.util.Map copyMap(java.util.Map map)
Returns a fresh map equivalent to the specified map. This implementation calls createMap to get a new, empty map and then putAll to populate the map. A subclass should override this method if it can copy the specified map more efficiently (such as by invoking clone or using a copy constructor). This AbstractMapByDate will not work properly if the returned map is not independent of the parameter.

Parameters:
map - mappings to be included in the new map
Returns:
a map equivalent to yet independent of the specified map

createMap

protected abstract java.util.Map createMap()

dateIterator

public DateIterator dateIterator(java.util.Date date)
Returns an iterator of the dates of when this dated type has changed.

Specified by:
dateIterator in interface DatedObject
Specified by:
dateIterator in class AbstractDatedObject
Parameters:
date - date to position the iteration
Returns:
an iterator of the dates of when this dated type has changed.

entrySet

public DatedSet entrySet()
Description copied from interface: DatedMap
Returns a modifiable view of the mappings of this dated map. Each element of the returned view implement java.util.Map.

Specified by:
entrySet in interface DatedMap
Specified by:
entrySet in class AbstractDatedMap
Returns:
a dated set of the entries of this dated map

modCount

protected int modCount(java.util.Date date)

put

public DatedValue put(java.lang.Object key,
                      java.lang.Object value,
                      java.util.Date from,
                      java.util.Date to)
Description copied from interface: DatedMap
Associates key with value in this dated map during the specified date range.

Specified by:
put in interface DatedMap
Overrides:
put in class AbstractDatedMap
Parameters:
key - key to put in this dated map
value - value to map to the key
from - starting date of the range (inclusive) to put the mapping
to - ending date of the range (exclusive) to put the mapping
Returns:
the value(s) mapped to the specified key in the specified range before the invocation

remove

public DatedValue remove(java.lang.Object key,
                         java.util.Date from,
                         java.util.Date to)
Description copied from interface: DatedMap
Removes any values associated with the specified key in the specified date range.

Specified by:
remove in interface DatedMap
Overrides:
remove in class AbstractDatedMap
Parameters:
key - key indicating which mapping to remove
from - starting date of the range (inclusive) to remove the mapping
to - ending date of the range (exclusive) to remove the mapping
Returns:
the value(s) mapped to the specified key in the specified range before the invocation

upModCount

protected void upModCount(java.util.Date from,
                          java.util.Date to)


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