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 Details

    • resolvePlaceholders

      String resolvePlaceholders(String s, Map<String,?> parameters)
      Resolve all placeholders.
      Parameters:
      s - the string to resolve placeholders in
      parameters - parameters to use while resolving placeholders, or null
      Returns:
      the resolved string, or null if s is null
    • registerParameters

      void registerParameters(Map<String,?> parameters)
      Register a set of parameters for future use.
      Parameters:
      parameters - the parameters to register
    • copyPlaceholders

      default <T> void copyPlaceholders(Map<String,T> destination)
      Copy all placeholders to a map.
      Type Parameters:
      T - the parameters value type; typically String or Object
      Parameters:
      destination - the map to copy all placeholders to
      Since:
      2.1
    • copyPlaceholders

      <T> void copyPlaceholders(Map<String,T> destination, Predicate<Map.Entry<String,T>> filter)
      Copy placeholders to a map.
      Type Parameters:
      T - the parameters value type; typically String or Object
      Parameters:
      destination - the map to copy all placeholders to
      filter - an optional filter to restrict copying matching placeholders into destination
      Since:
      2.1
    • copyPlaceholders

      default <T> void copyPlaceholders(Map<String,T> destination, Pattern keyFilter)
      Copy placeholders to a map.
      Type Parameters:
      T - the parameters value type; typically String or Object
      Parameters:
      destination - the map to copy all placeholders to
      keyFilter - an optional pattern to match against placeholder keys to restrict copying matches into destination; the Matcher.find() method is used so the pattern matches anywhere within the key values
      Since:
      2.1
    • smartCopyPlaceholders

      default void smartCopyPlaceholders(Map<String,Object> destination)
      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

      default void smartCopyPlaceholders(Map<String,Object> destination, Pattern keyFilter)
      Copy placeholders to a destination map, converting obvious number string values into actual number instances.
      Parameters:
      destination - the map to copy all placeholders to
      keyFilter - an optional pattern to match against placeholder keys to restrict copying matches into destination; the Matcher.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:

      1. if it is a Number instance it is copied as-is
      2. if its string value looks like a valid integer or decimal number, it is copied as a new BigInteger or BigDecimal instance
      Parameters:
      destination - the map to copy all placeholders to
      filter - an optional filter to restrict copying matching placeholders into destination
      Since:
      2.1
    • 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 filter is 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 to destination. 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; typically String or Object
      Parameters:
      destination - the map to copy all placeholders to
      filter - an optional filter to restrict copying matching placeholders into destination; the function takes a stream of placeholder entries as input and returns a stream of desired output entries to add to destination
    • resolvePlaceholders

      static String resolvePlaceholders(net.solarnetwork.service.OptionalService<PlaceholderService> service, String s, Map<String,?> parameters)
      Helper to resolve placeholders from an optional PlaceholderService.
      Parameters:
      service - the optional service
      s - the string to resolve placeholders
      parameters - to use while resolving placeholders, or null
      Returns:
      the resolved string, or null if s is 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; typically String or Object
      Parameters:
      service - the optional service
      destination - 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; typically String or Object
      Parameters:
      service - the optional service
      destination - the map to copy all placeholders to
      filter - an optional filter to restrict copying matching placeholders into destination
      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; typically String or Object
      Parameters:
      service - the optional service
      destination - the map to copy all placeholders to
      keyFilter - an optional pattern to match against placeholder keys to restrict copying matches into destination; the Matcher.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; typically String or Object
      Parameters:
      service - the optional service
      destination - the map to copy all placeholders to
      filter - an optional filter to restrict copying matching placeholders into destination; the function takes a stream of placeholder entries as input and returns a stream of desired output entries to add to destination
      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 service
      destination - 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 service
      destination - the map to copy all placeholders to
      keyFilter - an optional pattern to match against placeholder keys to restrict copying matches into destination; the Matcher.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:

      1. if it is a Number instance it is copied as-is
      2. if its string value looks like a valid integer or decimal number, it is copied as a new BigInteger or BigDecimal instance
      Parameters:
      service - the optional service
      destination - the map to copy all placeholders to
      filter - an optional filter to restrict copying matching placeholders into destination
      Since:
      2.1
      See Also: