DefaultPreloadManager.SimpleRankingDataComparator


public class DefaultPreloadManager.SimpleRankingDataComparator implements RankingDataComparator


A RankingDataComparator which compares the ranks of the media items based on their distances to the index of current playing media item.

Summary

Protected fields

int

Public constructors

Creates a SimpleRankingDataComparator.

Public methods

int

Compares the ranks of two media items based on their distances to the current playing index.

final void
setCurrentPlayingIndex(int currentPlayingIndex)

Sets the index of the current playing media.

final void

Sets the InvalidationListener.

Protected methods

final int

Returns the index of the current playing media, or INDEX_UNSET if not set.

Inherited methods

From java.util.Comparator
static Comparator<T>
<T, U> comparing(
    Function<T, U> keyExtractor,
    Comparator<U> keyComparator
)
static Comparator<T>
<T> comparingDouble(ToDoubleFunction<T> keyExtractor)
static Comparator<T>
<T> comparingInt(ToIntFunction<T> keyExtractor)
static Comparator<T>
<T> comparingLong(ToLongFunction<T> keyExtractor)
static Comparator<T>
<T extends Comparable<T>> naturalOrder()
static Comparator<T>
<T> nullsFirst(Comparator<T> comparator)
static Comparator<T>
<T> nullsLast(Comparator<T> comparator)
static Comparator<T>
<T extends Comparable<T>> reverseOrder()
Comparator<T>
Comparator<T>
Comparator<T>
Comparator<T>
Comparator<T>

Protected fields

currentPlayingIndex

protected int currentPlayingIndex

Public constructors

SimpleRankingDataComparator

public SimpleRankingDataComparator()

Creates a 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
Integer o1

The index of the first media item to be compared.

Integer 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 InvalidationListener.

Protected methods

getCurrentPlayingIndex

protected final int getCurrentPlayingIndex()

Returns the index of the current playing media, or INDEX_UNSET if not set.