TimedValueQueue


@UnstableApi
public final class TimedValueQueue<V>


A utility class to keep a queue of values with timestamps. This class is thread safe.

Summary

Public constructors

TimedValueQueue(int initialBufferSize)

Creates a TimedValueBuffer with the given initial buffer size.

Public methods

synchronized void
add(long timestamp, V value)

Associates the specified value with the specified timestamp.

synchronized void

Removes all of the values.

synchronized @Nullable V
poll(long timestamp)

Returns the value with the closest timestamp to the given timestamp.

synchronized @Nullable V

Removes and returns the first value in the queue, or null if the queue is empty.

synchronized @Nullable V
pollFloor(long timestamp)

Returns the value with the greatest timestamp which is less than or equal to the given timestamp.

synchronized int

Returns number of the values buffered.

Public constructors

TimedValueQueue

public TimedValueQueue()

TimedValueQueue

public TimedValueQueue(int initialBufferSize)

Creates a TimedValueBuffer with the given initial buffer size.

Public methods

add

synchronized 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

synchronized public void clear()

Removes all of the values.

poll

synchronized public @Nullablepoll(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
long timestamp

The timestamp value.

Returns
@Nullable V

The value with the closest timestamp or null if the buffer is empty.

See also
pollFloor

pollFirst

synchronized public @NullablepollFirst()

Removes and returns the first value in the queue, or null if the queue is empty.

pollFloor

synchronized public @NullablepollFloor(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
long timestamp

The timestamp value.

Returns
@Nullable V

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

size

synchronized public int size()

Returns number of the values buffered.