simtools.data
Class DataSourceCollectionAnimator

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.Vector
              extended by simtools.data.DataSourceCollection
                  extended by simtools.data.DynamicDataSourceCollection
                      extended by simtools.data.DataSourceCollectionAnimator
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.List, java.util.RandomAccess, DataSourceCollectionListener
Direct Known Subclasses:
DataSourceCollectionAnimator

public class DataSourceCollectionAnimator
extends DynamicDataSourceCollection
implements DataSourceCollectionListener

This class adds dynamical features to a DataSourceCollection. This is useful to replay time series, for example. It will use the underlying collection to provide the values, and has its own API to control how to advance the index : step by step, or with a timer. Note: All APIs from superclasses are also redirected, including vector. Collective data sources are also redirect to us. So, this wrapper should really be transparent. This is especially important to understand the code behind buffer functions also works without overloading base functions.

Author:
Nicolas Brodu
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class simtools.data.DynamicDataSourceCollection
DynamicDataSourceCollection.SourceInfo
 
Nested classes/interfaces inherited from class simtools.data.DataSourceCollection
DataSourceCollection.Container
 
Field Summary
protected  boolean autoStop
           
protected  boolean finished
           
static java.lang.String MARKER
           
protected  long period
           
protected  DataSourceCollection target
           
protected  java.util.Timer timer
           
 
Fields inherited from class simtools.data.DynamicDataSourceCollection
ourInfo, sourceInfo
 
Fields inherited from class simtools.data.DataSourceCollection
buffers, endNotificationListeners, lastIndex, listeners, map, startIndex
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
DataSourceCollectionAnimator(DataSourceCollection dsc)
           
 
Method Summary
 void add(int index, java.lang.Object element)
           
 boolean add(java.lang.Object o)
           
 boolean addAll(java.util.Collection c)
           
 boolean addAll(int index, java.util.Collection c)
           
 void addElement(java.lang.Object obj)
           
 int capacity()
           
 void clear()
           
 java.lang.Object clone()
           
 boolean contains(java.lang.Object elem)
           
 boolean containsAll(java.util.Collection c)
           
 void copyInto(java.lang.Object[] anArray)
           
protected  DataSource createDataSource(DataInfo info)
           
protected  DataSource createDataSource(DataInfo info, int kind)
          Add a data source with the given info.
 void DataSourceCollectionDataSourceAdded(DataSourceCollection dsc, DataSource ds)
          Called when the information about the data source collection changed
 void DataSourceCollectionDataSourceRemoved(DataSourceCollection dsc, DataSource ds)
          Called when the information about the data source collection changed
 void DataSourceCollectionInfoChanged(DataSourceCollection dsc, DataInfo newInfo)
          Called when the information about the data source collection changed
 void DataSourceCollectionRemoved(DataSourceCollection dsc)
          Called when the data source collection has been removed
 java.lang.Object elementAt(int index)
           
 java.util.Enumeration elements()
           
 void ensureCapacity(int minCapacity)
           
 boolean equals(java.lang.Object o)
           
 java.lang.Object firstElement()
           
 java.lang.Object get(int index)
           
 DataSource get(java.lang.String id)
           
 DataInfo getInformation()
           
 long getPeriod()
           
 DataSourceCollection getTargetCollection()
           
 int hashCode()
          Overrides Vector/AbstractList implementation to get a fix hashcode and be able to put and remove a collection from a HashSet for instance
 int indexOf(java.lang.Object elem)
           
 int indexOf(java.lang.Object elem, int index)
           
 void insertElementAt(java.lang.Object obj, int index)
           
 boolean isAutoStop()
           
 boolean isEmpty()
           
 boolean isFinished()
           
 boolean isRunning()
           
 java.util.Iterator iterator()
           
 java.lang.Object lastElement()
           
 int lastIndexOf(java.lang.Object elem)
           
 int lastIndexOf(java.lang.Object elem, int index)
           
 java.util.ListIterator listIterator()
           
 java.util.ListIterator listIterator(int index)
           
 java.lang.Object remove(int index)
           
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection c)
           
 void removeAllElements()
           
 boolean removeElement(java.lang.Object obj)
           
 void removeElementAt(int index)
           
 void reset()
          Resets the source.
 boolean retainAll(java.util.Collection c)
           
 java.lang.Object set(int index, java.lang.Object element)
           
 void setAutoStop(boolean autoStop)
           
 void setElementAt(java.lang.Object obj, int index)
           
 void setPeriod(long period)
          Sets a period for cyclic execution
 void setSize(int newSize)
           
 int size()
           
 void start()
          Starts to update the values with the previously set period.
 void start(long period)
          Starts to update the values with the given period.
 void step()
          Increase current index
 void stop()
          Stop to update the values.
 java.util.List subList(int fromIndex, int toIndex)
           
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] a)
           
 java.lang.String toString()
           
 void trimToSize()
           
 
Methods inherited from class simtools.data.DynamicDataSourceCollection
bufferize, bufferize, bufferize, changeDataSourceInfo, changeInfo, computeLastIndex, computeMax, computeMin, computeStartIndex, getByteMax, getByteMin, getDoubleMax, getDoubleMin, getFloatMax, getFloatMin, getInformation, getIntegerMax, getIntegerMin, getKind, getLastIndex, getLongMax, getLongMin, getMax, getMin, getShortMax, getShortMin, getStartIndex, getValue, isComparable, registerNewValues, removeDataSource, removeDataSource, setByteValue, setDoubleValue, setFloatValue, setIntegerValue, setLongValue, setObjectValue, setShortValue, valueClass
 
Methods inherited from class simtools.data.DataSourceCollection
addEndNotificationListener, addListener, attachBuffer, computeLastIndex, computeStartIndex, getByteValue, getCollectionContainers, getDoubleValue, getFloatValue, getIntegerValue, getLastIndex, getLongValue, getShortValue, getStartIndex, isCompound, notifyEndNotificationListeners, notifyListenersForCollectionRemoved, notifyListenersForDataSourceAdded, notifyListenersForDataSourceRemoved, notifyListenersForInfoChange, removeEndNotificationListener, removeListener, setSlice, sortedOrder
 
Methods inherited from class java.util.Vector
removeRange
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MARKER

public static final java.lang.String MARKER
See Also:
Constant Field Values

target

protected DataSourceCollection target

period

protected long period

timer

protected java.util.Timer timer

finished

protected boolean finished

autoStop

protected boolean autoStop
Constructor Detail

DataSourceCollectionAnimator

public DataSourceCollectionAnimator(DataSourceCollection dsc)
Method Detail

isFinished

public boolean isFinished()
Returns:
true iff the underlying data source has no more values

getInformation

public DataInfo getInformation()
Overrides:
getInformation in class DynamicDataSourceCollection

step

public void step()
          throws DataException
Increase current index

Throws:
DataException

getPeriod

public long getPeriod()
Returns:
The current period, in milliseconds

setPeriod

public void setPeriod(long period)
Sets a period for cyclic execution

Parameters:
period, - in milliseconds

isRunning

public boolean isRunning()
Returns:
true is the values are beeing updated cyclically.

start

public void start(long period)
Starts to update the values with the given period.


start

public void start()
Starts to update the values with the previously set period. Default is 1 second.


stop

public void stop()
Stop to update the values. This method is automatically called when there is no more data in the underlying data source, if this option is chosen.


reset

public void reset()
Resets the source. Next call to step will show the first source element.


isAutoStop

public boolean isAutoStop()
Returns:
Returns the autoStop.

setAutoStop

public void setAutoStop(boolean autoStop)
Parameters:
autoStop - The autoStop to set.

createDataSource

protected DataSource createDataSource(DataInfo info,
                                      int kind)
Description copied from class: DynamicDataSourceCollection
Add a data source with the given info. Make sure you call this function before calling setValue, or just after calling registerNewValues() and before setting the values for the next round.

Overrides:
createDataSource in class DynamicDataSourceCollection
Parameters:
info - Any information that will describe the data source, null is possible but not recommended.
kind - the data source kind, see ValueProvider. Object is default.
Returns:
DataSource

createDataSource

protected DataSource createDataSource(DataInfo info)
Overrides:
createDataSource in class DynamicDataSourceCollection

DataSourceCollectionInfoChanged

public void DataSourceCollectionInfoChanged(DataSourceCollection dsc,
                                            DataInfo newInfo)
Description copied from interface: DataSourceCollectionListener
Called when the information about the data source collection changed

Specified by:
DataSourceCollectionInfoChanged in interface DataSourceCollectionListener
Parameters:
dsc - The data source collection that changed
newInfo - The new information concerning this collection

DataSourceCollectionDataSourceAdded

public void DataSourceCollectionDataSourceAdded(DataSourceCollection dsc,
                                                DataSource ds)
Description copied from interface: DataSourceCollectionListener
Called when the information about the data source collection changed

Specified by:
DataSourceCollectionDataSourceAdded in interface DataSourceCollectionListener
Parameters:
dsc - The data source collection that changed
ds - The data source that was added

DataSourceCollectionDataSourceRemoved

public void DataSourceCollectionDataSourceRemoved(DataSourceCollection dsc,
                                                  DataSource ds)
Description copied from interface: DataSourceCollectionListener
Called when the information about the data source collection changed

Specified by:
DataSourceCollectionDataSourceRemoved in interface DataSourceCollectionListener
Parameters:
dsc - The data source collection that changed
ds - The data source that was removed

DataSourceCollectionRemoved

public void DataSourceCollectionRemoved(DataSourceCollection dsc)
Description copied from interface: DataSourceCollectionListener
Called when the data source collection has been removed

Specified by:
DataSourceCollectionRemoved in interface DataSourceCollectionListener
Parameters:
dsc - The data source collection that has been removed

get

public DataSource get(java.lang.String id)
Overrides:
get in class DataSourceCollection
Returns:
data source related to a string id

copyInto

public void copyInto(java.lang.Object[] anArray)
Overrides:
copyInto in class java.util.Vector

trimToSize

public void trimToSize()
Overrides:
trimToSize in class java.util.Vector

ensureCapacity

public void ensureCapacity(int minCapacity)
Overrides:
ensureCapacity in class java.util.Vector

setSize

public void setSize(int newSize)
Overrides:
setSize in class java.util.Vector

capacity

public int capacity()
Overrides:
capacity in class java.util.Vector

size

public int size()
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.List
Overrides:
size in class java.util.Vector

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection
Specified by:
isEmpty in interface java.util.List
Overrides:
isEmpty in class java.util.Vector

elements

public java.util.Enumeration elements()
Overrides:
elements in class java.util.Vector

contains

public boolean contains(java.lang.Object elem)
Specified by:
contains in interface java.util.Collection
Specified by:
contains in interface java.util.List
Overrides:
contains in class java.util.Vector

indexOf

public int indexOf(java.lang.Object elem)
Specified by:
indexOf in interface java.util.List
Overrides:
indexOf in class java.util.Vector

indexOf

public int indexOf(java.lang.Object elem,
                   int index)
Overrides:
indexOf in class java.util.Vector

lastIndexOf

public int lastIndexOf(java.lang.Object elem)
Specified by:
lastIndexOf in interface java.util.List
Overrides:
lastIndexOf in class java.util.Vector

lastIndexOf

public int lastIndexOf(java.lang.Object elem,
                       int index)
Overrides:
lastIndexOf in class java.util.Vector

elementAt

public java.lang.Object elementAt(int index)
Overrides:
elementAt in class java.util.Vector

firstElement

public java.lang.Object firstElement()
Overrides:
firstElement in class java.util.Vector

lastElement

public java.lang.Object lastElement()
Overrides:
lastElement in class java.util.Vector

setElementAt

public void setElementAt(java.lang.Object obj,
                         int index)
Overrides:
setElementAt in class java.util.Vector

removeElementAt

public void removeElementAt(int index)
Overrides:
removeElementAt in class java.util.Vector

insertElementAt

public void insertElementAt(java.lang.Object obj,
                            int index)
Overrides:
insertElementAt in class java.util.Vector

addElement

public void addElement(java.lang.Object obj)
Overrides:
addElement in class java.util.Vector

removeElement

public boolean removeElement(java.lang.Object obj)
Overrides:
removeElement in class java.util.Vector

removeAllElements

public void removeAllElements()
Overrides:
removeAllElements in class DataSourceCollection

clone

public java.lang.Object clone()
Overrides:
clone in class java.util.Vector

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List
Overrides:
toArray in class java.util.Vector

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List
Overrides:
toArray in class java.util.Vector

get

public java.lang.Object get(int index)
Specified by:
get in interface java.util.List
Overrides:
get in class java.util.Vector

set

public java.lang.Object set(int index,
                            java.lang.Object element)
Specified by:
set in interface java.util.List
Overrides:
set in class java.util.Vector

add

public boolean add(java.lang.Object o)
Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.List
Overrides:
add in class java.util.Vector

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.List
Overrides:
remove in class java.util.Vector

add

public void add(int index,
                java.lang.Object element)
Specified by:
add in interface java.util.List
Overrides:
add in class java.util.Vector

remove

public java.lang.Object remove(int index)
Specified by:
remove in interface java.util.List
Overrides:
remove in class java.util.Vector

clear

public void clear()
Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.List
Overrides:
clear in class java.util.Vector

containsAll

public boolean containsAll(java.util.Collection c)
Specified by:
containsAll in interface java.util.Collection
Specified by:
containsAll in interface java.util.List
Overrides:
containsAll in class java.util.Vector

addAll

public boolean addAll(java.util.Collection c)
Specified by:
addAll in interface java.util.Collection
Specified by:
addAll in interface java.util.List
Overrides:
addAll in class java.util.Vector

removeAll

public boolean removeAll(java.util.Collection c)
Specified by:
removeAll in interface java.util.Collection
Specified by:
removeAll in interface java.util.List
Overrides:
removeAll in class java.util.Vector

retainAll

public boolean retainAll(java.util.Collection c)
Specified by:
retainAll in interface java.util.Collection
Specified by:
retainAll in interface java.util.List
Overrides:
retainAll in class java.util.Vector

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Specified by:
addAll in interface java.util.List
Overrides:
addAll in class java.util.Vector

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Collection
Specified by:
equals in interface java.util.List
Overrides:
equals in class java.util.Vector

hashCode

public int hashCode()
Description copied from class: DataSourceCollection
Overrides Vector/AbstractList implementation to get a fix hashcode and be able to put and remove a collection from a HashSet for instance

Specified by:
hashCode in interface java.util.Collection
Specified by:
hashCode in interface java.util.List
Overrides:
hashCode in class DataSourceCollection

toString

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

subList

public java.util.List subList(int fromIndex,
                              int toIndex)
Specified by:
subList in interface java.util.List
Overrides:
subList in class java.util.Vector

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in interface java.util.List
Overrides:
iterator in class java.util.AbstractList

listIterator

public java.util.ListIterator listIterator()
Specified by:
listIterator in interface java.util.List
Overrides:
listIterator in class java.util.AbstractList

listIterator

public java.util.ListIterator listIterator(int index)
Specified by:
listIterator in interface java.util.List
Overrides:
listIterator in class java.util.AbstractList

getTargetCollection

public DataSourceCollection getTargetCollection()
Returns: