# DefaultPreloadManager.SimpleRankingDataComparator

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/preload/DefaultPreloadManager.java+class:androidx.media3.exoplayer.source.preload.DefaultPreloadManager.SimpleRankingDataComparator)

*** ** * ** ***


```
public class DefaultPreloadManager.SimpleRankingDataComparator implements RankingDataComparator<Integer>
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/RankingDataComparator` which compares the ranks of the media items based on their distances to the `https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/DefaultPreloadManager.SimpleRankingDataComparator#setCurrentPlayingIndex(int)`.

## Summary

| ### Protected fields |
|---|---|
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/DefaultPreloadManager.SimpleRankingDataComparator#currentPlayingIndex()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/DefaultPreloadManager.SimpleRankingDataComparator#SimpleRankingDataComparator()()` Creates a `https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/DefaultPreloadManager.SimpleRankingDataComparator`. |

| ### Public methods |
|---|---|
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/DefaultPreloadManager.SimpleRankingDataComparator#compare(java.lang.Integer,java.lang.Integer)(https://developer.android.com/reference/java/lang/Integer.html o1, https://developer.android.com/reference/java/lang/Integer.html o2)` Compares the ranks of two media items based on their distances to the current playing index. |
| `final void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/DefaultPreloadManager.SimpleRankingDataComparator#setCurrentPlayingIndex(int)(int currentPlayingIndex)` Sets the index of the current playing media. |
| `final void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/DefaultPreloadManager.SimpleRankingDataComparator#setInvalidationListener(androidx.media3.exoplayer.source.preload.RankingDataComparator.InvalidationListener)( @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/RankingDataComparator.InvalidationListener invalidationListener )` Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/RankingDataComparator.InvalidationListener`. |

| ### Protected methods |
|---|---|
| `final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/DefaultPreloadManager.SimpleRankingDataComparator#getCurrentPlayingIndex()()` Returns the index of the current playing media, or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if not set. |

### Inherited methods

From [java.util.Comparator](https://developer.android.com/reference/java/util/Comparator.html) `static https://developer.android.com/reference/java/util/Comparator.html<T>` `<T, U extends https://developer.android.com/reference/java/lang/Comparable.html<U>> https://developer.android.com/reference/java/util/Comparator.html#comparing(java.util.function.Function&lt;? super T,? extends U&gt;)(https://developer.android.com/reference/java/util/function/Function.html<T, U> keyExtractor)` `static https://developer.android.com/reference/java/util/Comparator.html<T>` `<T> https://developer.android.com/reference/java/util/Comparator.html#comparingDouble(java.util.function.ToDoubleFunction&lt;? super T&gt;)(https://developer.android.com/reference/java/util/function/ToDoubleFunction.html<T> keyExtractor)` `static https://developer.android.com/reference/java/util/Comparator.html<T>` `<T> https://developer.android.com/reference/java/util/Comparator.html#comparingInt(java.util.function.ToIntFunction&lt;? super T&gt;)(https://developer.android.com/reference/java/util/function/ToIntFunction.html<T> keyExtractor)` `static https://developer.android.com/reference/java/util/Comparator.html<T>` `<T> https://developer.android.com/reference/java/util/Comparator.html#comparingLong(java.util.function.ToLongFunction&lt;? super T&gt;)(https://developer.android.com/reference/java/util/function/ToLongFunction.html<T> keyExtractor)` `static https://developer.android.com/reference/java/util/Comparator.html<T>` `<T extends https://developer.android.com/reference/java/lang/Comparable.html<T>> https://developer.android.com/reference/java/util/Comparator.html#naturalOrder()()` `static https://developer.android.com/reference/java/util/Comparator.html<T>` `<T> https://developer.android.com/reference/java/util/Comparator.html#nullsFirst(java.util.Comparator&lt;? super T&gt;)(https://developer.android.com/reference/java/util/Comparator.html<T> comparator)` `static https://developer.android.com/reference/java/util/Comparator.html<T>` `<T> https://developer.android.com/reference/java/util/Comparator.html#nullsLast(java.util.Comparator&lt;? super T&gt;)(https://developer.android.com/reference/java/util/Comparator.html<T> comparator)` `static https://developer.android.com/reference/java/util/Comparator.html<T>` `<T extends https://developer.android.com/reference/java/lang/Comparable.html<T>> https://developer.android.com/reference/java/util/Comparator.html#reverseOrder()()` `https://developer.android.com/reference/java/util/Comparator.html<T>` `https://developer.android.com/reference/java/util/Comparator.html#reversed()()` `https://developer.android.com/reference/java/util/Comparator.html<T>` `https://developer.android.com/reference/java/util/Comparator.html#thenComparing(java.util.Comparator&lt;? super T&gt;)(https://developer.android.com/reference/java/util/Comparator.html<T> other)` `https://developer.android.com/reference/java/util/Comparator.html<T>` `https://developer.android.com/reference/java/util/Comparator.html#thenComparingDouble(java.util.function.ToDoubleFunction&lt;? super T&gt;)(https://developer.android.com/reference/java/util/function/ToDoubleFunction.html<T> keyExtractor)` `https://developer.android.com/reference/java/util/Comparator.html<T>` `https://developer.android.com/reference/java/util/Comparator.html#thenComparingInt(java.util.function.ToIntFunction&lt;? super T&gt;)(https://developer.android.com/reference/java/util/function/ToIntFunction.html<T> keyExtractor)` `https://developer.android.com/reference/java/util/Comparator.html<T>` `https://developer.android.com/reference/java/util/Comparator.html#thenComparingLong(java.util.function.ToLongFunction&lt;? super T&gt;)(https://developer.android.com/reference/java/util/function/ToLongFunction.html<T> keyExtractor)`

## Protected fields

### currentPlayingIndex

```
protected int currentPlayingIndex
```

## Public constructors

### SimpleRankingDataComparator

```
public SimpleRankingDataComparator()
```

Creates a `https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/DefaultPreloadManager.SimpleRankingDataComparator`.

## Public methods

### compare

```
public int compare(Integer o1, Integer o2)
```

Compares the ranks of two media items based on their distances to the current playing index. The media item with lower rank will be preloaded earlier than the other. If the ranks of the two media items are equal, the relative preload order of them is arbitrary.

Apps can override this method if a more fine-tuned comparison logic is needed.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/Integer.html o1` | The index of the first media item to be compared. |
| `https://developer.android.com/reference/java/lang/Integer.html o2` | The index of the second media item to be compared. |

| Returns |
|---|---|
| `int` | A negative integer, zero, or a positive integer as the rank of the first media item is less than, equal to, or greater than the second. |

### setCurrentPlayingIndex

```
public final void setCurrentPlayingIndex(int currentPlayingIndex)
```

Sets the index of the current playing media.

| Parameters |
|---|---|
| `int currentPlayingIndex` | The index of current playing media. |

### setInvalidationListener

```
public final void setInvalidationListener(
    @Nullable RankingDataComparator.InvalidationListener invalidationListener
)
```

Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/RankingDataComparator.InvalidationListener`.

## Protected methods

### getCurrentPlayingIndex

```
protected final int getCurrentPlayingIndex()
```

Returns the index of the current playing media, or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if not set.