# ShuffleOrder

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

*** ** * ** ***


```
@UnstableApi
public interface ShuffleOrder
```

<br />

Known direct subclasses [FakeShuffleOrder](https://developer.android.com/reference/androidx/media3/test/utils/FakeShuffleOrder), [ShuffleOrder.DefaultShuffleOrder](https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder.DefaultShuffleOrder), [ShuffleOrder.UnshuffledShuffleOrder](https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder.UnshuffledShuffleOrder)

|---|---|
| `https://developer.android.com/reference/androidx/media3/test/utils/FakeShuffleOrder` | Fake `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` which returns a reverse order. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder.DefaultShuffleOrder` | The default `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` implementation for random shuffle order. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder.UnshuffledShuffleOrder` | A `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` implementation which does not shuffle. |

*** ** * ** ***

Shuffled order of indices.

The shuffle order must be immutable to ensure thread safety.

The order must be consistent when traversed both `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder#getNextIndex(int)` and `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder#getPreviousIndex(int)`.

## Summary

| ### Nested types |
|---|
| `public class https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder.DefaultShuffleOrder implements https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` The default `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` implementation for random shuffle order. |
| `public final class https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder.UnshuffledShuffleOrder implements https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` A `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` implementation which does not shuffle. |

| ### Public methods |
|---|---|
| `abstract https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder#cloneAndClear()()` Returns a copy of the shuffle order with all elements removed. |
| `abstract https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder#cloneAndInsert(int,int)(int insertionIndex, int insertionCount)` Returns a copy of the shuffle order with newly inserted elements. |
| `default https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder#cloneAndMove(int,int,int)(int indexFrom, int indexToExclusive, int newIndexFrom)` Returns a copy of the shuffle order to be used after a move. |
| `abstract https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder#cloneAndRemove(int,int)(int indexFrom, int indexToExclusive)` Returns a copy of the shuffle order with a range of elements removed. |
| `default https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder#cloneAndSet(int,int)(int insertionCount, int startIndex)` Returns a copy of the shuffle order with all elements replaced. |
| `abstract int` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder#getFirstIndex()()` Returns the first index in the shuffle order, or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if the shuffle order is empty. |
| `abstract int` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder#getLastIndex()()` Returns the last index in the shuffle order, or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if the shuffle order is empty. |
| `abstract int` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder#getLength()()` Returns length of shuffle order. |
| `abstract int` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder#getNextIndex(int)(int index)` Returns the next index in the shuffle order. |
| `abstract int` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder#getPreviousIndex(int)(int index)` Returns the previous index in the shuffle order. |

## Public methods

### cloneAndClear

```
abstract ShuffleOrder cloneAndClear()
```

Returns a copy of the shuffle order with all elements removed.

### cloneAndInsert

```
abstract ShuffleOrder cloneAndInsert(int insertionIndex, int insertionCount)
```

Returns a copy of the shuffle order with newly inserted elements.

| Parameters |
|---|---|
| `int insertionIndex` | The index in the unshuffled order at which elements are inserted. |
| `int insertionCount` | The number of elements inserted at `insertionIndex`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` | A copy of this `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` with newly inserted elements. |

### cloneAndMove

```
default ShuffleOrder cloneAndMove(int indexFrom, int indexToExclusive, int newIndexFrom)
```

Returns a copy of the shuffle order to be used after a move.

The default implementation is a no-op. Custom implementation can choose to re-shuffle when items are moved.

| Parameters |
|---|---|
| `int indexFrom` | The starting index in the unshuffled order of the range to move, from before the move occurs. |
| `int indexToExclusive` | The smallest index (must be greater or equal to `indexFrom`) that is not included in the range of elements moved, from before the move occurs. |
| `int newIndexFrom` | The starting index in the unshuffled order of the range to move, from after the move occurs. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` | A copy of this `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` with the elements moved. |

### cloneAndRemove

```
abstract ShuffleOrder cloneAndRemove(int indexFrom, int indexToExclusive)
```

Returns a copy of the shuffle order with a range of elements removed.

| Parameters |
|---|---|
| `int indexFrom` | The starting index in the unshuffled order of the range to remove. |
| `int indexToExclusive` | The smallest index (must be greater or equal to `indexFrom`) that will not be removed. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` | A copy of this `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` without the elements in the removed range. |

### cloneAndSet

```
default ShuffleOrder cloneAndSet(int insertionCount, int startIndex)
```

Returns a copy of the shuffle order with all elements replaced.

The default implementation uses `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder#cloneAndClear()` and `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder#cloneAndInsert(int,int)` to replace all elements in the shuffle order. Custom implementations can override this method if the first element in the shuffled order should be set to the one whose index in the unshuffled order is `startIndex`.

| Parameters |
|---|---|
| `int insertionCount` | The number of elements. |
| `int startIndex` | The index of the new element in the unshuffled order that should be the first in the shuffled order or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if the the first element in the shuffled order is not specified. It should be ignored if the new list is empty, or if it is larger than the last index (inclusive) of the new list. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` | A copy of this `https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder` with the elements replaced. |

### getFirstIndex

```
abstract int getFirstIndex()
```

Returns the first index in the shuffle order, or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if the shuffle order is empty.

### getLastIndex

```
abstract int getLastIndex()
```

Returns the last index in the shuffle order, or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if the shuffle order is empty.

### getLength

```
abstract int getLength()
```

Returns length of shuffle order.

### getNextIndex

```
abstract int getNextIndex(int index)
```

Returns the next index in the shuffle order.

| Parameters |
|---|---|
| `int index` | An index. |

| Returns |
|---|---|
| `int` | The index after `index`, or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if `index` is the last element. |

### getPreviousIndex

```
abstract int getPreviousIndex(int index)
```

Returns the previous index in the shuffle order.

| Parameters |
|---|---|
| `int index` | An index. |

| Returns |
|---|---|
| `int` | The index before `index`, or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if `index` is the first element. |