PamguardMVC
Class DataUnitFinder<Tunit extends PamDataUnit>

java.lang.Object
  extended by PamguardMVC.DataUnitFinder<Tunit>
Direct Known Subclasses:
DeletedDataUnitFinder

public class DataUnitFinder<Tunit extends PamDataUnit>
extends java.lang.Object

Class for finding data units in a reasonably controlled and organised way.

It sets up a list iterator at the start of the data block and then searches for each requested data unit from the unit after the last unit requested. This will generally be an efficient way of matching two almost ordered lists of units.

If the iterator gets to the end of the list without finding a match it restarts at the beginning, only returning null (nothing found) when it has been right through the list exactly once.

The finder can work with a default mather of time and channel or with user created matchers which can use any criteria the user wants

Author:
Doug Gillespie
See Also:
DataUnitMatcher, DefaultUnitMatcher;

Field Summary
private  DataUnitMatcher dataUnitMatcher
           
private  Tunit lastUnit
           
private  java.util.ListIterator<Tunit> li
           
private  PamDataBlock<Tunit> pamDataBlock
           
 
Constructor Summary
DataUnitFinder(PamDataBlock<Tunit> pamDataBlock)
          Create a data unit finder that uses the default matcher.
DataUnitFinder(PamDataBlock<Tunit> pamDataBlock, DataUnitMatcher dataUnitMatcher)
          Create a data unit finder that uses a user created matcher
 
Method Summary
 Tunit findDataUnit(java.lang.Object... criteria)
          Find a data unit which satisfies the criteria in criteria.
 DataUnitMatcher getDataUnitMatcher()
           
 Tunit getLastUnit()
           
protected  java.util.ListIterator<Tunit> getListIterator()
           
 PamDataBlock<Tunit> getPamDataBlock()
           
 void setDataUnitMatcher(DataUnitMatcher dataUnitMatcher)
           
protected  void setListIterator(java.util.ListIterator<Tunit> li)
           
protected  void setupList()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataUnitMatcher

private DataUnitMatcher dataUnitMatcher

pamDataBlock

private PamDataBlock<Tunit extends PamDataUnit> pamDataBlock

li

private java.util.ListIterator<Tunit extends PamDataUnit> li

lastUnit

private Tunit extends PamDataUnit lastUnit
Constructor Detail

DataUnitFinder

public DataUnitFinder(PamDataBlock<Tunit> pamDataBlock)
Create a data unit finder that uses the default matcher.

Parameters:
pamDataBlock - parent PamDataBLock

DataUnitFinder

public DataUnitFinder(PamDataBlock<Tunit> pamDataBlock,
                      DataUnitMatcher dataUnitMatcher)
Create a data unit finder that uses a user created matcher

Parameters:
pamDataBlock - parent PamDataBlock
dataUnitMatcher - user created matcher
Method Detail

setupList

protected void setupList()

findDataUnit

public Tunit findDataUnit(java.lang.Object... criteria)
Find a data unit which satisfies the criteria in criteria.

For the default search, the criteria are either just the time in milliseconds OR both the time AND the channel bitmap.

For user defined matchers, the criteria will have to match whatever the matcher expects.

Parameters:
criteria - variable number of matching criteria.
Returns:
the next data unit in the data block that matches those criteria.

getDataUnitMatcher

public DataUnitMatcher getDataUnitMatcher()
Returns:
the dataUnitMatcher

setDataUnitMatcher

public void setDataUnitMatcher(DataUnitMatcher dataUnitMatcher)
Parameters:
dataUnitMatcher - the dataUnitMatcher to set

getPamDataBlock

public PamDataBlock<Tunit> getPamDataBlock()
Returns:
the pamDataBlock

getLastUnit

public Tunit getLastUnit()
Returns:
the lastUnit

getListIterator

protected java.util.ListIterator<Tunit> getListIterator()
Returns:
the list iterator

setListIterator

protected void setListIterator(java.util.ListIterator<Tunit> li)
Parameters:
li - the list iterator to set