SortedList

open class SortedList<T>(source)

A Sorted list implementation that can keep items in order and also notify for changes in the list such that it can be bound to a RecyclerView.Adapter.

It keeps items ordered using the compare method and uses binary search to retrieve items. If the sorting criteria of your items may change, make sure you call appropriate methods while editing them to avoid data inconsistencies.

You can control the order of items and change notifications via the Callback parameter.

Constructors

Link copied to clipboard
constructor(@NonNull klass: Class<T>, @NonNull callback: SortedList.Callback<T>)
Creates a new SortedList of type T.
constructor(@NonNull klass: Class<T>, @NonNull callback: SortedList.Callback<T>, initialCapacity: Int)
Creates a new SortedList of type T.

Types

Link copied to clipboard
A callback implementation that can batch notify events dispatched by the SortedList.
Link copied to clipboard
The class that controls the behavior of the SortedList.

Properties

Link copied to clipboard
Used by indexOf when the item cannot be found in the list.

Functions

Link copied to clipboard
open fun add(item: T): Int
Adds the given item to the list.
Link copied to clipboard
open fun addAll(@NonNull items: Array<T>)
open fun addAll(@NonNull items: Collection<T>)
open fun addAll(@NonNull items: Array<T>, mayModifyInput: Boolean)
Adds the given items to the list.
Link copied to clipboard
Batches adapter updates that happen after calling this method and before calling endBatchedUpdates.
Link copied to clipboard
open fun clear()
Removes all items from the SortedList.
Link copied to clipboard
Ends the update transaction and dispatches any remaining event to the callback.
Link copied to clipboard
open fun get(index: Int): T
Returns the item at the given index.
Link copied to clipboard
open fun indexOf(item: T): Int
Returns the position of the provided item.
Link copied to clipboard
This method can be used to recalculate the position of the item at the given index, without triggering an onChanged callback.
Link copied to clipboard
open fun remove(item: T): Boolean
Removes the provided item from the list and calls onRemoved.
Link copied to clipboard
open fun removeItemAt(index: Int): T
Removes the item at the given index and calls onRemoved.
Link copied to clipboard
open fun replaceAll(@NonNull items: Array<T>)
open fun replaceAll(@NonNull items: Collection<T>)
open fun replaceAll(@NonNull items: Array<T>, mayModifyInput: Boolean)
Replaces the current items with the new items, dispatching ListUpdateCallback events for each change detected as appropriate.
Link copied to clipboard
open fun size(): Int
The number of items in the list.
Link copied to clipboard
open fun updateItemAt(index: Int, item: T)
Updates the item at the given index and calls onChanged and/or onMoved if necessary.