Package net.solarnetwork.node.service
Interface PlaceholderService
- All Known Implementing Classes:
SettingsPlaceholderService
public interface PlaceholderService
API for a service that can resolve "placeholder" variables in strings.
- Since:
- 1.76
- Version:
- 2.1
- Author:
- matt
-
Method Summary
Modifier and TypeMethodDescriptiondefault <T> voidcopyPlaceholders(Map<String, T> destination) Copy all placeholders to a map.<T> voidCopy placeholders to a map.default <T> voidcopyPlaceholders(Map<String, T> destination, Pattern keyFilter) Copy placeholders to a map.static <T> voidcopyPlaceholders(net.solarnetwork.service.OptionalService<PlaceholderService> service, Map<String, T> destination) Helper to copy plaeholders to a map.static <T> voidcopyPlaceholders(net.solarnetwork.service.OptionalService<PlaceholderService> service, Map<String, T> destination, Predicate<Map.Entry<String, T>> filter) Helper to copy plaeholders to a map.static <T> voidcopyPlaceholders(net.solarnetwork.service.OptionalService<PlaceholderService> service, Map<String, T> destination, Pattern keyFilter) Helper to copy plaeholders to a map.<T> voidmapPlaceholders(Map<String, T> destination, Function<Stream<Map.Entry<String, ?>>, Stream<Map.Entry<String, T>>> filter) Copy placeholders to a map using a stream filter.static <T> voidmapPlaceholders(net.solarnetwork.service.OptionalService<PlaceholderService> service, Map<String, T> destination, Function<Stream<Map.Entry<String, ?>>, Stream<Map.Entry<String, T>>> filter) Helper to copy plaeholders to a map.voidregisterParameters(Map<String, ?> parameters) Register a set of parameters for future use.resolvePlaceholders(String s, Map<String, ?> parameters) Resolve all placeholders.static StringresolvePlaceholders(net.solarnetwork.service.OptionalService<PlaceholderService> service, String s, Map<String, ?> parameters) Helper to resolve placeholders from an optionalPlaceholderService.default voidsmartCopyPlaceholders(Map<String, Object> destination) Copy all placeholders to a destination map, converting obvious number string values into actual number instances.default voidCopy placeholders to a destination map, converting obvious number string values into actual number instances.default voidsmartCopyPlaceholders(Map<String, Object> destination, Pattern keyFilter) Copy placeholders to a destination map, converting obvious number string values into actual number instances.static voidsmartCopyPlaceholders(net.solarnetwork.service.OptionalService<PlaceholderService> service, Map<String, Object> destination) Copy placeholders to a destination map, converting obvious number string values into actual number instances.static voidsmartCopyPlaceholders(net.solarnetwork.service.OptionalService<PlaceholderService> service, Map<String, Object> destination, Predicate<Map.Entry<String, ?>> filter) Copy placeholders to a destination map, converting obvious number string values into actual number instances.static voidsmartCopyPlaceholders(net.solarnetwork.service.OptionalService<PlaceholderService> service, Map<String, Object> destination, Pattern keyFilter) Copy placeholders to a destination map, converting obvious number string values into actual number instances.
-
Method Details
-
resolvePlaceholders
Resolve all placeholders.- Parameters:
s- the string to resolve placeholders inparameters- parameters to use while resolving placeholders, or null- Returns:
- the resolved string, or null if
sis null
-
registerParameters
Register a set of parameters for future use.- Parameters:
parameters- the parameters to register
-
copyPlaceholders
Copy all placeholders to a map.- Type Parameters:
T- the parameters value type; typicallyStringorObject- Parameters:
destination- the map to copy all placeholders to- Since:
- 2.1
-
copyPlaceholders
Copy placeholders to a map.- Type Parameters:
T- the parameters value type; typicallyStringorObject- Parameters:
destination- the map to copy all placeholders tofilter- an optional filter to restrict copying matching placeholders intodestination- Since:
- 2.1
-
copyPlaceholders
Copy placeholders to a map.- Type Parameters:
T- the parameters value type; typicallyStringorObject- Parameters:
destination- the map to copy all placeholders tokeyFilter- an optional pattern to match against placeholder keys to restrict copying matches intodestination; theMatcher.find()method is used so the pattern matches anywhere within the key values- Since:
- 2.1
-
smartCopyPlaceholders
Copy all placeholders to a destination map, converting obvious number string values into actual number instances.- Parameters:
destination- the map to copy all placeholders to- Since:
- 2.1
- See Also:
-
smartCopyPlaceholders
Copy placeholders to a destination map, converting obvious number string values into actual number instances.- Parameters:
destination- the map to copy all placeholders tokeyFilter- an optional pattern to match against placeholder keys to restrict copying matches intodestination; theMatcher.find()method is used so the pattern matches anywhere within the key values- Since:
- 2.1
- See Also:
-
smartCopyPlaceholders
default void smartCopyPlaceholders(Map<String, Object> destination, Predicate<Map.Entry<String, ?>> filter) Copy placeholders to a destination map, converting obvious number string values into actual number instances.Each placeholder value is examined:
- if it is a
Numberinstance it is copied as-is - if its string value looks like a valid integer or decimal number, it
is copied as a new
BigIntegerorBigDecimalinstance
- Parameters:
destination- the map to copy all placeholders tofilter- an optional filter to restrict copying matching placeholders intodestination- Since:
- 2.1
- if it is a
-
mapPlaceholders
<T> void mapPlaceholders(Map<String, T> destination, Function<Stream<Map.Entry<String, ?>>, Stream<Map.Entry<String, T>>> filter) Copy placeholders to a map using a stream filter.This method allows you the most flexibility in copying placeholders to a map. The
filteris a function that is passed a stream of placeholder entries and can then filter and/or map that stream to a new stream, whose output entries will be copied todestination. For example, you could copy specific placeholders converted to integer values:mapPlaceholders(params, s -> { return s.filter(e -> { return e.getKey().startsWith("max"); }).map(e -> { return new SimpleEntry<>(e.getKey(), Integer.valueOf(e.getValue().toString())); }); });- Type Parameters:
T- the parameters value type; typicallyStringorObject- Parameters:
destination- the map to copy all placeholders tofilter- an optional filter to restrict copying matching placeholders intodestination; the function takes a stream of placeholder entries as input and returns a stream of desired output entries to add todestination
-
resolvePlaceholders
static String resolvePlaceholders(net.solarnetwork.service.OptionalService<PlaceholderService> service, String s, Map<String, ?> parameters) Helper to resolve placeholders from an optionalPlaceholderService.- Parameters:
service- the optional services- the string to resolve placeholdersparameters- to use while resolving placeholders, or null- Returns:
- the resolved string, or null if
sis null
-
copyPlaceholders
static <T> void copyPlaceholders(net.solarnetwork.service.OptionalService<PlaceholderService> service, Map<String, T> destination) Helper to copy plaeholders to a map.- Type Parameters:
T- the parameters value type; typicallyStringorObject- Parameters:
service- the optional servicedestination- the map to copy all placeholders to- Since:
- 2.1
-
copyPlaceholders
static <T> void copyPlaceholders(net.solarnetwork.service.OptionalService<PlaceholderService> service, Map<String, T> destination, Predicate<Map.Entry<String, T>> filter) Helper to copy plaeholders to a map.- Type Parameters:
T- the parameters value type; typicallyStringorObject- Parameters:
service- the optional servicedestination- the map to copy all placeholders tofilter- an optional filter to restrict copying matching placeholders intodestination- Since:
- 2.1
-
copyPlaceholders
static <T> void copyPlaceholders(net.solarnetwork.service.OptionalService<PlaceholderService> service, Map<String, T> destination, Pattern keyFilter) Helper to copy plaeholders to a map.- Type Parameters:
T- the parameters value type; typicallyStringorObject- Parameters:
service- the optional servicedestination- the map to copy all placeholders tokeyFilter- an optional pattern to match against placeholder keys to restrict copying matches intodestination; theMatcher.find()method is used so the pattern matches anywhere within the key values- Since:
- 2.1
-
mapPlaceholders
static <T> void mapPlaceholders(net.solarnetwork.service.OptionalService<PlaceholderService> service, Map<String, T> destination, Function<Stream<Map.Entry<String, ?>>, Stream<Map.Entry<String, T>>> filter) Helper to copy plaeholders to a map.- Type Parameters:
T- the parameters value type; typicallyStringorObject- Parameters:
service- the optional servicedestination- the map to copy all placeholders tofilter- an optional filter to restrict copying matching placeholders intodestination; the function takes a stream of placeholder entries as input and returns a stream of desired output entries to add todestination- Since:
- 2.1
-
smartCopyPlaceholders
static void smartCopyPlaceholders(net.solarnetwork.service.OptionalService<PlaceholderService> service, Map<String, Object> destination) Copy placeholders to a destination map, converting obvious number string values into actual number instances.- Parameters:
service- the optional servicedestination- the map to copy all placeholders to- Since:
- 2.1
- See Also:
-
smartCopyPlaceholders
static void smartCopyPlaceholders(net.solarnetwork.service.OptionalService<PlaceholderService> service, Map<String, Object> destination, Pattern keyFilter) Copy placeholders to a destination map, converting obvious number string values into actual number instances.- Parameters:
service- the optional servicedestination- the map to copy all placeholders tokeyFilter- an optional pattern to match against placeholder keys to restrict copying matches intodestination; theMatcher.find()method is used so the pattern matches anywhere within the key values- Since:
- 2.1
- See Also:
-
smartCopyPlaceholders
static void smartCopyPlaceholders(net.solarnetwork.service.OptionalService<PlaceholderService> service, Map<String, Object> destination, Predicate<Map.Entry<String, ?>> filter) Copy placeholders to a destination map, converting obvious number string values into actual number instances.Each placeholder value is examined:
- if it is a
Numberinstance it is copied as-is - if its string value looks like a valid integer or decimal number, it
is copied as a new
BigIntegerorBigDecimalinstance
- Parameters:
service- the optional servicedestination- the map to copy all placeholders tofilter- an optional filter to restrict copying matching placeholders intodestination- Since:
- 2.1
- See Also:
- if it is a
-