Class ToMapListener<K,V>

Type Parameters:
K - the key type
V - the value type
All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable, NotificationQueue.Dependency, LivenessManager, LivenessNode, LivenessReferent, ListenerBase, ShiftAwareListener, Serializable, Map<K,V>

public class ToMapListener<K,V> extends InstrumentedShiftAwareListenerAdapter implements Map<K,V>
Listens to a table, mapping keys to values. When you call get, we return the value as of the start of this clock cycle.
See Also:
  • Method Details

    • make

      public static ToMapListener make(DynamicTable source, String keySourceName)
    • make

      public static ToMapListener make(DynamicTable source, String keySourceName, String valueSourceName)
    • make

      public static <K1, V1> ToMapListener<K1,V1> make(DynamicTable source, ColumnSource<K1> keySource, ColumnSource<V1> valueSource)
    • make

      public static <K1, V1> ToMapListener<K1,V1> make(DynamicTable source, LongFunction<K1> keyProducer, LongFunction<K1> prevKeyProducer, LongFunction<V1> valueProducer, LongFunction<V1> prevValueProducer)
    • onUpdate

      public void onUpdate(ShiftAwareListener.Update upstream)
      Description copied from interface: ShiftAwareListener
      Process notification of table changes.

      The Listener onUpdate call executes within the LiveTableMonitor refresh loop. Any tables used within the listener's onUpdate call must have already been refreshed. Using the typical pattern of a Listener that is listening to a single table, with DynamicTable.listenForUpdates(Listener), this is trivially true.

      When the listener must reference more than just one parent, the tables (or other objects) it references, must be made a NotificationQueue.Dependency of the listener. For listeners that reference multiple ticking tables, a common pattern is to use a MergedListener and collection of ListenerRecorders.

      Specified by:
      onUpdate in interface ShiftAwareListener
      Specified by:
      onUpdate in class InstrumentedShiftAwareListenerAdapter
      Parameters:
      upstream - The set of upstream table updates.
    • size

      public int size()
      Specified by:
      size in interface Map<K,V>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<K,V>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<K,V>
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<K,V>
    • get

      public V get(Object key)
      Specified by:
      get in interface Map<K,V>
    • get

      public <T> T get(K key, groovy.lang.Closure<T> valueProducer, groovy.lang.Closure<T> prevValueProducer)
    • get

      public <T> T get(K key, ColumnSource<T> cs)
    • get

      public <T> T get(K key, LongFunction<T> valueProducer, LongFunction<T> prevValueProducer)
      Get but instead of applying the default value producer, use a custom value producer. The intention is that you can wrap the map up with several different value producers, e.g. one for bid and another for ask.
      Type Parameters:
      T - the type of the value we are retrieving
      Parameters:
      key - the key to retrieve
      valueProducer - retrieve the current value out of the table
      prevValueProducer - retrieve the previous value out of the table
      Returns:
      the value associated with key
    • put

      @Nullable public V put(K key, V value)
      Specified by:
      put in interface Map<K,V>
    • remove

      public V remove(Object key)
      Specified by:
      remove in interface Map<K,V>
    • putAll

      public void putAll(@NotNull Map<? extends K,? extends V> m)
      Specified by:
      putAll in interface Map<K,V>
    • clear

      public void clear()
      Specified by:
      clear in interface Map<K,V>
    • keySet

      @NotNull public Set<K> keySet()
      Specified by:
      keySet in interface Map<K,V>
    • values

      @NotNull public Collection<V> values()
      Specified by:
      values in interface Map<K,V>
    • entrySet

      @NotNull public Set<Map.Entry<K,V>> entrySet()
      Specified by:
      entrySet in interface Map<K,V>