# TimedValueQueue

Artifact: [androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/common/util/TimedValueQueue.java+class:androidx.media3.common.util.TimedValueQueue)

*** ** * ** ***


```
@UnstableApi
public final class TimedValueQueue<V>
```

<br />

*** ** * ** ***

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

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/common/util/TimedValueQueue#TimedValueQueue()()` |
| `https://developer.android.com/reference/androidx/media3/common/util/TimedValueQueue#TimedValueQueue(int)(int initialBufferSize)` Creates a TimedValueBuffer with the given initial buffer size. |

| ### Public methods |
|---|---|
| `synchronized void` | `https://developer.android.com/reference/androidx/media3/common/util/TimedValueQueue#add(long,V)(long timestamp, V value)` Associates the specified value with the specified timestamp. |
| `synchronized void` | `https://developer.android.com/reference/androidx/media3/common/util/TimedValueQueue#clear()()` Removes all of the values. |
| `synchronized @https://developer.android.com/reference/androidx/annotation/Nullable V` | `https://developer.android.com/reference/androidx/media3/common/util/TimedValueQueue#poll(long)(long timestamp)` Returns the value with the closest timestamp to the given timestamp. |
| `synchronized @https://developer.android.com/reference/androidx/annotation/Nullable V` | `https://developer.android.com/reference/androidx/media3/common/util/TimedValueQueue#pollFirst()()` Removes and returns the first value in the queue, or null if the queue is empty. |
| `synchronized @https://developer.android.com/reference/androidx/annotation/Nullable V` | `https://developer.android.com/reference/androidx/media3/common/util/TimedValueQueue#pollFloor(long)(long timestamp)` Returns the value with the greatest timestamp which is less than or equal to the given timestamp. |
| `synchronized int` | `https://developer.android.com/reference/androidx/media3/common/util/TimedValueQueue#size()()` 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 @Nullable 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 |
|---|---|
| `long timestamp` | The timestamp value. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable V` | The value with the closest timestamp or null if the buffer is empty. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/TimedValueQueue#pollFloor(long)` |   |

### pollFirst

```
synchronized public @Nullable V pollFirst()
```

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

### pollFloor

```
synchronized public @Nullable 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 |
|---|---|
| `long timestamp` | The timestamp value. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/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 |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/TimedValueQueue#poll(long)` |   |

### size

```
synchronized public int size()
```

Returns number of the values buffered.