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 Summary
Modifier and TypeMethodDescriptionchain
(Collection<? extends Function<String, String>> functions) Creates a composite function from a collection of functions.default String
interpolate
(String val, Function<String, String> callback) Interpolates a single string value using the provided callback function.default String
interpolate
(String val, Function<String, String> callback, boolean defaultsToEmpty) Interpolates a single string value using the provided callback function.interpolate
(String val, Function<String, String> callback, BiFunction<String, String, String> postprocessor, boolean defaultsToEmpty) Interpolates a single string value using the provided callback function.default void
Interpolates the values in the given map using the provided callback function.default void
Interpolates the values in the given map using the provided callback function.void
interpolate
(Map<String, String> map, Function<String, String> callback, BiFunction<String, String, String> postprocessor, boolean defaultsToEmpty) Interpolates the values in the given map using the provided callback function.Memoizes a given function that takes a String input and produces a String output.
-
Method Details
-
interpolate
default void interpolate(@Nonnull Map<String, String> properties, @Nullable Function<String, 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.
-
interpolate
default void interpolate(@Nonnull Map<String, String> map, @Nullable Function<String, 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.
-
interpolate
void interpolate(@Nonnull Map<String, String> map, @Nullable Function<String, String> callback, @Nullable BiFunction<String, String, 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 Function<String, 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 Function<String, 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 Function<String, String> callback, @Nullable BiFunction<String, String, 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.
-
chain
Creates 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
-
memoize
Memoizes 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
Function<String, 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:
-