Class ValueVenue<K,V>

java.lang.Object
io.github.projectunified.valuevenue.core.ValueVenue<K,V>
Type Parameters:
K - type of the key
V - type of the generated value

public class ValueVenue<K,V> extends Object
Holds the values generated for each key.

Values are computed only when update(Object) is called for a key; get(Object) never generates anything and returns an empty list until the key has been updated at least once.

Instances are safe for concurrent use; readers see either the values stored before or after an update(Object) call, never a partially generated list.

  • Constructor Details

    • ValueVenue

      public ValueVenue(Function<K,List<V>> valueGenerator)
      Creates a venue whose keys are updated through update(Object).
      Parameters:
      valueGenerator - generator invoked by update(Object) to compute the values of a key
  • Method Details

    • get

      public List<V> get(K key)
      Returns the values stored for the key by the last update(Object) call.
      Parameters:
      key - key to look up
      Returns:
      read-only list of the stored values, empty if the key was never updated
    • update

      public void update(K key)
      Generates the values of the key and stores them, replacing any previous values.
      Parameters:
      key - key to regenerate