Class PriorityMap<K extends Comparable<K>, V>

java.lang.Object
kr.toxicity.model.api.util.collection.PriorityMap<K,V>
Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values

public final class PriorityMap<K extends Comparable<K>, V> extends Object
A map that maintains the order of values based on priority, insertion order, and key comparison.
Since:
3.0.0
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    get(K key)
    Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
    boolean
    Returns true if this map contains no key-value mappings.
    put(K key, V value, int priority)
    Associates the specified value with the specified key and priority in this map.
    remove(K key)
    Removes the mapping for a key from this map if it is present.
    replace(K Key, @NotNull Function<V,V> function)
    Replaces the entry for the specified key only if it is currently mapped to some value.
    @NotNull Iterator<V>
    Returns an iterator over the values in this map in priority order.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PriorityMap

      public PriorityMap()
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Returns true if this map contains no key-value mappings.
      Returns:
      true if this map contains no key-value mappings
    • put

      @Nullable public V put(@NotNull K key, @NotNull V value, int priority)
      Associates the specified value with the specified key and priority in this map.
      Parameters:
      key - key with which the specified value is to be associated
      value - value to be associated with the specified key
      priority - priority of the entry
      Returns:
      the previous value associated with key, or null if there was no mapping for key.
    • get

      @Nullable public V get(@NotNull K key)
      Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped, or null if this map contains no mapping for the key
    • remove

      @Nullable public V remove(@NotNull K key)
      Removes the mapping for a key from this map if it is present.
      Parameters:
      key - key whose mapping is to be removed from the map
      Returns:
      the previous value associated with key, or null if there was no mapping for key.
    • replace

      @Nullable public V replace(@NotNull K Key, @NotNull @NotNull Function<V,V> function)
      Replaces the entry for the specified key only if it is currently mapped to some value.
      Parameters:
      Key - key with which the specified value is associated
      function - the function to compute a value
      Returns:
      the previous value associated with the specified key, or null if there was no mapping for the key.
    • valueIterator

      @NotNull public @NotNull Iterator<V> valueIterator()
      Returns an iterator over the values in this map in priority order.
      Returns:
      a value iterator
      Since:
      3.0.1