Package trclib.dataprocessor
Class TrcDataBuffer
java.lang.Object
trclib.dataprocessor.TrcDataBuffer
This class implements a thread-safe data buffer for recording double values. It provides methods to access data
in the buffer. It also provides methods to return minimum, maximum and average of the data in the buffer.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTrcDataBuffer
(String instanceName, int bufferSize) Constructor: Create an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addValue
(double value) This method adds a value to the end of the buffer.void
clear()
This method clears the buffer.double
This method calculates the average value in the buffer.Double[]
This method returns an array of the buffered values.This method gets the last value in the buffer.This method returns the maximum value in the buffer.This method returns the minimum value in the buffer.getValue
(int index) This method returns the indexed value in the buffer.toString()
This method returns the instance name and the data in the buffer.
-
Field Details
-
instanceName
-
bufferSize
private final int bufferSize -
bufferedData
-
-
Constructor Details
-
TrcDataBuffer
Constructor: Create an instance of the object.- Parameters:
instanceName
- specifies the instance name.bufferSize
- specifies the maximum buffer size, can be 0 if no maximum limit.
-
-
Method Details
-
toString
This method returns the instance name and the data in the buffer. -
clear
public void clear()This method clears the buffer. -
addValue
public void addValue(double value) This method adds a value to the end of the buffer.- Parameters:
value
- specifies the value to be added to the buffer.
-
getValue
This method returns the indexed value in the buffer.- Parameters:
index
- specifies the buffer index of the value to retrieve.- Returns:
- indexed value.
-
getLastValue
This method gets the last value in the buffer.- Returns:
- last value in the buffer, null if the buffer is empty.
-
getBufferedData
This method returns an array of the buffered values.- Returns:
- array of buffered data, null if buffer is empty.
-
getMinimumValue
This method returns the minimum value in the buffer.- Returns:
- minimum value in the buffer, null if buffer is empty.
-
getMaximumValue
This method returns the maximum value in the buffer.- Returns:
- maximum value in the buffer, null if buffer is empty.
-
getAverageValue
public double getAverageValue()This method calculates the average value in the buffer.- Returns:
- average value calculated.
-