Class ValueWithTime<T>

java.lang.Object
net.maswag.falcaun.ValueWithTime<T>
Type Parameters:
T - the type of values

public class ValueWithTime<T> extends Object
A sequence of values each associated with an increasing timestamp.
  • Field Details

    • timestamps

      protected final List<Double> timestamps
    • values

      protected final List<T> values
  • Constructor Details

    • ValueWithTime

      public ValueWithTime()
      Initializes with empty lists.
    • ValueWithTime

      public ValueWithTime(List<Double> timestamps, List<T> values)
      Initializes with the given timestamps and values. i-th timestamp corresponds to i-th value. So the sizes of timestamps and values must be equal.
      Parameters:
      timestamps - The list of timestamps
      values - The list of values
      Throws:
      IllegalArgumentException - if the sizes of timestamps and values are not equal or if any value is null
  • Method Details

    • duration

      public double duration()
      Get the duration of the signal. That is the difference between the last and first timestamps.
      Returns:
      The duration of the signal, or 0 if the signal is empty
    • size

      public int size()
      Get the number of contained values.
    • isEmpty

      public boolean isEmpty()
      Check if the value is empty.
    • at

      @Nullable public T at(double time)
      Get the value at the given time.
      Parameters:
      time - The time to get the value at
      Returns:
      the value at the closest time
    • range

      public ValueWithTime<T> range(double from, double to)
      Get the values in the given time range.
      Parameters:
      from - The start time (non-inclusive)
      to - The end time (inclusive)
    • range

      public ValueWithTime<T> range(double from, double to, boolean leftInclusive, boolean rightInclusive)
      Get the values in the given time range.
      Parameters:
      from - The start time
      to - The end time
      leftInclusive - Whether the start time is inclusive
      rightInclusive - Whether the end time is inclusive
    • stream

      public Stream<List<T>> stream(double signalStep)
      Stream the List of values between each signal step. Since the values between each signal step can be multiple in general, each element of the stream is a list.

      The i-th element is the list of values whose timestamp is between ((i-1) * signalStep, i * signalStep].

      Parameters:
      signalStep - The time step between each signal
      Returns:
      A stream of lists of values, grouped by signal step.