TimedValueQueue


@UnstableApi
class TimedValueQueue<V>


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

Summary

Public constructors

TimedValueQueue(initialBufferSize: Int)

Creates a TimedValueBuffer with the given initial buffer size.

Public functions

synchronized Unit
add(timestamp: Long, value: V!)

Associates the specified value with the specified timestamp.

synchronized Unit

Removes all of the values.

synchronized V?
poll(timestamp: Long)

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

synchronized V?

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

synchronized V?
pollFloor(timestamp: Long)

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

TimedValueQueue()

TimedValueQueue

TimedValueQueue(initialBufferSize: Int)

Creates a TimedValueBuffer with the given initial buffer size.

Public functions

add

synchronized fun add(timestamp: Long, value: V!): Unit

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 fun clear(): Unit

Removes all of the values.

poll

synchronized fun poll(timestamp: Long): V?

Returns the value with the closest timestamp to the given timestamp. Removes all older values including the returned one from the buffer.

Parameters
timestamp: Long

The timestamp value.

Returns
V?

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

See also
pollFloor

pollFirst

synchronized fun pollFirst(): V?

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

pollFloor

synchronized fun pollFloor(timestamp: Long): V?

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: Long

The timestamp value.

Returns
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 fun size(): Int

Returns number of the values buffered.