com.timeindexing.index
Class AbstractIndex

java.lang.Object
  extended by com.timeindexing.index.AbstractIndex
All Implemented Interfaces:
IndexEventGenerator, ExtendedIndex, ExtendedIndexHeader, Index, IndexHeader
Direct Known Subclasses:
FileIndex, IncoreIndex, SQLIndex

public abstract class AbstractIndex
extends java.lang.Object
implements ExtendedIndex, ExtendedIndexHeader, IndexEventGenerator

An abstract implementation of an Index object. It represents the index header, the index stream and the data stream.


Constructor Summary
protected AbstractIndex()
           
 
Method Summary
 void addAccessEventListener(IndexAccessEventListener l)
          Add a IndexAccessEventListener.
 void addAddEventListener(IndexAddEventListener l)
          Add a IndexAddEventListener.
 boolean addDataType(ID typeID, java.lang.String typeName)
          Add a new data type
abstract  IndexItem addItem(DataItem item)
          Add a Data Item to the Index.
abstract  IndexItem addItem(DataItem item, Timestamp dataTime)
          Add a Data Item to the Index with a speicifed Data Timestamp
abstract  IndexItem addItem(DataItem item, Timestamp dataTime, long annotation)
          Add a Data Item to the Index with a speicifed Data Timestamp and some annotation data
protected  IndexItem addItem(IndexItem item)
          Add an Index Item to the Index.
 void addPrimaryEventListener(IndexPrimaryEventListener l)
          Add a IndexPrimaryEventListener.
abstract  IndexItem addReference(IndexItem item, Index other)
          Add a Reference to an IndexItem in a Index.
abstract  IndexItem addReference(IndexItem item, Index other, Timestamp dataTime)
          Add a Reference to an IndexItem in a Index.
abstract  IndexItem addReference(IndexItem item, Index other, Timestamp dataTime, long annotation)
          Add a Reference to an IndexItem in a Index.
 DoubleLinkedList apply(Function fn)
          Apply a function to all of the IndexItems, resulting in a List of results.
protected  TimestampMapping binarySearch(Timestamp t, long start, long end, IndexTimestampSelector selector, Lifetime lifetime, int depth)
          Do a binary search of the list.
 boolean commit()
          Commit all changes to the index.
 boolean contains(Timestamp t)
          Does a timestamp fall within the bounds of the Index.
 boolean contains(Timestamp t, IndexTimestampSelector selector)
          Does a timestamp fall within the bounds of the Index.
 IndexEventMulticaster eventMulticaster()
          Get the event listener.
 IndexView filter(Function fn)
          Filter some IndexItems out into a new IncoreIndex.
 int getAnnotationStyle()
          Get the annotation style.
 IndexCache getCache()
          Get the current Cache.
 CachePolicy getCachePolicy()
          Get the current CachePolicy.
 java.lang.String getDataPathName()
          Get the path of the data if the index data style is external or shadow.
 long getDataSize()
          Get the size of the data items, if there is fixed size data.
 java.lang.String getDataType(ID typeID)
          Get the type name of the things in the data stream.
 Description getDescription()
          Get the description for an index.
 Timestamp getEndTime()
          Get the end time of the index.
 Timestamp getFirstDataTime()
          Get the data time for the first IndexItem in the Index.
 Timestamp getFirstTime()
          Get the time the first IndexItem was put into the Index.
 ID getID()
          Get an ID of an index.
 DataType getIndexDataType()
          Get the index data type.
 java.lang.String getIndexPathName()
          Get the indexPath of the index.
 IndexType getIndexType()
          Get the index type.
abstract  IndexItem getItem(long n)
          Get an Index Item from the Index.
 IndexItem getItem(Position p)
          Get an Index Item from the Index.
 IndexItem getItem(Timestamp t)
          Get an Index Item from the Index.
 IndexItem getItem(Timestamp t, IndexTimestampSelector sel, Lifetime lifetime)
          Get an Index Item from the Index.
 int getItemSize()
          Get the size of the items.
 Timestamp getLastAccessTime()
          Get the last time an IndexItem was accessed from the index.
 Timestamp getLastDataTime()
          Get the data time for the last IndexItem in the Index.
 Timestamp getLastTime()
          Get the time the last IndexItem was put into the Index.
 long getLength()
          Get the no of items in the index.
 boolean getLoadDataAutomatically()
          Does the index load data automatically when doing a get item.
 java.lang.String getName()
          Get the name of the index.
 Timestamp getStartTime()
          Get the start time of the index.
 java.net.URI getURI()
          Get the Index specification in the form of a URI.
 boolean hasAnnotations()
          Does this index have annotations.
 boolean hasDataType(java.lang.String typeName)
          Does this index have a typed name.
 boolean isActivated()
          Is the Index activated.
 boolean isChanged()
          Has the index changed in any way.
 boolean isClosed()
          Is the Index closed.
 boolean isFixedSizeData()
          Does the index have fixed size data.
 boolean isInTimeOrder()
          Is the index still in time order.
 boolean isReadOnly()
          Is the Index only available for read-only operations.
 boolean isTerminated()
          Is the Index terminated.
 java.util.Iterator iterator()
          Get an iterator over the IndexItems in the Index.
 TimestampMapping locate(Position p)
          Try and determine the Timestamp associated with the speicifed Position.
 TimestampMapping locate(Position pos, IndexTimestampSelector selector, Lifetime lifetime)
          Try and determine the Timestamp associated with the speicifed Position.
 TimestampMapping locate(Timestamp t)
          Try and determine the position associated with the speicifed Timestamp.
 TimestampMapping locate(Timestamp t, IndexTimestampSelector selector, Lifetime lifetime)
          Try and determine the position associated with the speicifed Timestamp.
 IndexView map(Function fn)
          Map a function to all of the IndexItems, resulting in a new IncoreIndex.
 void removeAccessEventListener(IndexAccessEventListener l)
          Remove a IndexAccessEventListener.
 void removeAddEventListener(IndexAddEventListener l)
          Remove a IndexAddEventListener.
 void removePrimaryEventListener(IndexPrimaryEventListener l)
          Remove a IndexPrimaryEventListener.
 IndexView select(AbsoluteTimestamp t, IntervalSpecifier intervalSpecifier)
          Select an Interval given a Timestamp and an IntervalSpecifier.
 IndexView select(AbsoluteTimestamp t, IntervalSpecifier intervalSpecifier, IndexTimestampSelector selector, Overlap overlap, Lifetime lifetime)
          Select an Interval given a Timestamp and an IntervalSpecifier.
 IndexView select(Interval interval)
          Select an Interval given an Interval object.
 IndexView select(Interval interval, IndexTimestampSelector selector, Overlap overlap, Lifetime lifetime)
          Select an Interval given an Interval object.
 boolean setAutoCommit(boolean commit)
          Set auto commit to be true or false.
 CachePolicy setCachePolicy(CachePolicy policy)
          Set a CachePolicy in order to manage the cache.
protected  Index setLastAccessTime()
          Set the last time an IndexItem was accessed from the index.
 boolean setLoadDataAutomatically(boolean load)
          Load data automatically when doing a get item.
 Index terminate()
          Make the Index finalized.
 Index updateDescription(Description description)
          Set the description.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.timeindexing.index.ExtendedIndex
getFirstOffset, getLastFlushPosition, getLastFlushTime, getLastOffset
 
Methods inherited from interface com.timeindexing.index.Index
activate, asView, close, isWriteLocked
 
Methods inherited from interface com.timeindexing.index.ExtendedIndexHeader
addIndexURI, getIndexURI, hasIndexURI
 

Constructor Detail

AbstractIndex

protected AbstractIndex()
Method Detail

getName

public java.lang.String getName()
Get the name of the index.

Specified by:
getName in interface IndexHeader

getID

public ID getID()
Get an ID of an index.

Specified by:
getID in interface IndexHeader

getURI

public java.net.URI getURI()
Get the Index specification in the form of a URI.

Specified by:
getURI in interface IndexHeader

getStartTime

public Timestamp getStartTime()
Get the start time of the index. This is when the index was created not necessarliy when the first item was added to the index.

Specified by:
getStartTime in interface IndexHeader

getEndTime

public Timestamp getEndTime()
Get the end time of the index. This is the time the last item was closed, not necessarliy when the last item was added to the index.

Specified by:
getEndTime in interface IndexHeader

getFirstTime

public Timestamp getFirstTime()
Get the time the first IndexItem was put into the Index.

Specified by:
getFirstTime in interface IndexHeader
Returns:
ZeroTimestamp if there is no first item, usually when there are no items in the index

getLastTime

public Timestamp getLastTime()
Get the time the last IndexItem was put into the Index.

Specified by:
getLastTime in interface IndexHeader
Returns:
ZeroTimestamp if there is no last item, usually when there are no items in the index

getFirstDataTime

public Timestamp getFirstDataTime()
Get the data time for the first IndexItem in the Index.

Specified by:
getFirstDataTime in interface IndexHeader
Returns:
ZeroTimestamp if there is no first item, usually when there are no items in the index

getLastDataTime

public Timestamp getLastDataTime()
Get the data time for the last IndexItem in the Index.

Specified by:
getLastDataTime in interface IndexHeader
Returns:
ZeroTimestamp if there is no last item, usually when there are no items in the index

getItemSize

public int getItemSize()
Get the size of the items.

Specified by:
getItemSize in interface ExtendedIndexHeader
Specified by:
getItemSize in interface Index

isFixedSizeData

public boolean isFixedSizeData()
Does the index have fixed size data.

Specified by:
isFixedSizeData in interface IndexHeader

getDataSize

public long getDataSize()
Get the size of the data items, if there is fixed size data.

Specified by:
getDataSize in interface ExtendedIndexHeader
Specified by:
getDataSize in interface IndexHeader

getDataType

public java.lang.String getDataType(ID typeID)
Get the type name of the things in the data stream.

Specified by:
getDataType in interface ExtendedIndexHeader
Specified by:
getDataType in interface Index

hasDataType

public boolean hasDataType(java.lang.String typeName)
Does this index have a typed name.

Specified by:
hasDataType in interface ExtendedIndexHeader
Specified by:
hasDataType in interface Index

addDataType

public boolean addDataType(ID typeID,
                           java.lang.String typeName)
Add a new data type

Specified by:
addDataType in interface ExtendedIndexHeader
Specified by:
addDataType in interface Index
Returns:
true, if a new type was added; false, if the index had this ID/typeName pair already

getIndexType

public IndexType getIndexType()
Get the index type. Either inline or external.

Specified by:
getIndexType in interface ExtendedIndex
Specified by:
getIndexType in interface IndexHeader

getIndexDataType

public DataType getIndexDataType()
Get the index data type. Some indexes have the same type throughout, other have mixed type data.

Specified by:
getIndexDataType in interface IndexHeader

isInTimeOrder

public boolean isInTimeOrder()
Is the index still in time order.

Specified by:
isInTimeOrder in interface IndexHeader

hasAnnotations

public boolean hasAnnotations()
Does this index have annotations.

Specified by:
hasAnnotations in interface ExtendedIndexHeader
Specified by:
hasAnnotations in interface Index

getAnnotationStyle

public int getAnnotationStyle()
Get the annotation style. Either inline or external.

Specified by:
getAnnotationStyle in interface ExtendedIndexHeader
Specified by:
getAnnotationStyle in interface Index

getLength

public long getLength()
Get the no of items in the index.

Specified by:
getLength in interface IndexHeader

addItem

public abstract IndexItem addItem(DataItem item)
                           throws IndexTerminatedException,
                                  IndexClosedException,
                                  IndexActivationException,
                                  AddItemException
Add a Data Item to the Index.

Specified by:
addItem in interface Index
Throws:
IndexTerminatedException
IndexClosedException
IndexActivationException
AddItemException

addItem

public abstract IndexItem addItem(DataItem item,
                                  Timestamp dataTime)
                           throws IndexTerminatedException,
                                  IndexClosedException,
                                  IndexActivationException,
                                  AddItemException
Add a Data Item to the Index with a speicifed Data Timestamp

Specified by:
addItem in interface Index
Throws:
IndexTerminatedException
IndexClosedException
IndexActivationException
AddItemException

addItem

public abstract IndexItem addItem(DataItem item,
                                  Timestamp dataTime,
                                  long annotation)
                           throws IndexTerminatedException,
                                  IndexClosedException,
                                  IndexActivationException,
                                  AddItemException
Add a Data Item to the Index with a speicifed Data Timestamp and some annotation data

Specified by:
addItem in interface Index
Throws:
IndexTerminatedException
IndexClosedException
IndexActivationException
AddItemException

addItem

protected IndexItem addItem(IndexItem item)
                     throws IndexTerminatedException,
                            IndexClosedException,
                            IndexActivationException,
                            AddItemException
Add an Index Item to the Index.

Parameters:
item - the IndexItem to add
Returns:
the no of items in the index.
Throws:
IndexTerminatedException - if the index has been terminated and an attempt is made to add an Item
IndexActivationException - if the index has NOT been activated and an attempt is made to add an Item
IndexClosedException
AddItemException

addReference

public abstract IndexItem addReference(IndexItem item,
                                       Index other)
                                throws IndexTerminatedException,
                                       IndexClosedException,
                                       IndexActivationException,
                                       AddItemException
Add a Reference to an IndexItem in a Index. The Data Timestamp of the IndexItem is passed into this Index.

Specified by:
addReference in interface Index
Throws:
IndexTerminatedException
IndexClosedException
IndexActivationException
AddItemException

addReference

public abstract IndexItem addReference(IndexItem item,
                                       Index other,
                                       Timestamp dataTime)
                                throws IndexTerminatedException,
                                       IndexClosedException,
                                       IndexActivationException,
                                       AddItemException
Add a Reference to an IndexItem in a Index. The Data Timestamp of the IndexItem is the one specified.

Specified by:
addReference in interface Index
Throws:
IndexTerminatedException
IndexClosedException
IndexActivationException
AddItemException

addReference

public abstract IndexItem addReference(IndexItem item,
                                       Index other,
                                       Timestamp dataTime,
                                       long annotation)
                                throws IndexTerminatedException,
                                       IndexClosedException,
                                       IndexActivationException,
                                       AddItemException
Add a Reference to an IndexItem in a Index. The Data Timestamp of the IndexItem is the one specified, as is the annotation value.

Specified by:
addReference in interface Index
Throws:
IndexTerminatedException
IndexClosedException
IndexActivationException
AddItemException

getItem

public abstract IndexItem getItem(long n)
                           throws GetItemException,
                                  IndexClosedException
Get an Index Item from the Index.

Specified by:
getItem in interface Index
Throws:
GetItemException
IndexClosedException

getItem

public IndexItem getItem(Position p)
                  throws GetItemException,
                         IndexClosedException
Get an Index Item from the Index.

Specified by:
getItem in interface Index
Throws:
GetItemException
IndexClosedException

getItem

public IndexItem getItem(Timestamp t)
                  throws GetItemException,
                         IndexClosedException
Get an Index Item from the Index. Uses IndexTimestampSelector.DATA and Lifetime.CONTINUOUS as defaults.

Specified by:
getItem in interface Index
Throws:
GetItemException
IndexClosedException

getItem

public IndexItem getItem(Timestamp t,
                         IndexTimestampSelector sel,
                         Lifetime lifetime)
                  throws GetItemException,
                         IndexClosedException
Get an Index Item from the Index.

Specified by:
getItem in interface Index
Throws:
GetItemException
IndexClosedException

getLastAccessTime

public Timestamp getLastAccessTime()
Get the last time an IndexItem was accessed from the index.

Specified by:
getLastAccessTime in interface Index

setLastAccessTime

protected Index setLastAccessTime()
Set the last time an IndexItem was accessed from the index.


getIndexPathName

public java.lang.String getIndexPathName()
Get the indexPath of the index.

Specified by:
getIndexPathName in interface IndexHeader
Returns:
null if there is no index path

getDataPathName

public java.lang.String getDataPathName()
Get the path of the data if the index data style is external or shadow.

Specified by:
getDataPathName in interface IndexHeader
Returns:
null if there is no data path

getDescription

public Description getDescription()
Get the description for an index.

Specified by:
getDescription in interface IndexHeader
Returns:
null if there is no description

updateDescription

public Index updateDescription(Description description)
Set the description. This is one of the few attributes of an index that can be set directly.

Specified by:
updateDescription in interface Index

contains

public boolean contains(Timestamp t)
Does a timestamp fall within the bounds of the Index. Uses IndexTimestampSelector.DATA as a default. The bounds are the first time data is put in and the last time data is put in the Index.

Specified by:
contains in interface Index

contains

public boolean contains(Timestamp t,
                        IndexTimestampSelector selector)
Does a timestamp fall within the bounds of the Index. The bounds are the first time data is put in and the last time data is put in the Index.

Specified by:
contains in interface Index

locate

public TimestampMapping locate(Timestamp t)
Try and determine the position associated with the speicifed Timestamp. Uses IndexTimestampSelector.DATA and Lifetime.CONTINUOUS as defaults. Returns a TimestampMapping which contains the original time and the found position.

Specified by:
locate in interface Index

locate

public TimestampMapping locate(Timestamp t,
                               IndexTimestampSelector selector,
                               Lifetime lifetime)
Try and determine the position associated with the speicifed Timestamp.

Specified by:
locate in interface Index
Returns:
null if no position is found

locate

public TimestampMapping locate(Position p)
Try and determine the Timestamp associated with the speicifed Position. Uses IndexTimestampSelector.DATA and Lifetime.CONTINUOUS as defaults. Returns a TimestampMapping which contains the original Position and the found Timestamp.

Specified by:
locate in interface Index

locate

public TimestampMapping locate(Position pos,
                               IndexTimestampSelector selector,
                               Lifetime lifetime)
Try and determine the Timestamp associated with the speicifed Position. Returns a TimestampMapping which contains the original Position and the found Timestamp. Lifetime has no effect in this situation.

Specified by:
locate in interface Index

binarySearch

protected TimestampMapping binarySearch(Timestamp t,
                                        long start,
                                        long end,
                                        IndexTimestampSelector selector,
                                        Lifetime lifetime,
                                        int depth)
                                 throws GetItemException,
                                        IndexClosedException
Do a binary search of the list.

Throws:
GetItemException
IndexClosedException

select

public IndexView select(Interval interval)
Select an Interval given an Interval object. Defaults to using IndexTimestampSelector.DATA, Overlap.FREE, and Lifetime.CONTINUOUS, as these are the most common values. Returns null if it cant be done.

Specified by:
select in interface Index

select

public IndexView select(AbsoluteTimestamp t,
                        IntervalSpecifier intervalSpecifier)
Select an Interval given a Timestamp and an IntervalSpecifier. Defaults to using IndexTimestampSelector.DATA, Overlap.FREE, and Lifetime.CONTINUOUS, as these are the most common values. Returns null if it cant be done.

Specified by:
select in interface Index

select

public IndexView select(Interval interval,
                        IndexTimestampSelector selector,
                        Overlap overlap,
                        Lifetime lifetime)
Select an Interval given an Interval object. Returns null if it cant be done.

Specified by:
select in interface Index

select

public IndexView select(AbsoluteTimestamp t,
                        IntervalSpecifier intervalSpecifier,
                        IndexTimestampSelector selector,
                        Overlap overlap,
                        Lifetime lifetime)
Description copied from interface: Index
Select an Interval given a Timestamp and an IntervalSpecifier.

Specified by:
select in interface Index

filter

public IndexView filter(Function fn)
                 throws TimeIndexException
Filter some IndexItems out into a new IncoreIndex.

Specified by:
filter in interface Index
Throws:
TimeIndexException

map

public IndexView map(Function fn)
              throws TimeIndexException
Map a function to all of the IndexItems, resulting in a new IncoreIndex.

Specified by:
map in interface Index
Throws:
TimeIndexException

apply

public DoubleLinkedList apply(Function fn)
                       throws TimeIndexException
Apply a function to all of the IndexItems, resulting in a List of results.

Specified by:
apply in interface Index
Throws:
TimeIndexException

isActivated

public boolean isActivated()
Is the Index activated.

Specified by:
isActivated in interface Index

isTerminated

public boolean isTerminated()
Is the Index terminated.

Specified by:
isTerminated in interface IndexHeader

terminate

public Index terminate()
Make the Index finalized. It is not possible to add items ever again to an Index that has been terminated.

Specified by:
terminate in interface Index

commit

public boolean commit()
               throws IndexCommitException
Commit all changes to the index.

Specified by:
commit in interface Index
Throws:
IndexCommitException

setAutoCommit

public boolean setAutoCommit(boolean commit)
Set auto commit to be true or false. When auto commit is true, then every addItem() is automatically committed.

Specified by:
setAutoCommit in interface Index
Returns:
the previous value of auto commit.

isClosed

public boolean isClosed()
Is the Index closed.

Specified by:
isClosed in interface Index

isChanged

public boolean isChanged()
Has the index changed in any way.

Specified by:
isChanged in interface Index

isReadOnly

public boolean isReadOnly()
Is the Index only available for read-only operations.

Specified by:
isReadOnly in interface IndexHeader

iterator

public java.util.Iterator iterator()
Get an iterator over the IndexItems in the Index.

Specified by:
iterator in interface Index

getCache

public IndexCache getCache()
Get the current Cache.


getCachePolicy

public CachePolicy getCachePolicy()
Get the current CachePolicy.

Specified by:
getCachePolicy in interface Index

setCachePolicy

public CachePolicy setCachePolicy(CachePolicy policy)
Set a CachePolicy in order to manage the cache. Setting a new CachePolicy in the middle of operation can lose some timing information held by the existing CachePolicy, so it has to be used with care. Consequently, the Policy will only be changed if the IndexCache decides it is safe to do so.

Specified by:
setCachePolicy in interface Index
Returns:
the old policy if the policy was set

getLoadDataAutomatically

public boolean getLoadDataAutomatically()
Does the index load data automatically when doing a get item.

Specified by:
getLoadDataAutomatically in interface Index

setLoadDataAutomatically

public boolean setLoadDataAutomatically(boolean load)
Load data automatically when doing a get item.

Specified by:
setLoadDataAutomatically in interface Index
Returns:
the previous value of this status

eventMulticaster

public IndexEventMulticaster eventMulticaster()
Get the event listener.


addPrimaryEventListener

public void addPrimaryEventListener(IndexPrimaryEventListener l)
Add a IndexPrimaryEventListener.

Specified by:
addPrimaryEventListener in interface IndexEventGenerator

removePrimaryEventListener

public void removePrimaryEventListener(IndexPrimaryEventListener l)
Remove a IndexPrimaryEventListener.

Specified by:
removePrimaryEventListener in interface IndexEventGenerator

addAddEventListener

public void addAddEventListener(IndexAddEventListener l)
Add a IndexAddEventListener.

Specified by:
addAddEventListener in interface IndexEventGenerator

removeAddEventListener

public void removeAddEventListener(IndexAddEventListener l)
Remove a IndexAddEventListener.

Specified by:
removeAddEventListener in interface IndexEventGenerator

addAccessEventListener

public void addAccessEventListener(IndexAccessEventListener l)
Add a IndexAccessEventListener.

Specified by:
addAccessEventListener in interface IndexEventGenerator

removeAccessEventListener

public void removeAccessEventListener(IndexAccessEventListener l)
Remove a IndexAccessEventListener.

Specified by:
removeAccessEventListener in interface IndexEventGenerator


Timeindexing 2008