public final class

MutableSelection<K>

extends Selection<java.lang.Object>

 java.lang.Object

androidx.recyclerview.selection.Selection<java.lang.Object>

↳androidx.recyclerview.selection.MutableSelection<K>

Gradle dependencies

compile group: 'androidx.recyclerview', name: 'recyclerview-selection', version: '1.2.0-alpha01'

  • groupId: androidx.recyclerview
  • artifactId: recyclerview-selection
  • version: 1.2.0-alpha01

Artifact androidx.recyclerview:recyclerview-selection:1.2.0-alpha01 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.recyclerview:recyclerview-selection com.android.support:recyclerview-selection

Overview

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 SelectionTracker.copySelection(MutableSelection).

While the Selection class is not intrinsically immutable, it is not mutable by non-library code. Furthermore the value returned from SelectionTracker.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.
 

Summary

Constructors
publicMutableSelection()

Methods
booleanadd(java.lang.Object key)

Adds a new item to the primary selection.

voidclear()

Clears the primary selection.

voidcopyFrom(Selection<java.lang.Object> source)

Clones primary and provisional selection from supplied Selection.

booleanremove(java.lang.Object key)

Removes an item from the primary selection.

from Selection<K>contains, equals, hashCode, isEmpty, iterator, size, toString
from java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait

Constructors

public MutableSelection()

Methods

boolean add(java.lang.Object key)

Adds a new item to the primary selection.

Returns:

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

boolean remove(java.lang.Object key)

Removes an item from the primary selection.

Returns:

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

void copyFrom(Selection<java.lang.Object> source)

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

void clear()

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

Source

/*
 * Copyright 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.recyclerview.selection;

import androidx.annotation.NonNull;

/**
 * Subclass of {@link Selection} exposing public support for mutating the underlying
 * selection data. This is useful for clients of {@link SelectionTracker} that wish to
 * manipulate a copy of selection data obtained via
 * {@link SelectionTracker#copySelection(MutableSelection)}.
 *
 * <p>
 * While the {@link Selection} class is not intrinsically immutable, it is not mutable
 * by non-library code. Furthermore the value returned from {@link SelectionTracker#getSelection()}
 * is a live view of the underlying selection, mutable by the library itself.
 *
 * <p>
 * {@link 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.
 *
 *
 * <p><b>Example</b>
 *
 * <p>
 * <pre>
 * 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.
 * </pre>
 *
 * @see android.text.Selection
 *
 * @param <K> Selection key type. @see {@link StorageStrategy} for supported types.
 */
public final class MutableSelection<K> extends Selection<K> {

    @Override
    public boolean add(@NonNull K key) {
        return super.add(key);
    }

    @Override
    public boolean remove(@NonNull K key) {
        return super.remove(key);
    }

    @Override
    public void copyFrom(@NonNull Selection<K> source) {
        super.copyFrom(source);
    }

    @Override
    public void clear() {
        super.clear();
    }
}