Class TimedValueQueue<V>


  • public final class TimedValueQueue<V>
    extends Object
    A utility class to keep a queue of values with timestamps. This class is thread safe.
    • Constructor Summary

      Constructors 
      Constructor Description
      TimedValueQueue()  
      TimedValueQueue​(int initialBufferSize)
      Creates a TimedValueBuffer with the given initial buffer size.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(long timestamp, V value)
      Associates the specified value with the specified timestamp.
      void clear()
      Removes all of the values.
      V poll​(long timestamp)
      Returns the value with the closest timestamp to the given timestamp.
      V pollFirst()
      Removes and returns the first value in the queue, or null if the queue is empty.
      V pollFloor​(long timestamp)
      Returns the value with the greatest timestamp which is less than or equal to the given timestamp.
      int size()
      Returns number of the values buffered.
    • Constructor Detail

      • TimedValueQueue

        public TimedValueQueue()
      • TimedValueQueue

        public TimedValueQueue​(int initialBufferSize)
        Creates a TimedValueBuffer with the given initial buffer size.
    • Method Detail

      • add

        public void add​(long timestamp,
                        V value)
        Associates the specified value with the specified timestamp. All new values should have a greater timestamp than the previously added values. Otherwise all values are removed before adding the new one.
      • clear

        public void clear()
        Removes all of the values.
      • size

        public int size()
        Returns number of the values buffered.
      • pollFirst

        @Nullable
        public V pollFirst()
        Removes and returns the first value in the queue, or null if the queue is empty.
      • pollFloor

        @Nullable
        public V pollFloor​(long timestamp)
        Returns the value with the greatest timestamp which is less than or equal to the given timestamp. Removes all older values and the returned one from the buffer.
        Parameters:
        timestamp - The timestamp value.
        Returns:
        The value with the greatest timestamp which is less than or equal to the given timestamp or null if there is no such value.
        See Also:
        poll(long)
      • poll

        @Nullable
        public V poll​(long timestamp)
        Returns the value with the closest timestamp to the given timestamp. Removes all older values including the returned one from the buffer.
        Parameters:
        timestamp - The timestamp value.
        Returns:
        The value with the closest timestamp or null if the buffer is empty.
        See Also:
        pollFloor(long)