Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

jtemporal
Class TreeTemporalMultiMap  view TreeTemporalMultiMap download TreeTemporalMultiMap.java

java.lang.Object
  extended byjtemporal.AbstractTemporalMultiMap
      extended byjtemporal.TreeTemporalMultiMap
All Implemented Interfaces:
TemporalMultiMap

public class TreeTemporalMultiMap
extends AbstractTemporalMultiMap

Maintains internally a TreeMap over the periods and an HashMap over the values so that query performances are acceptable for queries in both dimensions even when the collection is very large.

Note: this implementation is not synchronized. If multiple threads access the map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more mappings; merely changing the value associated with an existing key is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the map. If no such object exists, the map should be "wrapped" using the SynchronizedTemporalMultiMap.getInstance method. This is best done at creation time, to prevent accidental unsynchronized access to the map:

     TemporalMultiMap tm = SynchronizedTemporalMap.getInstance(new TreeTemporalMultiMap(...));
 

Note the synchronizing proxies are not available yet.

(internal structure)
In a future version, this structure will be optimized in order to reduce the memory usage when the map contains few values.

Version:
$Id$

Nested Class Summary
(package private)  class TreeTemporalMultiMap.SortedMapSubscriber
          Listening the inner loop treeMaps, allows to know what is really changed, because for example a "put" invocation can partially overwrite preexisting information.
private  class TreeTemporalMultiMap.ValueSetView
           
 
Field Summary
private  NodeParent nodeDeadListener
          This inner class has been created because it is impossible to implement a non public insterface without declaring the implementing methods as public :-( (http://developer.java.sun.com/developer/bugParade/bugs/4456057.html)
private  java.util.SortedMap timeMap
           
private  java.util.Map valueMap
           
private  java.lang.Class valueType
           
 
Constructor Summary
TreeTemporalMultiMap()
          Default constructor.
TreeTemporalMultiMap(java.lang.Class valueType)
           
 
Method Summary
 void clear()
          Removes all the mappings from this map (optional operation).
 boolean contains(Instant instant, java.lang.Object value)
          Returns true if there is a mapping for this value at the given instant.
 boolean containsValue(java.lang.Object value)
          Returns true if if ther is a mapping for the specified value.
 Instant firstInstant(java.lang.Object value)
          Returns the first (lowest) instant currently defined for the given value.
 Period firstPeriod(java.lang.Object value)
          Returns the first (lowest) period currently defined for the given value.
 Period getPeriod(Instant instant, java.lang.Object value)
          Returns the period of the mapping valid at the specified instant for the value.
private  TemporalUnaryMap getTemporalUnaryMap(java.lang.Object value)
           
private  TemporalUnaryMap getTemporalUnaryMapOrNull(java.lang.Object value)
           
 boolean isEmpty()
          Returns true if this map contains no Period-value mappings.
 Instant lastInstant(java.lang.Object value)
          Returns the last (highest) instant currently defined for the given value.
 Period lastPeriod(java.lang.Object value)
          Returns the last (highest) period currently defined for the given value.
 java.util.Set periodSet(java.lang.Object value)
          Returns a set view of the periods contained in this map for the give value.
 boolean put(Period p, java.lang.Object value)
          Associates the specified value to the specified Period in this map.
 boolean remove(Period p, java.lang.Object value)
          Removes the mapping(s) for this period and value from this map if present (optional operation).
 boolean removePeriod(Period p)
          Removes all the mapping(s) for this period from this map if present (optional operation).
 void removeValue(java.lang.Object value)
          Removes all the mapping(s) for this value from this map if present (optional operation).
 int size(java.lang.Object value)
          Returns the number of Period-value mappings in this map.
 java.util.Set valueSet()
          Returns a read-only Set containing the values defined somewhen in this map.
 java.util.Set valueSet(Instant instant)
          Returns a read-only Set containing the values defined in this map at the specified instant.
 
Methods inherited from class jtemporal.AbstractTemporalMultiMap
equals, extent, putAll
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

valueMap

private final java.util.Map valueMap

timeMap

private final java.util.SortedMap timeMap

valueType

private final java.lang.Class valueType

nodeDeadListener

private final NodeParent nodeDeadListener
This inner class has been created because it is impossible to implement a non public insterface without declaring the implementing methods as public :-( (http://developer.java.sun.com/developer/bugParade/bugs/4456057.html)

Constructor Detail

TreeTemporalMultiMap

public TreeTemporalMultiMap()
Default constructor. Values of any type will be accepted.


TreeTemporalMultiMap

public TreeTemporalMultiMap(java.lang.Class valueType)
Method Detail

firstInstant

public Instant firstInstant(java.lang.Object value)
Description copied from interface: TemporalMultiMap
Returns the first (lowest) instant currently defined for the given value.

Specified by:
firstInstant in interface TemporalMultiMap
Specified by:
firstInstant in class AbstractTemporalMultiMap

lastInstant

public Instant lastInstant(java.lang.Object value)
Description copied from interface: TemporalMultiMap
Returns the last (highest) instant currently defined for the given value.

Specified by:
lastInstant in interface TemporalMultiMap
Specified by:
lastInstant in class AbstractTemporalMultiMap

getPeriod

public Period getPeriod(Instant instant,
                        java.lang.Object value)
Description copied from interface: TemporalMultiMap
Returns the period of the mapping valid at the specified instant for the value.

Specified by:
getPeriod in interface TemporalMultiMap
Specified by:
getPeriod in class AbstractTemporalMultiMap

contains

public boolean contains(Instant instant,
                        java.lang.Object value)
Description copied from interface: TemporalMultiMap
Returns true if there is a mapping for this value at the given instant. Same as containsValue(Instant instant, Object value)

Specified by:
contains in interface TemporalMultiMap
Specified by:
contains in class AbstractTemporalMultiMap

containsValue

public boolean containsValue(java.lang.Object value)
Description copied from interface: TemporalMultiMap
Returns true if if ther is a mapping for the specified value.

Specified by:
containsValue in interface TemporalMultiMap
Specified by:
containsValue in class AbstractTemporalMultiMap

firstPeriod

public Period firstPeriod(java.lang.Object value)
Description copied from interface: TemporalMultiMap
Returns the first (lowest) period currently defined for the given value.

Specified by:
firstPeriod in interface TemporalMultiMap
Specified by:
firstPeriod in class AbstractTemporalMultiMap

lastPeriod

public Period lastPeriod(java.lang.Object value)
Description copied from interface: TemporalMultiMap
Returns the last (highest) period currently defined for the given value.

Specified by:
lastPeriod in interface TemporalMultiMap
Specified by:
lastPeriod in class AbstractTemporalMultiMap

isEmpty

public boolean isEmpty()
Description copied from interface: TemporalMultiMap
Returns true if this map contains no Period-value mappings.

Specified by:
isEmpty in interface TemporalMultiMap
Specified by:
isEmpty in class AbstractTemporalMultiMap

size

public int size(java.lang.Object value)
Description copied from interface: TemporalMultiMap
Returns the number of Period-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
size in interface TemporalMultiMap
Specified by:
size in class AbstractTemporalMultiMap

periodSet

public java.util.Set periodSet(java.lang.Object value)
Description copied from interface: TemporalMultiMap
Returns a set view of the periods contained in this map for the give value. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll retainAll, and clear operations. It does not support the add or addAll operations.

Specified by:
periodSet in interface TemporalMultiMap
Specified by:
periodSet in class AbstractTemporalMultiMap

valueSet

public java.util.Set valueSet()
Description copied from interface: TemporalMultiMap
Returns a read-only Set containing the values defined somewhen in this map.

Specified by:
valueSet in interface TemporalMultiMap
Specified by:
valueSet in class AbstractTemporalMultiMap

valueSet

public java.util.Set valueSet(Instant instant)
Description copied from interface: TemporalMultiMap
Returns a read-only Set containing the values defined in this map at the specified instant. Returns an empty set if the map contains no mapping at this Instant.

Specified by:
valueSet in interface TemporalMultiMap
Specified by:
valueSet in class AbstractTemporalMultiMap

clear

public void clear()
Description copied from interface: TemporalMultiMap
Removes all the mappings from this map (optional operation).

Specified by:
clear in interface TemporalMultiMap
Specified by:
clear in class AbstractTemporalMultiMap

removeValue

public void removeValue(java.lang.Object value)
Description copied from interface: TemporalMultiMap
Removes all the mapping(s) for this value from this map if present (optional operation).

Specified by:
removeValue in interface TemporalMultiMap
Specified by:
removeValue in class AbstractTemporalMultiMap

remove

public boolean remove(Period p,
                      java.lang.Object value)
Description copied from interface: TemporalMultiMap
Removes the mapping(s) for this period and value from this map if present (optional operation).

Specified by:
remove in interface TemporalMultiMap
Specified by:
remove in class AbstractTemporalMultiMap

removePeriod

public boolean removePeriod(Period p)
Description copied from interface: TemporalMultiMap
Removes all the mapping(s) for this period from this map if present (optional operation).

Specified by:
removePeriod in interface TemporalMultiMap
Specified by:
removePeriod in class AbstractTemporalMultiMap

put

public boolean put(Period p,
                   java.lang.Object value)
Description copied from interface: TemporalMultiMap
Associates the specified value to the specified Period in this map. If the map previously contained a mapping to the same value, during a period overlapping this period, the periods are merged.

Specified by:
put in interface TemporalMultiMap
Specified by:
put in class AbstractTemporalMultiMap

getTemporalUnaryMapOrNull

private TemporalUnaryMap getTemporalUnaryMapOrNull(java.lang.Object value)

getTemporalUnaryMap

private TemporalUnaryMap getTemporalUnaryMap(java.lang.Object value)