Class TrcDataBuffer

java.lang.Object
trclib.dataprocessor.TrcDataBuffer

public class TrcDataBuffer extends Object
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 Details

    • instanceName

      private final String instanceName
    • bufferSize

      private final int bufferSize
    • bufferedData

      private final ArrayList<Double> bufferedData
  • Constructor Details

    • TrcDataBuffer

      public TrcDataBuffer(String instanceName, int bufferSize)
      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

      public String toString()
      This method returns the instance name and the data in the buffer.
      Overrides:
      toString in class Object
      Returns:
      instance name and data.
    • 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

      public Double getValue(int index)
      This method returns the indexed value in the buffer.
      Parameters:
      index - specifies the buffer index of the value to retrieve.
      Returns:
      indexed value.
    • getLastValue

      public Double getLastValue()
      This method gets the last value in the buffer.
      Returns:
      last value in the buffer, null if the buffer is empty.
    • getBufferedData

      public Double[] getBufferedData()
      This method returns an array of the buffered values.
      Returns:
      array of buffered data, null if buffer is empty.
    • getMinimumValue

      public Double getMinimumValue()
      This method returns the minimum value in the buffer.
      Returns:
      minimum value in the buffer, null if buffer is empty.
    • getMaximumValue

      public Double 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.