JTemporal Home
Tutorial

net.sf.jtemporal.spi
Class CompactTemporalSetStorage

java.lang.Object
  extended by net.sf.jtemporal.spi.CompactTemporalSetStorage
All Implemented Interfaces:
TemporalSetStorage

public class CompactTemporalSetStorage
extends java.lang.Object
implements TemporalSetStorage

Uses a HashMap containing CompactPeriodStorages
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.

Version:
$Id: CompactTemporalSetStorage.java,v 1.6 2006/12/16 21:15:04 tabeck Exp $

Constructor Summary
CompactTemporalSetStorage()
           
 
Method Summary
 void beginAtomicOperation()
          Tells the storage that the JTemporal client is calling a method that can result in multiples updates in the storage.
 void clear()
          Removes all the stored mappings.
 boolean containsValue(Instant i, java.lang.Object value)
          Returns true if this storage contains a mapping for the specified value at the given instant.
 boolean containsValue(java.lang.Object value)
          Returns true if this storage contains one or more mappings for the specified value.
 void endAtomicOperation()
          Tells the storage that an atomic operation has finished.
 CloseableIterator entryIterator()
          Iterates over all the entries of the storage.
 CloseableIterator entryIterator(Instant instant)
          Returns an iterator looping over the entries contained et the given instant.
 CloseableIterator entryIterator(Period period)
          Iterates over all the entries of the storage that intersects the period P.
 CloseableIterator entryIterator(Period period, java.lang.Object value)
          Iterates over all the entries of the storage for the given value that intersects the given period.
 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 given value.
 Period getPeriodEndingAt(Instant instant, java.lang.Object value)
          Returns the period finishing exactly at the given instant, for the given value, if any is found.
 Period getPeriodStartingAt(Instant instant, java.lang.Object value)
          Returns the period starting exactly at the given instant, for the given value, if any is found.
 boolean isEmpty()
          Returns true if this storage does not contain entries.
 boolean isEmpty(Instant instant)
          Returns true if this storage does not contain entries at the given instant.
 Period lastPeriod(java.lang.Object value)
          Returns the last (highest) period currently defined for the given value.
 CloseableIterator periodIterator(java.lang.Object value)
          Iterates over all the periods of the entries having the given value.
 void put(Period p, java.lang.Object value)
          Stores a mapping (entry, tuple, row) composed by period and value.
 void remove(Period p, java.lang.Object value)
          Removes a mapping (entry, tuple, row) composed by period and value previously stored.
 boolean removeValue(java.lang.Object value)
          Removes all the entries having the given value.
 int size()
          Returns the number of Period-value mappings in this map.
 int sizeAt(Instant instant)
          Returns the number of entries, at the given instant.
 int sizeFor(java.lang.Object value)
          Returns the number of entries in this map whose value equals the given one.
 int sizeValues()
          Returns the number of distinct values in this storage.
 java.lang.String toString()
           
 CloseableIterator valueIterator()
          Iterates over all the distinct values of the entries in the storage.
 CloseableIterator valueIterator(Instant instant)
          Iterates over the set of values valid at the given instant.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CompactTemporalSetStorage

public CompactTemporalSetStorage()
Method Detail

lastPeriod

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

Specified by:
lastPeriod in interface TemporalSetStorage
Parameters:
value - the values whose last period must be returned.
Returns:
the last (highest) period currently defined for the given value.

firstPeriod

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

Specified by:
firstPeriod in interface TemporalSetStorage
Parameters:
value - the values whose first period must be returned.
Returns:
the first (lowest) period currently defined for the given value.

isEmpty

public boolean isEmpty()
Description copied from interface: TemporalSetStorage
Returns true if this storage does not contain entries.

Specified by:
isEmpty in interface TemporalSetStorage
Returns:
true if this storage does not contain entries.

isEmpty

public boolean isEmpty(Instant instant)
Description copied from interface: TemporalSetStorage
Returns true if this storage does not contain entries at the given instant.

Specified by:
isEmpty in interface TemporalSetStorage
Parameters:
instant - the instant to be checked
Returns:
true if this storage does not contain entries at the given instant.

containsValue

public boolean containsValue(java.lang.Object value)
Description copied from interface: TemporalSetStorage
Returns true if this storage contains one or more mappings for the specified value.

Specified by:
containsValue in interface TemporalSetStorage
Parameters:
value - value whose presence in this map is to be tested.
Returns:
true if this map maps one or more keys to the specified value.

containsValue

public boolean containsValue(Instant i,
                             java.lang.Object value)
Description copied from interface: TemporalSetStorage
Returns true if this storage contains a mapping for the specified value at the given instant.

Specified by:
containsValue in interface TemporalSetStorage
Parameters:
i - the instant to be checked
value - value whose presence in this map is to be checked.
Returns:
true if this map maps to the given value at the given instant.

getPeriod

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

Specified by:
getPeriod in interface TemporalSetStorage
Parameters:
instant - the instant where the value is valid
value - valid for the returned period. The returned period contains the passed instant.
Returns:
the period of the mapping valid at the specified instant for the given value. Returns null if this map does not contain a mapping for the given value at the specified instant.

getPeriodEndingAt

public Period getPeriodEndingAt(Instant instant,
                                java.lang.Object value)
Description copied from interface: TemporalSetStorage
Returns the period finishing exactly at the given instant, for the given value, if any is found.

Specified by:
getPeriodEndingAt in interface TemporalSetStorage
Parameters:
instant - the instant the equals the entry end
value - of the entry finishing at the given instant
Returns:
the Period ending exactly at the given instant, or null.

getPeriodStartingAt

public Period getPeriodStartingAt(Instant instant,
                                  java.lang.Object value)
Description copied from interface: TemporalSetStorage
Returns the period starting exactly at the given instant, for the given value, if any is found.

Specified by:
getPeriodStartingAt in interface TemporalSetStorage
Parameters:
instant - the instant the equals the entry end
value - of the entry starting at the given instant
Returns:
the Period starting exactly at the given instant, or null.

beginAtomicOperation

public void beginAtomicOperation()
Description copied from interface: TemporalSetStorage
Tells the storage that the JTemporal client is calling a method that can result in multiples updates in the storage.
This is not exactly a transaction.
If the storage supports transactions, this method suggests to perform all the following operations inside the same transaction.
For example, this method is called by TemporalSetImpl at the beginning of the put(Period, Object) method, then TemporalSetImpl calls some times the put and remove methods, then finally it calls TemporalSetStorage.endAtomicOperation().
If your storage supports nested transactions, this is the inner one. Non persistent implemetations just return with no action.
Must not throw any exception (including unchecked exceptions).

Specified by:
beginAtomicOperation in interface TemporalSetStorage
See Also:
TemporalSetStorage.endAtomicOperation()

endAtomicOperation

public void endAtomicOperation()
Description copied from interface: TemporalSetStorage
Tells the storage that an atomic operation has finished. If the storage supports transactions, it should commit if a transaction has been started by TemporalSetStorage.beginAtomicOperation().
Non persistent implemetations just return with no action.
Must not throw any exception (including unchecked exceptions).

Specified by:
endAtomicOperation in interface TemporalSetStorage
See Also:
TemporalSetStorage.beginAtomicOperation()

clear

public void clear()
Description copied from interface: TemporalSetStorage
Removes all the stored mappings.

Specified by:
clear in interface TemporalSetStorage

size

public int size()
Description copied from interface: TemporalSetStorage
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 TemporalSetStorage
Returns:
the number of Instant-value mappings in this map.

sizeFor

public int sizeFor(java.lang.Object value)
Description copied from interface: TemporalSetStorage
Returns the number of entries in this map whose value equals the given one. If the there are more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
sizeFor in interface TemporalSetStorage
Parameters:
value - the value of the entries to be counted
Returns:
the number of entries in this map whose value equals the given one.

sizeValues

public int sizeValues()
Description copied from interface: TemporalSetStorage
Returns the number of distinct values in this storage. If there are more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
sizeValues in interface TemporalSetStorage
Returns:
the number of distinct values in this map.

sizeAt

public int sizeAt(Instant instant)
Description copied from interface: TemporalSetStorage
Returns the number of entries, at the given instant. If there are more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
sizeAt in interface TemporalSetStorage
Parameters:
instant - the instant to be checked
Returns:
the number of entries intersecting the given instant.

put

public void put(Period p,
                java.lang.Object value)
Description copied from interface: TemporalSetStorage
Stores a mapping (entry, tuple, row) composed by period and value.
No particular check or rich semantics is expected, this method just stores.

Specified by:
put in interface TemporalSetStorage
Parameters:
p - period with which the specified value is associated. Cannot be null.
value - value to be associated with the specified key. Cannot be null.

remove

public void remove(Period p,
                   java.lang.Object value)
Description copied from interface: TemporalSetStorage
Removes a mapping (entry, tuple, row) composed by period and value previously stored.

The period and the value must match the parameter previously used to call the put method.

Specified by:
remove in interface TemporalSetStorage
Parameters:
p - the period of the entry to be removed
value - the value of the entry to be removed

removeValue

public boolean removeValue(java.lang.Object value)
Description copied from interface: TemporalSetStorage
Removes all the entries having the given value.

Specified by:
removeValue in interface TemporalSetStorage
Parameters:
value - the value of the entry to be removed
Returns:
true if the storage contained at least one entry for the given value

entryIterator

public CloseableIterator entryIterator()
Description copied from interface: TemporalSetStorage
Iterates over all the entries of the storage.
The instances are sorted by Period.equals(Object)

Specified by:
entryIterator in interface TemporalSetStorage
Returns:
instances of TimedObject
See Also:
TimedObject

entryIterator

public CloseableIterator entryIterator(Instant instant)
Description copied from interface: TemporalSetStorage
Returns an iterator looping over the entries contained et the given instant.

Specified by:
entryIterator in interface TemporalSetStorage
Parameters:
instant - instant whose entries are to be returned
Returns:
an iterator of instances of TimedObject
See Also:
TimedObject

entryIterator

public CloseableIterator entryIterator(Period period)
Description copied from interface: TemporalSetStorage
Iterates over all the entries of the storage that intersects the period P.
Note that the CloseableIterator#remove() method, removes the whole entry, even if the entry has a period lager then the period p.
The instances are sorted by Period.equals(Object)

Specified by:
entryIterator in interface TemporalSetStorage
Parameters:
period - the intersecting period.
Returns:
instances of TimedObject
See Also:
TimedObject

entryIterator

public CloseableIterator entryIterator(Period period,
                                       java.lang.Object value)
Description copied from interface: TemporalSetStorage
Iterates over all the entries of the storage for the given value that intersects the given period.
Note that the CloseableIterator#remove() method, removes the whole entry, even if the entry has a period larger then the given period.
The instances are sorted by Period.equals(Object)

Specified by:
entryIterator in interface TemporalSetStorage
Parameters:
period - the intersecting period.
value - the value to be iterated
Returns:
instances of TimedObject
See Also:
TimedObject

periodIterator

public CloseableIterator periodIterator(java.lang.Object value)
Description copied from interface: TemporalSetStorage
Iterates over all the periods of the entries having the given value.

The instances are sorted by Comparable.compareTo(Object)

Specified by:
periodIterator in interface TemporalSetStorage
Parameters:
value - the selected value
Returns:
instances of Period
See Also:
Period

valueIterator

public CloseableIterator valueIterator()
Description copied from interface: TemporalSetStorage
Iterates over all the distinct values of the entries in the storage.

Specified by:
valueIterator in interface TemporalSetStorage
Returns:
instances of Object

valueIterator

public CloseableIterator valueIterator(Instant instant)
Description copied from interface: TemporalSetStorage
Iterates over the set of values valid at the given instant.
Returns a read-only iterator.

Specified by:
valueIterator in interface TemporalSetStorage
Parameters:
instant - the instant where all the returned value are valid
Returns:
instances of Object, the iterator is read-only

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

JTemporal Home
Tutorial