PriorityMap

class PriorityMap<K : Comparable<K>?, V>

A map that visits higher priorities first and the most recently inserted value first within a priority. Replacing a value preserves its position; putting an existing key inserts it again. Traversal starts in constant time; insertion can take linear time. This map is not thread-safe. Its independent iterators support removal and are fail-fast on a best-effort basis after structural changes outside that iterator.


var animations = new PriorityMap<String, String>();
animations.put("idle", "idle animation", 0);
var iterator = animations.valueIterator();
while (iterator.hasNext()) {
    if (iterator.next().isEmpty()) iterator.remove();
}

Since

3.0.0

Parameters

<K>

the type of keys maintained by this map

<V>

the type of mapped values

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
@Nullable
open fun get(@NotNull key: @NotNull K): @Nullable V
Returns the value to which the specified key is mapped.
Link copied to clipboard
open fun isEmpty(): Boolean
Returns true if this map contains no key-value mappings.
Link copied to clipboard
@Nullable
open fun put(@NotNull key: @NotNull K, @NotNull value: @NotNull V, priority: Int): @Nullable V
Associates the specified value with the specified key and priority in this map.
Link copied to clipboard
@Nullable
open fun remove(@NotNull key: @NotNull K): @Nullable V
Removes the mapping for a key from this map if it is present.
Link copied to clipboard
@Nullable
open fun replace(@NotNull key: @NotNull K, @NotNull function: @NotNull (V) -> V): @Nullable V
Replaces the entry for the specified key only if it is currently mapped to some value.
Link copied to clipboard
@NotNull
open fun valueIterator(): @NotNull Iterator<V>
Returns a new, independent iterator over the values in priority order.