Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/910#discussion_r40001330
  
    --- Diff: 
core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java 
---
    @@ -483,6 +483,114 @@ public T apply(@Nullable U input) {
                 taskArgs);
         }
     
    +    public static Task<String> regexReplacement(Object source, Object 
pattern, Object replacement) {
    +        List<TaskAdaptable<Object>> taskArgs = getTaskAdaptable(source, 
pattern, replacement);
    +        Function<List<Object>, String> transformer = new 
RegexTransformerString(source, pattern, replacement);
    +        return transformMultiple(
    +                MutableMap.of("displayName", String.format("creating regex 
replacement function (%s:%s)", pattern, replacement)),
    +                transformer,
    +                taskArgs
    +        );
    +    }
    +
    +    public static Task<Function<String, String>> regexReplacement(Object 
pattern, Object replacement) {
    +        List<TaskAdaptable<Object>> taskArgs = getTaskAdaptable(pattern, 
replacement);
    +        Function<List<Object>, Function<String, String>> transformer = new 
RegexTransformerFunction(pattern, replacement);
    +        return transformMultiple(
    +                MutableMap.of("displayName", String.format("creating regex 
replacement function (%s:%s)", pattern, replacement)),
    +                transformer,
    +                taskArgs
    +        );
    +    }
    +
    +    private static List<TaskAdaptable<Object>> getTaskAdaptable(Object... 
args){
    +        List<TaskAdaptable<Object>> taskArgs = Lists.newArrayList();
    +        for (Object arg: args) {
    +            if (arg instanceof TaskAdaptable) {
    +                taskArgs.add((TaskAdaptable<Object>)arg);
    +            } else if (arg instanceof TaskFactory) {
    +                
taskArgs.add(((TaskFactory<TaskAdaptable<Object>>)arg).newTask());
    +            }
    +        }
    +        return taskArgs;
    +    }
    +
    +    public static class RegexTransformerString implements 
Function<List<Object>, String> {
    +
    +        private final Object source;
    +        private final Object pattern;
    +        private final Object replacement;
    +
    +        public RegexTransformerString(Object source, Object pattern, 
Object replacement){
    +            this.source = source;
    +            this.pattern = pattern;
    +            this.replacement = replacement;
    +        }
    +
    +        @Nullable
    +        @Override
    +        public String apply(@Nullable List<Object> input) {
    +            Iterator<?> taskArgsIterator = input.iterator();
    +            String resolvedSource = resolveArgument(source, 
taskArgsIterator);
    +            String resolvedPattern = resolveArgument(pattern, 
taskArgsIterator);
    +            String resolvedReplacement = resolveArgument(replacement, 
taskArgsIterator);
    +            return new RegexReplacer(resolvedPattern, 
resolvedReplacement).apply(resolvedSource);
    +        }
    +    }
    +
    +    public static class RegexTransformerFunction implements 
Function<List<Object>, Function<String, String>> {
    --- End diff --
    
    feels a bit convoluted but okay with me if you think this is the right way. 
 maybe mark `@Beta` ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to