Package org.apache.maven.api.services
Interface Interpolator
- All Superinterfaces:
- Service
- All Known Implementing Classes:
- DefaultInterpolator
The Interpolator service provides methods for variable substitution in strings and maps.
 It allows for the replacement of placeholders (e.g., ${variable}) with their corresponding values.
- Since:
- 4.0.0
- 
Method SummaryModifier and TypeMethodDescriptionstatic UnaryOperator<String>chain(Collection<? extends UnaryOperator<String>> functions) Creates a composite function from a collection of functions.static UnaryOperator<String>chain(UnaryOperator<String>... functions) default Stringinterpolate(String val, UnaryOperator<String> callback) Interpolates a single string value using the provided callback function.default Stringinterpolate(String val, UnaryOperator<String> callback, boolean defaultsToEmpty) Interpolates a single string value using the provided callback function.interpolate(String val, UnaryOperator<String> callback, BinaryOperator<String> postprocessor, boolean defaultsToEmpty) Interpolates a single string value using the provided callback function.default voidinterpolate(Map<String, String> properties, UnaryOperator<String> callback) Interpolates the values in the given map using the provided callback function.default voidinterpolate(Map<String, String> map, UnaryOperator<String> callback, boolean defaultsToEmpty) Interpolates the values in the given map using the provided callback function.voidinterpolate(Map<String, String> map, UnaryOperator<String> callback, BinaryOperator<String> postprocessor, boolean defaultsToEmpty) Interpolates the values in the given map using the provided callback function.static UnaryOperator<String>memoize(UnaryOperator<String> callback) Memoizes a given function that takes a String input and produces a String output.
- 
Method Details- 
interpolatedefault void interpolate(@Nonnull Map<String, String> properties, @Nullable UnaryOperator<String> callback) Interpolates the values in the given map using the provided callback function. This method defaults to setting empty strings for unresolved placeholders.- Parameters:
- properties- The map containing key-value pairs to be interpolated.
- callback- The function to resolve variable values not found in the map.
 
- 
interpolatedefault void interpolate(@Nonnull Map<String, String> map, @Nullable UnaryOperator<String> callback, boolean defaultsToEmpty) Interpolates the values in the given map using the provided callback function.- Parameters:
- map- The map containing key-value pairs to be interpolated.
- callback- The function to resolve variable values not found in the map.
- defaultsToEmpty- If true, unresolved placeholders are replaced with empty strings. If false, they are left unchanged.
 
- 
interpolatevoid interpolate(@Nonnull Map<String, String> map, @Nullable UnaryOperator<String> callback, @Nullable BinaryOperator<String> postprocessor, boolean defaultsToEmpty) Interpolates the values in the given map using the provided callback function.- Parameters:
- map- The map containing key-value pairs to be interpolated.
- callback- The function to resolve variable values not found in the map.
- defaultsToEmpty- If true, unresolved placeholders are replaced with empty strings. If false, they are left unchanged.
 
- 
interpolate@Nullable default String interpolate(@Nullable String val, @Nullable UnaryOperator<String> callback) Interpolates a single string value using the provided callback function. This method defaults to not replacing unresolved placeholders.- Parameters:
- val- The string to be interpolated.
- callback- The function to resolve variable values.
- Returns:
- The interpolated string, or null if the input was null.
 
- 
interpolate@Nullable default String interpolate(@Nullable String val, @Nullable UnaryOperator<String> callback, boolean defaultsToEmpty) Interpolates a single string value using the provided callback function.- Parameters:
- val- The string to be interpolated.
- callback- The function to resolve variable values.
- defaultsToEmpty- If true, unresolved placeholders are replaced with empty strings.
- Returns:
- The interpolated string, or null if the input was null.
 
- 
interpolate@Nullable String interpolate(@Nullable String val, @Nullable UnaryOperator<String> callback, @Nullable BinaryOperator<String> postprocessor, boolean defaultsToEmpty) Interpolates a single string value using the provided callback function.- Parameters:
- val- The string to be interpolated.
- callback- The function to resolve variable values.
- defaultsToEmpty- If true, unresolved placeholders are replaced with empty strings.
- Returns:
- The interpolated string, or null if the input was null.
 
- 
chainCreates a composite function from a collection of functions.- Parameters:
- functions- A collection of functions, each taking a String as input and returning a String.
- Returns:
- A function that applies each function in the collection in order until a non-null result is found. If all functions return null, the composite function returns null.
- Throws:
- NullPointerException- if the input collection is null or contains null elements.
 
- 
chain
- 
memoizeMemoizes a given function that takes a String input and produces a String output. This method creates a new function that caches the results of the original function, improving performance for repeated calls with the same input.- Parameters:
- callback- The original function to be memoized. It takes a String as input and returns a String.
- Returns:
- A new UnaryOperator<String>that caches the results of the original function. If the original function returns null for a given input, null will be cached and returned for subsequent calls with the same input.
- See Also:
 
 
-