Class ReverseLookupListener

All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable, NotificationQueue.Dependency, LivenessManager, LivenessNode, LivenessReferent, DynamicNode, NotificationStepSource, ReverseLookup, Serializable

public class ReverseLookupListener extends LivenessArtifact implements ReverseLookup, DynamicNode, NotificationStepSource
Maintains a map from key column values to their index. This allows you to quickly find a row based on a unique key on a ticking table, without the need for searching the entire table. Note: The key column values must be unique.
See Also:
  • Method Details

    • makeReverseLookupListenerWithSnapshot

      public static ReverseLookupListener makeReverseLookupListenerWithSnapshot(BaseTable source, String... columns)
    • makeReverseLookupListenerWithLock

      public static ReverseLookupListener makeReverseLookupListenerWithLock(DynamicTable source, String... columns)
    • prepareForTree

      @ScriptApi public static void prepareForTree(BaseTable preTree, String idColumn)
      Prepare the parameter table for use with tree table
      Parameters:
      preTree - The tree to prepare
      idColumn - The column that will be used as the id for Table.treeTable(String, String)
    • get

      public long get(Object key)
      Description copied from interface: ReverseLookup
      Gets the index value where key exists in the table, or the no-entry-value if it is not found in the table.
      Specified by:
      get in interface ReverseLookup
      Parameters:
      key - a single object for a single column, or a SmartKey for multiple columns
      Returns:
      the row index where key exists in the table
    • getPrev

      public long getPrev(Object key)
      Description copied from interface: ReverseLookup
      Gets the index value where key previously in the table, or the no-entry-value if it is was not found in the table.
      Specified by:
      getPrev in interface ReverseLookup
      Parameters:
      key - a single object for a single column, or a SmartKey for multiple columns
      Returns:
      the row index where key previously existed in the table
    • getNoEntryValue

      public long getNoEntryValue()
      Description copied from interface: ReverseLookup
      Returns the value that will be returned from ReverseLookup.get(java.lang.Object) or if no entry exists for a given key.
      Specified by:
      getNoEntryValue in interface ReverseLookup
    • getKey

      protected Object getKey(long row)
      Gets the key for a given row.
      Parameters:
      row - the index value to retrieve the key for
      Returns:
      an individual object or SmartKey for multi-column keys
    • toString

      public String toString()
      Overrides:
      toString in class ReferenceCounted
    • getKeyColumns

      public String[] getKeyColumns()
      Specified by:
      getKeyColumns in interface ReverseLookup
      Returns:
      the key columns this reverse lookup is indexed on
    • getLastNotificationStep

      public long getLastNotificationStep()
      Description copied from interface: NotificationStepSource
      Get the last logical clock step on which this element dispatched a notification.
      Specified by:
      getLastNotificationStep in interface NotificationStepSource
      Returns:
      The last notification step
    • satisfied

      public boolean satisfied(long step)
      Description copied from interface: NotificationQueue.Dependency
      Is this ancestor satisfied? Note that this method must be safe to call on any thread.
      Specified by:
      satisfied in interface NotificationQueue.Dependency
      Parameters:
      step - The step for which we are testing satisfaction
      Returns:
      Whether the dependency is satisfied on step (and will not fire subsequent notifications)
    • isRefreshing

      public boolean isRefreshing()
      Description copied from interface: DynamicNode
      Is the node updating?
      Specified by:
      isRefreshing in interface DynamicNode
      Returns:
      true if the node is updating; false otherwise.
    • setRefreshing

      public boolean setRefreshing(boolean refreshing)
      Description copied from interface: DynamicNode
      Change the node's refresh mode.
      Specified by:
      setRefreshing in interface DynamicNode
      Parameters:
      refreshing - true to cause the node to update; false otherwise.
      Returns:
      new refreshing state
    • addParentReference

      public void addParentReference(Object parent)
      Description copied from interface: DynamicNode
      Called on a dependent node to ensure that a strong reference is maintained to any parent object that is required for the proper maintenance and functioning of the dependent. In the most common case, the parent object is a child listener to a parent node. The parent node only keeps a weak reference to its child listener, but the listener maintains a strong reference to the parent node. In this scenario, the only strong reference to the listener (and thus indirectly to the parent node itself) is the reference kept by the dependent node.
      Specified by:
      addParentReference in interface DynamicNode
      Parameters:
      parent - A parent of this node