Side of Software
Dated Collections Library 2.0

sos.dated.util
Class AbstractMapByDate<K,V,D>

java.lang.Object
  extended by sos.dated.util.AbstractDatedObject<D>
      extended by sos.dated.util.AbstractDatedMap<K,V,D>
          extended by sos.dated.util.AbstractMapByDate<K,V,D>
Type Parameters:
K - the type of keys maintained by this dated map
V - the type of values maintained by this dated map
D - the type of dates used by this dated map
All Implemented Interfaces:
java.io.Serializable, DatedMap<K,V,D>, DatedObject<D>
Direct Known Subclasses:
HashMapByDate, IdentityHashMapByDate, LinkedHashMapByDate, TreeMapByDate

public abstract class AbstractMapByDate<K,V,D>
extends AbstractDatedMap<K,V,D>
implements DatedMap<K,V,D>, 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/interfaces inherited from interface sos.dated.util.DatedMap
DatedMap.Entry<K,V,D>
 
Constructor Summary
protected AbstractMapByDate()
          No-argument constructor available only to subclasses.
 
Method Summary
protected  void checkForComodification(int expectedModCount, D at)
          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 shallow copy of this object.
 boolean containsKey(java.lang.Object key, D at)
          Returns true if this dated map contains the specified key at the specified date.
 boolean containsValue(java.lang.Object value, D at)
          Returns true if any key maps to the specified value at the specified date.
protected  java.util.Map<K,V> copyMap(java.util.Map<K,V> map, D from, D to)
          Returns a fresh map equivalent to the specified map.
protected abstract  java.util.Map<K,V> createMap(D from, D to)
          Creates and returns a new empty map given the specified date range.
 DateIterator<D> dateIterator(D at)
          Returns an iterator of the dates of when this dated type has changed.
 DatedSet<DatedMap.Entry<K,V,D>,D> entrySet()
          Returns a modifiable view of the mappings of this dated map.
 V get(java.lang.Object key, D at)
          Retrieves the value associated with the specified key on the specified date, or null if this dated map does not contain a mapping for the key at that date.
protected  int modCount(D at)
          Returns the modification count at the specified date, if assertions are enabled; otherwise, returns 0.
 DatedValue<V,D> put(K key, V value, D from, D to)
          Associates key with value in this dated map during the specified date range (optional operation).
 void putAll(DatedMap<? extends K,? extends V,D> datedMap)
          Places all mappings in datedMap into this dated map (optional operation).
 DatedValue<V,D> remove(java.lang.Object key, D from, D to)
          Removes any values associated with the specified key in the specified date range (optional operation).
protected  void upModCount(D from, D to)
          Adds 1 to the modification counts throughout the specified date range, if assertions are enabled; otherwise, does nothing.
 
Methods inherited from class sos.dated.util.AbstractDatedMap
clear, containsKeyThroughout, containsValueThroughout, equals, excludesKeyThroughout, excludesValueThroughout, get, hashCode, hasSizeThroughout, isEmpty, isEmptyThroughout, keySet, 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, hashCode, hasSizeThroughout, isEmpty, isEmptyThroughout, keySet, 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,
                                      D at)
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
at - 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 shallow 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<K,V,D>
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,
                           D at)
Description copied from class: AbstractDatedMap
Returns true if this dated map contains the specified key at the specified date. This implementation iterates through the entries at the specified date, returning true if the specified key is found.

Specified by:
containsKey in interface DatedMap<K,V,D>
Overrides:
containsKey in class AbstractDatedMap<K,V,D>
Parameters:
key - key whose presence is to be tested
at - 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,
                             D at)
Description copied from class: AbstractDatedMap
Returns true if any key maps to the specified value at the specified date. This implementation iterates through the entries at the specified date and returns true if it encounters the specified value.

Specified by:
containsValue in interface DatedMap<K,V,D>
Overrides:
containsValue in class AbstractDatedMap<K,V,D>
Parameters:
value - value whose presence is to be tested
at - 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<K,V> copyMap(java.util.Map<K,V> map,
                                     D from,
                                     D to)
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 map.

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<K,V> createMap(D from,
                                                D to)
Creates and returns a new empty map given the specified date range. The returned map will hold the entries for the given date range and must support the put and putAll operations.

Parameters:
from - start date (inclusive) for which to create the map
to - end date (exclusive) for which to create the map
Returns:
a map to hold the entries for the specified date range

dateIterator

public DateIterator<D> dateIterator(D at)
Returns an iterator of the dates of when this dated type has changed.

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

entrySet

public DatedSet<DatedMap.Entry<K,V,D>,D> entrySet()
Description copied from interface: DatedMap
Returns a modifiable view of the mappings of this dated map. The returned dated set is backed by this dated map, so changes to the dated map are reflected in the dated set and vice versa. The dated set supports removal but not insertion.

Specified by:
entrySet in interface DatedMap<K,V,D>
Specified by:
entrySet in class AbstractDatedMap<K,V,D>
Returns:
a dated set of the entries in this dated map

get

public V get(java.lang.Object key,
             D at)
Description copied from class: AbstractDatedMap
Retrieves the value associated with the specified key on the specified date, or null if this dated map does not contain a mapping for the key at that date.

This implementation iterates through the entry set at this date, returning the associated value if the key is found.

Specified by:
get in interface DatedMap<K,V,D>
Overrides:
get in class AbstractDatedMap<K,V,D>
Parameters:
key - key whose mapping is to be retrieved
at - date at which this map is to be queried
Returns:
the value associated with the specified key on the specified date

modCount

protected int modCount(D at)
Returns the modification count at the specified date, if assertions are enabled; otherwise, returns 0. The modification count is the number of times that this dated map has been structurally modified at the specified date. The modification count is used to detect concurrent modification exceptions.

Parameters:
at - date for which the modification count is requested
Returns:
the modification count at the specified date

put

public DatedValue<V,D> put(K key,
                           V value,
                           D from,
                           D to)
Description copied from class: AbstractDatedMap
Associates key with value in this dated map during the specified date range (optional operation). This implementation throws an UnsupportedOperationException.

Specified by:
put in interface DatedMap<K,V,D>
Overrides:
put in class AbstractDatedMap<K,V,D>
Parameters:
key - key to put in this dated map
value - value to map to the key
from - starting date (inclusive) at which to put the mapping
to - ending date (exclusive) at which to put the mapping
Returns:
the value(s) mapped to the specified key in the specified range before the invocation

putAll

public void putAll(DatedMap<? extends K,? extends V,D> datedMap)
Description copied from class: AbstractDatedMap
Places all mappings in datedMap into this dated map (optional operation). If this dated map and the map passed in are connected in a way that the map changes during any additions, this method is undefined. This means that this method cannot handle this as the parameter. This implementation iterates through the dates of datedMap, invoking put for each mapping and date range defined in datedMap.

Specified by:
putAll in interface DatedMap<K,V,D>
Overrides:
putAll in class AbstractDatedMap<K,V,D>
Parameters:
datedMap - mappings to put in this dated map

remove

public DatedValue<V,D> remove(java.lang.Object key,
                              D from,
                              D to)
Description copied from class: AbstractDatedMap
Removes any values associated with the specified key in the specified date range (optional operation). This implementation iterates through the entry set at each date between from and to and invokes remove on the iterator at the first occurrence of an entry with the key key.

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

upModCount

protected void upModCount(D from,
                          D to)
Adds 1 to the modification counts throughout the specified date range, if assertions are enabled; otherwise, does nothing.

Parameters:
from - start date (inclusive) for which to increase the modification counts
to - end date (inclusive) for which to increase the modification counts
See Also:
modCount(D)

Side of Software
Dated Collections Library 2.0

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