# TimedValueQueue

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/common/util/TimedValueQueue "View this page in Java")

<br />

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

<br />

*** ** * ** ***

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

## Summary

|                                                                                                                                        ### Public constructors                                                                                                                                        |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [TimedValueQueue](https://developer.android.com/reference/kotlin/androidx/media3/common/util/TimedValueQueue#TimedValueQueue())`()`                                                                                                                                                                   |
| [TimedValueQueue](https://developer.android.com/reference/kotlin/androidx/media3/common/util/TimedValueQueue#TimedValueQueue(int))`(initialBufferSize: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Creates a TimedValueBuffer with the given initial buffer size. |

|                                     ### Public functions                                     |
|----------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `synchronized `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [add](https://developer.android.com/reference/kotlin/androidx/media3/common/util/TimedValueQueue#add(long,V))`(timestamp: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`, value: V!)` Associates the specified value with the specified timestamp.                                     |
| `synchronized `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [clear](https://developer.android.com/reference/kotlin/androidx/media3/common/util/TimedValueQueue#clear())`()` Removes all of the values.                                                                                                                                                                              |
| `synchronized V?`                                                                            | [poll](https://developer.android.com/reference/kotlin/androidx/media3/common/util/TimedValueQueue#poll(long))`(timestamp: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Returns the value with the closest timestamp to the given timestamp.                                        |
| `synchronized V?`                                                                            | [pollFirst](https://developer.android.com/reference/kotlin/androidx/media3/common/util/TimedValueQueue#pollFirst())`()` Removes and returns the first value in the queue, or null if the queue is empty.                                                                                                                |
| `synchronized V?`                                                                            | [pollFloor](https://developer.android.com/reference/kotlin/androidx/media3/common/util/TimedValueQueue#pollFloor(long))`(timestamp: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Returns the value with the greatest timestamp which is less than or equal to the given timestamp. |
| `synchronized `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)   | [size](https://developer.android.com/reference/kotlin/androidx/media3/common/util/TimedValueQueue#size())`()` 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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The timestamp value. |

| Returns |
|---------|----------------------------------------------------------------------|
| `V?`    | The value with the closest timestamp or null if the buffer is empty. |

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

### 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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | 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](https://developer.android.com/reference/kotlin/androidx/media3/common/util/TimedValueQueue#poll(long)) |   |

### size

```
synchronized fun size(): Int
```

Returns number of the values buffered.