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.
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:
everyInput(int)— debounce every input change; the server does the filteringstructuralChange(BiPredicate)— refresh when the predicate detects a structural change; filter locally between refreshesstructuralChange(int, char)— refresh on length threshold or delimiter count change
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 TypeMethodDescriptiondefault StringcomposeSelection(String currentValue, String itemText) Composes the new input value when a menu item is selected.Evaluates the input transition and returns the appropriateDecision.static RefreshStrategyeveryInput(int debounceMs) Creates a strategy that debounces every input change by the given timeout.static RefreshStrategystructuralChange(int minLength, char delimiter) Convenience factory for a common structural-change pattern: refresh when the input first reachesminLengthcharacters, and again whenever the number ofdelimitercharacters changes.static RefreshStrategystructuralChange(BiPredicate<String, String> predicate) Creates a strategy that refreshes items when the predicate detects a structural change between the previous and current input values.
-
Method Details
-
evaluate
-
composeSelection
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 selectionitemText- the text of the selected menu item- Returns:
- the composed value to set in the input field
-
everyInput
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
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), returnstrueto trigger a refresh
-
structuralChange
Convenience factory for a common structural-change pattern: refresh when the input first reachesminLengthcharacters, and again whenever the number ofdelimitercharacters 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 refreshdelimiter- refresh when the count of this character changes between previous and current input
-