MutableOrderedScatterSet
public final class MutableOrderedScatterSet<E extends Object> extends OrderedScatterSet
| java.lang.Object | ||
| ↳ | androidx.collection.OrderedScatterSet | |
| ↳ | androidx.collection.MutableOrderedScatterSet |
MutableOrderedScatterSet is a container with a MutableSet-like interface based on a flat hash table implementation that preserves the insertion order for iteration. The underlying implementation is designed to avoid all allocations on insertion, removal, retrieval, and iteration. Allocations may still happen on insertion when the underlying storage needs to grow to accommodate newly added elements to the set.
This implementation guarantees the order of the elements when iterating over them using forEach or the iterator provided by asMutableSet.
This implementation is not thread-safe: if multiple threads access this container concurrently, and one or more threads modify the structure of the set (insertion or removal for instance), the calling code must provide the appropriate synchronization. Concurrent reads are however safe.
Note: when a Set is absolutely necessary, you can use the method asSet to create a thin wrapper around a MutableOrderedScatterSet. Please refer to asSet for more details and caveats.
Note: when a MutableSet is absolutely necessary, you can use the method asMutableSet to create a thin wrapper around a MutableOrderedScatterSet. Please refer to asMutableSet for more details and caveats.
| See also | |
|---|---|
Set |
Summary
Public constructors |
|---|
<E extends Object> MutableOrderedScatterSet(int initialCapacity)Creates a new |
Public methods |
|
|---|---|
final boolean |
Adds the specified element to the set. |
final boolean |
Adds all the |
final boolean |
Adds all the |
final boolean |
addAll(@NonNull ObjectList<@NonNull E> elements)Adds all the elements in the |
final boolean |
addAll(@NonNull OrderedScatterSet<@NonNull E> elements)Adds all the elements in the |
final boolean |
addAll(@NonNull ScatterSet<@NonNull E> elements)Adds all the elements in the |
final boolean |
Adds all the |
final @NonNull Set<@NonNull E> |
Wraps this |
final void |
clear()Removes all elements from this set. |
final void |
minusAssign(@NonNull E element)Removes the specified |
final void |
minusAssign(@NonNull E[] elements)Removes the specified |
final void |
minusAssign(@NonNull Iterable<@NonNull E> elements)Removes the specified |
final void |
minusAssign(@NonNull ObjectList<@NonNull E> elements)Removes the specified |
final void |
minusAssign(@NonNull OrderedScatterSet<@NonNull E> elements)Removes the specified |
final void |
minusAssign(@NonNull ScatterSet<@NonNull E> elements)Removes the specified |
final void |
minusAssign(@NonNull Sequence<@NonNull E> elements)Removes the specified |
final void |
plusAssign(@NonNull E element)Adds the specified element to the set. |
final void |
plusAssign(@NonNull E[] elements)Adds all the |
final void |
plusAssign(@NonNull Iterable<@NonNull E> elements)Adds all the |
final void |
plusAssign(@NonNull ObjectList<@NonNull E> elements)Adds all the elements in the |
final void |
plusAssign(@NonNull OrderedScatterSet<@NonNull E> elements)Adds all the elements in the |
final void |
plusAssign(@NonNull ScatterSet<@NonNull E> elements)Adds all the elements in the |
final void |
plusAssign(@NonNull Sequence<@NonNull E> elements)Adds all the |
final boolean |
Removes the specified |
final boolean |
Removes the specified |
final boolean |
Removes the specified |
final boolean |
removeAll(@NonNull ObjectList<@NonNull E> elements)Removes the specified |
final boolean |
removeAll(@NonNull OrderedScatterSet<@NonNull E> elements)Removes the specified |
final boolean |
removeAll(@NonNull ScatterSet<@NonNull E> elements)Removes the specified |
final boolean |
Removes the specified |
final void |
Removes any values for which the specified |
final boolean |
retainAll(@NonNull Collection<@NonNull E> elements)Removes all the entries in this set that are not contained in |
final boolean |
retainAll(@NonNull OrderedScatterSet<@NonNull E> elements)Removes all the entries in this set that are not contained in |
final boolean |
retainAll(@NonNull ScatterSet<@NonNull E> elements)Removes all the entries in this set that are not contained in |
final boolean |
Removes all the elements in this set for which the specified |
final @IntRange(from = 0) int |
trim()Trims this |
final void |
trimToSize(int maxSize)Remove entries until the total size of the remaining entries is less than or equal to |
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
MutableOrderedScatterSet
public <E extends Object> MutableOrderedScatterSet(int initialCapacity)
Creates a new MutableOrderedScatterSet
| Parameters | |
|---|---|
int initialCapacity |
The initial desired capacity for this container. the container will honor this value by guaranteeing its internal structures can hold that many elements without requiring any allocations. The initial capacity can be set to 0. |
Public methods
add
public final boolean add(@NonNull E element)
Adds the specified element to the set.
| Parameters | |
|---|---|
@NonNull E element |
The element to add to the set. |
| Returns | |
|---|---|
boolean |
|
addAll
public final boolean addAll(@NonNull E[] elements)
Adds all the elements into this set.
| Parameters | |
|---|---|
@NonNull E[] elements |
An array of elements to add to the set. |
| Returns | |
|---|---|
boolean |
|
addAll
public final boolean addAll(@NonNull Iterable<@NonNull E> elements)
Adds all the elements into this set.
| Returns | |
|---|---|
boolean |
|
addAll
public final boolean addAll(@NonNull ObjectList<@NonNull E> elements)
Adds all the elements in the elements set into this set.
| Parameters | |
|---|---|
@NonNull ObjectList<@NonNull E> elements |
An |
| Returns | |
|---|---|
boolean |
|
addAll
public final boolean addAll(@NonNull OrderedScatterSet<@NonNull E> elements)
Adds all the elements in the elements set into this set.
| Parameters | |
|---|---|
@NonNull OrderedScatterSet<@NonNull E> elements |
A |
| Returns | |
|---|---|
boolean |
|
addAll
public final boolean addAll(@NonNull ScatterSet<@NonNull E> elements)
Adds all the elements in the elements set into this set.
| Parameters | |
|---|---|
@NonNull ScatterSet<@NonNull E> elements |
A |
| Returns | |
|---|---|
boolean |
|
addAll
public final boolean addAll(@NonNull Sequence<@NonNull E> elements)
Adds all the elements into this set.
| Returns | |
|---|---|
boolean |
|
asMutableSet
public final @NonNull Set<@NonNull E> asMutableSet()
Wraps this OrderedScatterSet with a MutableSet interface. The MutableSet is backed by the OrderedScatterSet, so changes to the OrderedScatterSet are reflected in the MutableSet and vice-versa. If the OrderedScatterSet is modified while an iteration over the MutableSet is in progress (and vice- versa), the results of the iteration are undefined.
Note: while this method is useful to use this MutableOrderedScatterSet with APIs accepting MutableSet interfaces, it is less efficient to do so than to use MutableOrderedScatterSet's APIs directly. While the MutableSet implementation returned by this method tries to be as efficient as possible, the semantics of MutableSet may require the allocation of temporary objects for access and iteration.
minusAssign
public final void minusAssign(@NonNull E element)
Removes the specified element from the set if it is present.
| Parameters | |
|---|---|
@NonNull E element |
The element to be removed from the set. |
minusAssign
public final void minusAssign(@NonNull E[] elements)
Removes the specified elements from the set, if present.
| Parameters | |
|---|---|
@NonNull E[] elements |
An array of elements to be removed from the set. |
minusAssign
public final void minusAssign(@NonNull Iterable<@NonNull E> elements)
Removes the specified elements from the set, if present.
minusAssign
public final void minusAssign(@NonNull ObjectList<@NonNull E> elements)
Removes the specified elements from the set, if present.
| Parameters | |
|---|---|
@NonNull ObjectList<@NonNull E> elements |
An |
minusAssign
public final void minusAssign(@NonNull OrderedScatterSet<@NonNull E> elements)
Removes the specified elements from the set, if present.
| Parameters | |
|---|---|
@NonNull OrderedScatterSet<@NonNull E> elements |
A |
minusAssign
public final void minusAssign(@NonNull ScatterSet<@NonNull E> elements)
Removes the specified elements from the set, if present.
| Parameters | |
|---|---|
@NonNull ScatterSet<@NonNull E> elements |
A |
minusAssign
public final void minusAssign(@NonNull Sequence<@NonNull E> elements)
Removes the specified elements from the set, if present.
plusAssign
public final void plusAssign(@NonNull E element)
Adds the specified element to the set.
| Parameters | |
|---|---|
@NonNull E element |
The element to add to the set. |
plusAssign
public final void plusAssign(@NonNull E[] elements)
Adds all the elements into this set.
| Parameters | |
|---|---|
@NonNull E[] elements |
An array of elements to add to the set. |
plusAssign
public final void plusAssign(@NonNull Iterable<@NonNull E> elements)
Adds all the elements into this set.
plusAssign
public final void plusAssign(@NonNull ObjectList<@NonNull E> elements)
Adds all the elements in the elements set into this set.
| Parameters | |
|---|---|
@NonNull ObjectList<@NonNull E> elements |
An |
plusAssign
public final void plusAssign(@NonNull OrderedScatterSet<@NonNull E> elements)
Adds all the elements in the elements set into this set.
| Parameters | |
|---|---|
@NonNull OrderedScatterSet<@NonNull E> elements |
A |
plusAssign
public final void plusAssign(@NonNull ScatterSet<@NonNull E> elements)
Adds all the elements in the elements set into this set.
| Parameters | |
|---|---|
@NonNull ScatterSet<@NonNull E> elements |
A |
plusAssign
public final void plusAssign(@NonNull Sequence<@NonNull E> elements)
Adds all the elements into this set.
remove
public final boolean remove(@NonNull E element)
Removes the specified element from the set.
| Parameters | |
|---|---|
@NonNull E element |
The element to be removed from the set. |
| Returns | |
|---|---|
boolean |
|
removeAll
public final boolean removeAll(@NonNull E[] elements)
Removes the specified elements from the set, if present.
| Parameters | |
|---|---|
@NonNull E[] elements |
An array of elements to be removed from the set. |
| Returns | |
|---|---|
boolean |
|
removeAll
public final boolean removeAll(@NonNull Iterable<@NonNull E> elements)
Removes the specified elements from the set, if present.
| Parameters | |
|---|---|
@NonNull Iterable<@NonNull E> elements |
A Iterable of elements to be removed from the set. |
| Returns | |
|---|---|
boolean |
|
removeAll
public final boolean removeAll(@NonNull ObjectList<@NonNull E> elements)
Removes the specified elements from the set, if present.
| Parameters | |
|---|---|
@NonNull ObjectList<@NonNull E> elements |
An |
| Returns | |
|---|---|
boolean |
|
removeAll
public final boolean removeAll(@NonNull OrderedScatterSet<@NonNull E> elements)
Removes the specified elements from the set, if present.
| Parameters | |
|---|---|
@NonNull OrderedScatterSet<@NonNull E> elements |
A |
| Returns | |
|---|---|
boolean |
|
removeAll
public final boolean removeAll(@NonNull ScatterSet<@NonNull E> elements)
Removes the specified elements from the set, if present.
| Parameters | |
|---|---|
@NonNull ScatterSet<@NonNull E> elements |
A |
| Returns | |
|---|---|
boolean |
|
removeAll
public final boolean removeAll(@NonNull Sequence<@NonNull E> elements)
Removes the specified elements from the set, if present.
| Parameters | |
|---|---|
@NonNull Sequence<@NonNull E> elements |
A sequence of elements to be removed from the set. |
| Returns | |
|---|---|
boolean |
|
removeIf
public final void removeIf(@NonNull Function1<@NonNull E, @NonNull Boolean> predicate)
Removes any values for which the specified predicate returns true.
retainAll
public final boolean retainAll(@NonNull Collection<@NonNull E> elements)
Removes all the entries in this set that are not contained in elements.
| Parameters | |
|---|---|
@NonNull Collection<@NonNull E> elements |
A collection of elements to preserve in this set. |
| Returns | |
|---|---|
boolean |
|
retainAll
public final boolean retainAll(@NonNull OrderedScatterSet<@NonNull E> elements)
Removes all the entries in this set that are not contained in elements.
elements A set of elements to preserve in this set.
| Returns | |
|---|---|
boolean |
|
retainAll
public final boolean retainAll(@NonNull ScatterSet<@NonNull E> elements)
Removes all the entries in this set that are not contained in elements.
elements A set of elements to preserve in this set.
| Returns | |
|---|---|
boolean |
|
retainAll
public final boolean retainAll(@NonNull Function1<@NonNull E, @NonNull Boolean> predicate)
Removes all the elements in this set for which the specified predicate is true. For each element in the set, the predicate is invoked with that element as the sole parameter.
| Parameters | |
|---|---|
@NonNull Function1<@NonNull E, @NonNull Boolean> predicate |
Predicate invoked for each element in the set. When the predicate returns |
| Returns | |
|---|---|
boolean |
|
trim
public final @IntRange(from = 0) int trim()
Trims this MutableOrderedScatterSet's storage so it is sized appropriately to hold the current elements.
Returns the number of empty elements removed from this set's storage. Returns 0 if no trimming is necessary or possible.
trimToSize
public final void trimToSize(int maxSize)
Remove entries until the total size of the remaining entries is less than or equal to maxSize. Entries added last are removed first. Calling this method has no effect if maxSize is greater than size.