Skip to content

add missingLookupHandler in InterpolatorStringLookup #673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Allan-QLB
Copy link

Add a missingLookupHandler in InterpolatorStringLookup.
When resolving a variable with prefix,the InterpolatorStringLookup finds corresponding lookup by prefix in stringLookupMap,when there is no corresponding lookup for the prefix, the missingLookupHandler is used to determine whether to use default lookup. If the missingLookupHandler is null or returns true, the default lookup will be used to resolve the variable.

This allows user to control the behavior in such case. For example user can chose using default lookup as before, return null, or throw an exception.

@garydgregory
Copy link
Member

This doesn't make sense to me. You can provide a custom default StringLookup instead of adding the complexity of an additional layer of processing.

@Allan-QLB
Copy link
Author

This doesn't make sense to me. You can provide a custom default StringLookup instead of adding the complexity of an additional layer of processing.

There were 2 cases that would fallback to default lookup when resolving variable with a specified prefix, 1) there is no lookup for the prefix. 2)there is a lookup for the prefix but it cannot resolve this variable. This pr allows deal with the 2 cases differently. It is hard to distinguish the 2 cases in default lookup because the prefix is removed before calling default lookup.

# Conflicts:
#	src/main/java/org/apache/commons/text/lookup/InterpolatorStringLookup.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants