FloatSet
public sealed class FloatSet
MutableFloatSet |
|
FloatSet is a container with a Set-like interface designed to avoid allocations, including boxing.
This implementation makes no guarantee as to the order of the elements, nor does it make guarantees that the order remains constant over time.
Though FloatSet offers a read-only interface, it is always backed by a MutableFloatSet. Read operations alone are thread-safe. However, any mutations done through the backing MutableFloatSet while reading on another thread are not safe and the developer must protect the set from such changes during read operations.
| See also | |
|---|---|
MutableFloatSet |
Summary
Protected constructors |
|---|
FloatSet() |
Public methods |
|
|---|---|
final boolean |
Returns true if all elements match the given |
final boolean |
any()Returns |
final boolean |
Returns true if at least one element matches the given |
final boolean |
contains(float element)Returns |
final @IntRange(from = 0) int |
count()Returns the number of elements in this set. |
final @IntRange(from = 0) int |
Returns the number of elements matching the given |
boolean |
Compares the specified object |
final float |
first()Returns the first element in the collection. |
final float |
Returns the first element in the collection for which |
final void |
Iterates over every element stored in this set by invoking the specified |
final @IntRange(from = 0) int |
Returns the number of elements that can be stored in this set without requiring internal storage reallocation. |
final @IntRange(from = 0) int |
getSize()Returns the number of elements in this set. |
int |
hashCode()Returns the hash code value for this set. |
final boolean |
isEmpty()Indicates whether this set is empty. |
final boolean |
Returns |
final @NonNull String |
joinToString(Creates a String from the elements separated by |
final @NonNull String |
joinToString(Creates a String from the elements separated by |
final boolean |
none()Returns |
@NonNull String |
toString()Returns a string representation of this set. |
Protected constructors
Public methods
all
public final boolean all(@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate)
Returns true if all elements match the given predicate.
any
public final boolean any(@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate)
Returns true if at least one element matches the given predicate.
contains
public final boolean contains(float element)
Returns true if the specified element is present in this set, false otherwise.
| Parameters | |
|---|---|
float element |
The element to look for in this set |
count
public final @IntRange(from = 0) int count()
Returns the number of elements in this set.
count
public final @IntRange(from = 0) int count(@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate)
Returns the number of elements matching the given predicate.
equals
public boolean equals(Object other)
Compares the specified object other with this set for equality. The two objects are considered equal if other:
first
public final float first()
Returns the first element in the collection.
| Throws | |
|---|---|
kotlin.NoSuchElementException |
if the collection is empty |
first
public final float first(@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate)
Returns the first element in the collection for which predicate returns true.
Note There is no mechanism for both determining if there is an element that matches predicate and returning it if it exists. Developers should use forEach to achieve this behavior.
| Parameters | |
|---|---|
@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate |
Called on elements of the set, returning |
| Returns | |
|---|---|
float |
An element in the set for which |
| Throws | |
|---|---|
kotlin.NoSuchElementException |
if |
forEach
public final void forEach(@NonNull Function1<@NonNull Float, Unit> block)
Iterates over every element stored in this set by invoking the specified block lambda.
getCapacity
public final @IntRange(from = 0) int getCapacity()
Returns the number of elements that can be stored in this set without requiring internal storage reallocation.
getSize
public final @IntRange(from = 0) int getSize()
Returns the number of elements in this set.
hashCode
public int hashCode()
Returns the hash code value for this set. The hash code of a set is defined to be the sum of the hash codes of the elements in the set.
joinToString
public final @NonNull String joinToString(
@NonNull CharSequence separator,
@NonNull CharSequence prefix,
@NonNull CharSequence postfix,
int limit,
@NonNull CharSequence truncated
)
Creates a String from the elements separated by separator and using prefix before and postfix after, if supplied.
When a non-negative value of limit is provided, a maximum of limit items are used to generate the string. If the collection holds more than limit items, the string is terminated with truncated.
joinToString
public final @NonNull String joinToString(
@NonNull CharSequence separator,
@NonNull CharSequence prefix,
@NonNull CharSequence postfix,
int limit,
@NonNull CharSequence truncated,
@NonNull Function1<@NonNull Float, @NonNull CharSequence> transform
)
Creates a String from the elements separated by separator and using prefix before and postfix after, if supplied. transform dictates how each element will be represented.
When a non-negative value of limit is provided, a maximum of limit items are used to generate the string. If the collection holds more than limit items, the string is terminated with truncated.