MutableSelection


public final class MutableSelection<K> extends Selection


Subclass of Selection exposing public support for mutating the underlying selection data. This is useful for clients of SelectionTracker that wish to manipulate a copy of selection data obtained via copySelection.

While the Selection class is not intrinsically immutable, it is not mutable by non-library code. Furthermore the value returned from getSelection is a live view of the underlying selection, mutable by the library itself.

MutableSelection allows clients to obtain a mutable copy of the Selection state held by the selection library. This is useful in situations where a stable snapshot of the selection is required.

Example

MutableSelection snapshot = new MutableSelection();
selectionTracker.copySelection(snapshot);

// Clear the user visible selection.
selectionTracker.clearSelection();
// tracker.getSelection().isEmpty() will be true.
// shapshot has a copy of the previous selection.
Parameters
<K>

Selection key type. @see StorageStrategy for supported types.

See also
Selection

Summary

Public constructors

Public methods

boolean
add(@NonNull K key)

Adds a new item to the primary selection.

void

Clears the primary selection.

void

Clones primary and provisional selection from supplied Selection.

boolean
remove(@NonNull K key)

Removes an item from the primary selection.

Inherited methods

From java.lang.Iterable
void
forEach(Consumer<T> action)
abstract Iterator<T>
Spliterator<T>
From androidx.recyclerview.selection.Selection
boolean
boolean
equals(Object other)
int
boolean
@NonNull Iterator<K>

Returns an Iterator that iterators over the selection, *excluding* any provisional selection.

int
String

Public constructors

MutableSelection

Added in 1.0.0
public MutableSelection()

Public methods

add

Added in 1.0.0
public boolean add(@NonNull K key)

Adds a new item to the primary selection.

Returns
boolean

true if the operation resulted in a modification to the selection.

clear

Added in 1.0.0
public void clear()

Clears the primary selection. The provisional selection, if any, is unaffected.

copyFrom

Added in 1.0.0
public void copyFrom(@NonNull Selection<K> source)

Clones primary and provisional selection from supplied Selection. Does not copy active range data.

remove

Added in 1.0.0
public boolean remove(@NonNull K key)

Removes an item from the primary selection.

Returns
boolean

true if the operation resulted in a modification to the selection.