JTemporal Home
Tutorial

net.sf.jtemporal.spi
Class CompactPeriodStorage

java.lang.Object
  extended by net.sf.jtemporal.spi.CompactPeriodStorage
All Implemented Interfaces:
PeriodStorage

public class CompactPeriodStorage
extends java.lang.Object
implements PeriodStorage

A sorted storage for Periods, intended to allocate a small amount of memory; fast for small collections, but does not scale well for insertions in large collections.
The internal storage is based on a sorted ArrayList.
Given that for each put(Period) or remove(Period) in average 50% of the records are moved, write performance of this storage does not scale well.
the arraylist is instantiated only the first time put(Period) is called.

Version:
$Id: CompactPeriodStorage.java,v 1.5 2006/06/18 10:21:36 tabeck Exp $

Constructor Summary
CompactPeriodStorage()
           
 
Method Summary
 void clear()
          Removes all the stored periods.
 Period firstPeriod()
          Returns the first (lowest) period currently in this storage, or null if any is found.
 Period firstPeriod(Period p)
           
 Period getPeriod(Instant instant)
          Returns the period valid at the specified instant.
 Period getPeriodEndingAt(Instant instant)
          Returns the period finishing exactly at the given instant, if any is found.
 Period getPeriodStartingAt(Instant instant)
          Returns the period starting exactly at the given instant, if any is found.
 boolean isEmpty()
          Returns true if this storage does not contain objects.
 boolean isEmpty(Period p)
          Returns true if this storage does not contain objects intersecting the given period.
 Period lastPeriod()
          Returns the last (highest) period currently in this storage or null if empty.
 Period lastPeriod(Period p)
           
 CloseableIterator periodIterator()
          Iterates over all the periods of the entries.
 CloseableIterator periodIterator(Period period)
          Iterates over all the periods of the storage that intersects the given period.
 void put(Period p)
          Stores a period.
 void remove(Period p)
          Removes a period previously stored.
 int size()
          Returns the number of Periods in this storage.
 java.lang.String toString()
           
 void trimToSize()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CompactPeriodStorage

public CompactPeriodStorage()
Method Detail

lastPeriod

public Period lastPeriod()
Description copied from interface: PeriodStorage
Returns the last (highest) period currently in this storage or null if empty.

Specified by:
lastPeriod in interface PeriodStorage
Returns:
the last (highest) period currently in this storage or null.

lastPeriod

public Period lastPeriod(Period p)

firstPeriod

public Period firstPeriod()
Description copied from interface: PeriodStorage
Returns the first (lowest) period currently in this storage, or null if any is found.

Specified by:
firstPeriod in interface PeriodStorage
Returns:
the first (lowest) period currently in this storage, or null.

firstPeriod

public Period firstPeriod(Period p)

isEmpty

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

Specified by:
isEmpty in interface PeriodStorage
Returns:
true if this storage does not contain objects..

isEmpty

public boolean isEmpty(Period p)
Description copied from interface: PeriodStorage
Returns true if this storage does not contain objects intersecting the given period.

Specified by:
isEmpty in interface PeriodStorage
Parameters:
p - the intersecting period
Returns:
true if this storage does not contain objects intersecting the given period.

getPeriod

public Period getPeriod(Instant instant)
Description copied from interface: PeriodStorage
Returns the period valid at the specified instant.

Specified by:
getPeriod in interface PeriodStorage
Parameters:
instant - the instant whose enclosing period must be returned
Returns:
the period valid at the specified instant. Returns null if this storage does not contain a period at the specified instant.

put

public void put(Period p)
Description copied from interface: PeriodStorage
Stores a period.
No particular check or rich semantics is expected, this method just stores.

Specified by:
put in interface PeriodStorage
Parameters:
p - period to be added to the storage. Cannot be null.

remove

public void remove(Period p)
Description copied from interface: PeriodStorage
Removes a period previously stored.

The period must match the parameter previously used to call the PeriodStorage.put(Period) method.

Specified by:
remove in interface PeriodStorage
Parameters:
p - the period to be removed

getPeriodEndingAt

public Period getPeriodEndingAt(Instant instant)
Description copied from interface: PeriodStorage
Returns the period finishing exactly at the given instant, if any is found.

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

getPeriodStartingAt

public Period getPeriodStartingAt(Instant instant)
Description copied from interface: PeriodStorage
Returns the period starting exactly at the given instant, if any is found.

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

clear

public void clear()
Description copied from interface: PeriodStorage
Removes all the stored periods.

Specified by:
clear in interface PeriodStorage

size

public int size()
Description copied from interface: PeriodStorage
Returns the number of Periods in this storage. If the storage contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
size in interface PeriodStorage
Returns:
the number of periods in this storage.

periodIterator

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

Specified by:
periodIterator in interface PeriodStorage
Parameters:
period - the intersecting period.
Returns:
instances of TimedObject
See Also:
Period

periodIterator

public CloseableIterator periodIterator()
Description copied from interface: PeriodStorage
Iterates over all the periods of the entries.

The instances are sorted by Comparable.compareTo(Object)

Specified by:
periodIterator in interface PeriodStorage
Returns:
instances of Period
See Also:
Period

trimToSize

public void trimToSize()
See Also:
ArrayList.trimToSize()

toString

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

JTemporal Home
Tutorial