simtools.data.buffer
Class BufferedDataSource

java.lang.Object
  extended by simtools.data.ValueProvider
      extended by simtools.data.DataSource
          extended by simtools.data.buffer.BufferedDataSource

public class BufferedDataSource
extends DataSource

A data source providing a buffering service Designed to be a wrapper around a DataSource, somewhat like what's done for the java InputStreams.

Version:
1.0 2001
Author:
Nicolas Brodu

Field Summary
protected  Buffer buffer
           
 DataSource dataSource
           
 
Fields inherited from class simtools.data.DataSource
endNotificationListeners, listeners, sortedOrder
 
Fields inherited from class simtools.data.ValueProvider
ByteProvider, DoubleProvider, FloatProvider, IntegerProvider, kind, LongProvider, ObjectProvider, ShortProvider
 
Constructor Summary
BufferedDataSource(Buffer b)
           
BufferedDataSource(DataSource ds)
           
BufferedDataSource(DataSource ds, int bufferSize)
           
 
Method Summary
 void addEndNotificationListener(EndNotificationListener enl)
           
 void addListener(DataSourceListener dsl)
           
 long computeLastIndex()
           
 java.lang.Object computeMax()
           
 java.lang.Object computeMin()
          Force the computation if possible.
 long computeStartIndex()
           
 boolean equals(java.lang.Object obj)
           
 Buffer getBuffer()
           
 byte getByteMax()
           
 byte getByteMin()
           
 byte getByteValue(long index)
          Optimized accessor for byte values.
 double getDoubleMax()
           
 double getDoubleMin()
           
 double getDoubleValue(long index)
          Optimized accessor for double values.
 float getFloatMax()
           
 float getFloatMin()
           
 float getFloatValue(long index)
          Optimized accessor for float values.
 DataInfo getInformation()
           
 int getIntegerMax()
           
 int getIntegerMin()
           
 int getIntegerValue(long index)
          Optimized accessor for int values.
 long getLastIndex()
           
 long getLongMax()
           
 long getLongMin()
           
 long getLongValue(long index)
          Optimized accessor for long values.
 java.lang.Object getMax()
           
 java.lang.Object getMin()
          Return values if possibly only, without expensive computations.
 short getShortMax()
           
 short getShortMin()
           
 short getShortValue(long index)
          Optimized accessor for short values.
 long getStartIndex()
           
 java.lang.Object getValue(long index)
           
 boolean isComparable()
          Check if the values are comparable with each other.
 void notifyEndNotificationListeners()
          Use this method only when this data source is the referer.
 void notifyListenersForDataReplaced(DataSource newData)
           
 void notifyListenersForIndexRangeChange(long startIndex, long lastIndex)
           
 void notifyListenersForInfoChange(DataInfo newInfo)
           
 void notifyListenersForOrderChange(int newOrder)
           
 void notifyListenersForValueChange(long minIndex, long maxIndex)
           
 void notifyListenersForValueRangeChange()
           
 void removeEndNotificationListener(EndNotificationListener enl)
           
 void removeListener(DataSourceListener dsl)
           
 void setSlice(long min, long max)
          Sets a region of interest in the DataSource.
 int sortedOrder()
          Check if the values are sorted or not.
 
Methods inherited from class simtools.data.DataSource
computeSortedOrder, createEmptyDataSource, getAuxiliarySources, getChoiceFormat, getDataSourceInformationClass, getSortedOrder, getSourceDependencies, isAuxiliary, isCompound, notifyListenersForDataReplaced, updateSortedOrder
 
Methods inherited from class simtools.data.ValueProvider
getKind, getObjectValue, valueClass
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buffer

protected Buffer buffer

dataSource

public DataSource dataSource
Constructor Detail

BufferedDataSource

public BufferedDataSource(DataSource ds)

BufferedDataSource

public BufferedDataSource(DataSource ds,
                          int bufferSize)

BufferedDataSource

public BufferedDataSource(Buffer b)
Method Detail

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class DataSource

getBuffer

public Buffer getBuffer()

getValue

public java.lang.Object getValue(long index)
                          throws DataException
Specified by:
getValue in class ValueProvider
Throws:
DataException

getByteValue

public byte getByteValue(long index)
                  throws DataException
Description copied from class: ValueProvider
Optimized accessor for byte values. If the provider can provide bytes directly, then it should override this method. Otherwise, the default implementation will do its best to convert the Object returned by getValue() to a byte. This conversion also parses strings, and returns 0 if it failed. An exception is thrown if, and only if, getValue throws it.

Overrides:
getByteValue in class ValueProvider
Throws:
DataException

getShortValue

public short getShortValue(long index)
                    throws DataException
Description copied from class: ValueProvider
Optimized accessor for short values. If the provider can provide shorts directly, then it should override this method. Otherwise, the default implementation will do its best to convert the Object returned by getValue() to a short. This conversion also parses strings, and returns 0 if it failed. An exception is thrown if, and only if, getValue throws it.

Overrides:
getShortValue in class ValueProvider
Throws:
DataException

getIntegerValue

public int getIntegerValue(long index)
                    throws DataException
Description copied from class: ValueProvider
Optimized accessor for int values. If the provider can provide ints directly, then it should override this method. Otherwise, the default implementation will do its best to convert the Object returned by getValue() to a int. This conversion also parses strings, and returns 0 if it failed. An exception is thrown if, and only if, getValue throws it.

Overrides:
getIntegerValue in class ValueProvider
Throws:
DataException

getLongValue

public long getLongValue(long index)
                  throws DataException
Description copied from class: ValueProvider
Optimized accessor for long values. If the provider can provide longs directly, then it should override this method. Otherwise, the default implementation will do its best to convert the Object returned by getValue() to a long. This conversion also parses strings, and returns 0 if it failed. An exception is thrown if, and only if, getValue throws it.

Overrides:
getLongValue in class ValueProvider
Throws:
DataException

getFloatValue

public float getFloatValue(long index)
                    throws DataException
Description copied from class: ValueProvider
Optimized accessor for float values. If the provider can provide floats directly, then it should override this method. Otherwise, the default implementation will do its best to convert the Object returned by getValue() to a float. This conversion also parses strings, and returns 0 if it failed. An exception is thrown if, and only if, getValue throws it.

Overrides:
getFloatValue in class ValueProvider
Throws:
DataException

getDoubleValue

public double getDoubleValue(long index)
                      throws DataException
Description copied from class: ValueProvider
Optimized accessor for double values. If the provider can provide doubles directly, then it should override this method. Otherwise, the default implementation will do its best to convert the Object returned by getValue() to a double. This conversion also parses strings, and returns 0 if it failed. An exception is thrown if, and only if, getValue throws it.

Overrides:
getDoubleValue in class ValueProvider
Throws:
DataException

setSlice

public void setSlice(long min,
                     long max)
Description copied from class: DataSource
Sets a region of interest in the DataSource. This is a purely informative function, but the DataSource may use this information to optimize itself on this specific range.

Overrides:
setSlice in class DataSource

getInformation

public DataInfo getInformation()
Overrides:
getInformation in class DataSource

getMin

public java.lang.Object getMin()
                        throws UnsupportedOperation
Description copied from class: DataSource
Return values if possibly only, without expensive computations.

Overrides:
getMin in class DataSource
Throws:
UnsupportedOperation

getMax

public java.lang.Object getMax()
                        throws UnsupportedOperation
Overrides:
getMax in class DataSource
Throws:
UnsupportedOperation

getByteMin

public byte getByteMin()
                throws DataException
Overrides:
getByteMin in class DataSource
Throws:
DataException

getByteMax

public byte getByteMax()
                throws DataException
Overrides:
getByteMax in class DataSource
Throws:
DataException

getShortMin

public short getShortMin()
                  throws DataException
Overrides:
getShortMin in class DataSource
Throws:
DataException

getShortMax

public short getShortMax()
                  throws DataException
Overrides:
getShortMax in class DataSource
Throws:
DataException

getIntegerMin

public int getIntegerMin()
                  throws DataException
Overrides:
getIntegerMin in class DataSource
Throws:
DataException

getIntegerMax

public int getIntegerMax()
                  throws DataException
Overrides:
getIntegerMax in class DataSource
Throws:
DataException

getLongMin

public long getLongMin()
                throws DataException
Overrides:
getLongMin in class DataSource
Throws:
DataException

getLongMax

public long getLongMax()
                throws DataException
Overrides:
getLongMax in class DataSource
Throws:
DataException

getFloatMin

public float getFloatMin()
                  throws DataException
Overrides:
getFloatMin in class DataSource
Throws:
DataException

getFloatMax

public float getFloatMax()
                  throws DataException
Overrides:
getFloatMax in class DataSource
Throws:
DataException

getDoubleMin

public double getDoubleMin()
                    throws DataException
Overrides:
getDoubleMin in class DataSource
Throws:
DataException

getDoubleMax

public double getDoubleMax()
                    throws DataException
Overrides:
getDoubleMax in class DataSource
Throws:
DataException

getStartIndex

public long getStartIndex()
                   throws UnsupportedOperation
Overrides:
getStartIndex in class DataSource
Throws:
UnsupportedOperation

getLastIndex

public long getLastIndex()
                  throws UnsupportedOperation
Overrides:
getLastIndex in class DataSource
Throws:
UnsupportedOperation

computeMin

public java.lang.Object computeMin()
                            throws UnsupportedOperation
Force the computation if possible. The operation may take some time.

Overrides:
computeMin in class DataSource
Throws:
UnsupportedOperation

computeMax

public java.lang.Object computeMax()
                            throws UnsupportedOperation
Overrides:
computeMax in class DataSource
Throws:
UnsupportedOperation

computeStartIndex

public long computeStartIndex()
                       throws UnsupportedOperation
Overrides:
computeStartIndex in class DataSource
Throws:
UnsupportedOperation

computeLastIndex

public long computeLastIndex()
                      throws UnsupportedOperation
Overrides:
computeLastIndex in class DataSource
Throws:
UnsupportedOperation

sortedOrder

public int sortedOrder()
Description copied from class: DataSource
Check if the values are sorted or not. This is usefull to optimize some computations (curves drawing for instance)

Overrides:
sortedOrder in class DataSource
Returns:
0 if the values are not sorted, 1 if the values are sorted in ascending order and -1 if the values are sorted in descending order

isComparable

public boolean isComparable()
Description copied from class: DataSource
Check if the values are comparable with each other. If they are, the sortedOrder() function tells if they are also sorted.

Overrides:
isComparable in class DataSource

addListener

public void addListener(DataSourceListener dsl)
Overrides:
addListener in class DataSource

notifyListenersForIndexRangeChange

public void notifyListenersForIndexRangeChange(long startIndex,
                                               long lastIndex)
Overrides:
notifyListenersForIndexRangeChange in class DataSource

notifyListenersForInfoChange

public void notifyListenersForInfoChange(DataInfo newInfo)
Overrides:
notifyListenersForInfoChange in class DataSource

notifyListenersForOrderChange

public void notifyListenersForOrderChange(int newOrder)
Overrides:
notifyListenersForOrderChange in class DataSource

notifyListenersForValueChange

public void notifyListenersForValueChange(long minIndex,
                                          long maxIndex)
Overrides:
notifyListenersForValueChange in class DataSource

notifyListenersForValueRangeChange

public void notifyListenersForValueRangeChange()
Overrides:
notifyListenersForValueRangeChange in class DataSource

notifyListenersForDataReplaced

public void notifyListenersForDataReplaced(DataSource newData)
Overrides:
notifyListenersForDataReplaced in class DataSource

removeListener

public void removeListener(DataSourceListener dsl)
Overrides:
removeListener in class DataSource

addEndNotificationListener

public void addEndNotificationListener(EndNotificationListener enl)
Overrides:
addEndNotificationListener in class DataSource

notifyEndNotificationListeners

public void notifyEndNotificationListeners()
Description copied from class: DataSource
Use this method only when this data source is the referer. See class comments for EndNotificationListener. Data source collections handle the notification directly

Overrides:
notifyEndNotificationListeners in class DataSource

removeEndNotificationListener

public void removeEndNotificationListener(EndNotificationListener enl)
Overrides:
removeEndNotificationListener in class DataSource