Interface RefreshStrategy

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface RefreshStrategy
Decides what to do with a typeahead input value. Given the previous and current input values, returns a Decision telling the controller whether to re-query the server, debounce, or filter locally.

Use one of the static convenience factories for common patterns, or implement the interface directly for custom value-driven logic:

For value-driven strategy switching:

refreshOn((prev, curr) -> curr.startsWith("/")
    ? Decision.debounce(300)
    : myPredicate.test(prev, curr)
        ? Decision.refresh()
        : Decision.filter());
  • Method Summary

    Modifier and Type
    Method
    Description
    default String
    composeSelection(String currentValue, String itemText)
    Composes the new input value when a menu item is selected.
    evaluate(String previousValue, String currentValue)
    Evaluates the input transition and returns the appropriate Decision.
    everyInput(int debounceMs)
    Creates a strategy that debounces every input change by the given timeout.
    structuralChange(int minLength, char delimiter)
    Convenience factory for a common structural-change pattern: refresh when the input first reaches minLength characters, and again whenever the number of delimiter characters changes.
    Creates a strategy that refreshes items when the predicate detects a structural change between the previous and current input values.
  • Method Details

    • evaluate

      Decision evaluate(String previousValue, String currentValue)
      Evaluates the input transition and returns the appropriate Decision.
      Parameters:
      previousValue - the input value before the change
      currentValue - the input value after the change
      Returns:
      the decision for how to handle the current input
    • composeSelection

      default String composeSelection(String currentValue, String itemText)
      Composes the new input value when a menu item is selected. The default implementation returns the item text as-is. Strategies that understand hierarchical input (e.g., delimiter-based) override this to preserve the prefix.
      Parameters:
      currentValue - the current input value at the time of selection
      itemText - the text of the selected menu item
      Returns:
      the composed value to set in the input field
    • everyInput

      static RefreshStrategy everyInput(int debounceMs)
      Creates a strategy that debounces every input change by the given timeout. The server is responsible for filtering — no client-side filter is applied.
      Parameters:
      debounceMs - the debounce timeout in milliseconds; must be > 0
    • structuralChange

      static RefreshStrategy structuralChange(BiPredicate<String,String> predicate)
      Creates a strategy that refreshes items when the predicate detects a structural change between the previous and current input values. Between refreshes, items are filtered locally using the configured filter.
      Parameters:
      predicate - receives (previousValue, currentValue), returns true to trigger a refresh
    • structuralChange

      static RefreshStrategy structuralChange(int minLength, char delimiter)
      Convenience factory for a common structural-change pattern: refresh when the input first reaches minLength characters, and again whenever the number of delimiter characters changes. Between refreshes, items are filtered locally using the configured filter.

      The returned strategy also overrides composeSelection(String, String) to preserve the prefix up to and including the last delimiter when a menu item is selected.

      Parameters:
      minLength - refresh when input length first reaches or exceeds this threshold (previous < minLength, current >= minLength); deleting text back below the threshold does not trigger a refresh
      delimiter - refresh when the count of this character changes between previous and current input