@UnstableApi
interface ShuffleOrder

Known direct subclasses
FakeShuffleOrder

Fake ShuffleOrder which returns a reverse order.

ShuffleOrder.DefaultShuffleOrder

The default ShuffleOrder implementation for random shuffle order.

ShuffleOrder.UnshuffledShuffleOrder

A 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 forwards and backwards.

Summary

Nested types

The default ShuffleOrder implementation for random shuffle order.

A ShuffleOrder implementation which does not shuffle.

Public functions

ShuffleOrder!

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

ShuffleOrder!
cloneAndInsert(insertionIndex: Int, insertionCount: Int)

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

ShuffleOrder!
cloneAndMove(indexFrom: Int, indexToExclusive: Int, newIndexFrom: Int)

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

ShuffleOrder!
cloneAndRemove(indexFrom: Int, indexToExclusive: Int)

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

ShuffleOrder!
cloneAndSet(insertionCount: Int, startIndex: Int)

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

Int

Returns the first index in the shuffle order, or INDEX_UNSET if the shuffle order is empty.

Int

Returns the last index in the shuffle order, or INDEX_UNSET if the shuffle order is empty.

Int

Returns length of shuffle order.

Int
getNextIndex(index: Int)

Returns the next index in the shuffle order.

Int

Returns the previous index in the shuffle order.

Public functions

cloneAndClear

fun cloneAndClear(): ShuffleOrder!

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

cloneAndInsert

fun cloneAndInsert(insertionIndex: Int, insertionCount: Int): ShuffleOrder!

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

Parameters
insertionIndex: Int

The index in the unshuffled order at which elements are inserted.

insertionCount: Int

The number of elements inserted at insertionIndex.

Returns
ShuffleOrder!

A copy of this ShuffleOrder with newly inserted elements.

cloneAndMove

fun cloneAndMove(indexFrom: Int, indexToExclusive: Int, newIndexFrom: Int): ShuffleOrder!

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
indexFrom: Int

The starting index in the unshuffled order of the range to move, from before the move occurs.

indexToExclusive: Int

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.

newIndexFrom: Int

The starting index in the unshuffled order of the range to move, from after the move occurs.

Returns
ShuffleOrder!

A copy of this ShuffleOrder with the elements moved.

cloneAndRemove

fun cloneAndRemove(indexFrom: Int, indexToExclusive: Int): ShuffleOrder!

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

Parameters
indexFrom: Int

The starting index in the unshuffled order of the range to remove.

indexToExclusive: Int

The smallest index (must be greater or equal to indexFrom) that will not be removed.

Returns
ShuffleOrder!

A copy of this ShuffleOrder without the elements in the removed range.

cloneAndSet

fun cloneAndSet(insertionCount: Int, startIndex: Int): ShuffleOrder!

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

The default implementation uses cloneAndClear and cloneAndInsert 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
insertionCount: Int

The number of elements.

startIndex: Int

The index of the new element in the unshuffled order that should be the first in the shuffled order or 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
ShuffleOrder!

A copy of this ShuffleOrder with the elements replaced.

getFirstIndex

fun getFirstIndex(): Int

Returns the first index in the shuffle order, or INDEX_UNSET if the shuffle order is empty.

getLastIndex

fun getLastIndex(): Int

Returns the last index in the shuffle order, or INDEX_UNSET if the shuffle order is empty.

getLength

fun getLength(): Int

Returns length of shuffle order.

getNextIndex

fun getNextIndex(index: Int): Int

Returns the next index in the shuffle order.

Parameters
index: Int

An index.

Returns
Int

The index after index, or INDEX_UNSET if index is the last element.

getPreviousIndex

fun getPreviousIndex(index: Int): Int

Returns the previous index in the shuffle order.

Parameters
index: Int

An index.

Returns
Int

The index before index, or INDEX_UNSET if index is the first element.