brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [4/6] incubator-brooklyn git commit: Moves RegexReplacer into StringFunctions
Date Wed, 28 Oct 2015 12:05:19 GMT
Moves RegexReplacer into StringFunctions


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/6fbdd7f3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/6fbdd7f3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/6fbdd7f3

Branch: refs/heads/master
Commit: 6fbdd7f3aa67814d32abec5ac3b5df893fa4bf6a
Parents: a96cb55
Author: Martin Harris <github@nakomis.com>
Authored: Mon Oct 12 14:33:07 2015 +0100
Committer: Martin Harris <github@nakomis.com>
Committed: Thu Oct 15 15:42:16 2015 +0100

----------------------------------------------------------------------
 .../core/sensor/DependentConfiguration.java     | 24 ++++-----------
 .../brooklyn/enricher/stock/Transformer.java    |  2 ++
 .../camp/brooklyn/DslAndRebindYamlTest.java     |  2 +-
 .../brooklyn/util/text/StringFunctions.java     | 31 +++++++++++++++-----
 4 files changed, 32 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6fbdd7f3/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
b/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
index 1229990..6c251a7 100644
--- a/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
+++ b/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
@@ -68,6 +68,7 @@ import org.apache.brooklyn.util.exceptions.RuntimeTimeoutException;
 import org.apache.brooklyn.util.groovy.GroovyJavaMethods;
 import org.apache.brooklyn.util.guava.Functionals;
 import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.text.StringFunctions;
 import org.apache.brooklyn.util.text.Strings;
 import org.apache.brooklyn.util.time.CountdownTimer;
 import org.apache.brooklyn.util.time.Duration;
@@ -534,10 +535,11 @@ public class DependentConfiguration {
             String resolvedSource = resolveArgument(source, taskArgsIterator);
             String resolvedPattern = resolveArgument(pattern, taskArgsIterator);
             String resolvedReplacement = resolveArgument(replacement, taskArgsIterator);
-            return new RegexReplacer(resolvedPattern, resolvedReplacement).apply(resolvedSource);
+            return new StringFunctions.RegexReplacer(resolvedPattern, resolvedReplacement).apply(resolvedSource);
         }
     }
 
+    @Beta
     public static class RegexTransformerFunction implements Function<List<Object>,
Function<String, String>> {
 
         private final Object pattern;
@@ -551,7 +553,7 @@ public class DependentConfiguration {
         @Override
         public Function<String, String> apply(List<Object> input) {
             Iterator<?> taskArgsIterator = input.iterator();
-            return new RegexReplacer(resolveArgument(pattern, taskArgsIterator), resolveArgument(replacement,
taskArgsIterator));
+            return new StringFunctions.RegexReplacer(resolveArgument(pattern, taskArgsIterator),
resolveArgument(replacement, taskArgsIterator));
         }
 
     }
@@ -574,24 +576,8 @@ public class DependentConfiguration {
         return String.valueOf(resolvedArgument);
     }
 
-    public static class RegexReplacer implements Function<String, String> {
-
-        private final String pattern;
-        private final String replacement;
-
-        public RegexReplacer(String pattern, String replacement) {
-            this.pattern = pattern;
-            this.replacement = replacement;
-        }
-
-        @Nullable
-        @Override
-        public String apply(@Nullable String s) {
-            return Strings.replaceAllRegex(s, pattern, replacement);
-        }
-    }
 
-    /** returns a task for parallel execution returning a list of values for the given sensor
for the given entity list, 
+    /** returns a task for parallel execution returning a list of values for the given sensor
for the given entity list,
      * optionally when the values satisfy a given readiness predicate (defaulting to groovy
truth if not supplied) */
     public static <T> Task<List<T>> listAttributesWhenReady(AttributeSensor<T>
sensor, Iterable<Entity> entities) {
         return listAttributesWhenReady(sensor, entities, GroovyJavaMethods.truthPredicate());

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6fbdd7f3/core/src/main/java/org/apache/brooklyn/enricher/stock/Transformer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/enricher/stock/Transformer.java b/core/src/main/java/org/apache/brooklyn/enricher/stock/Transformer.java
index 997a12e..d6c4549 100644
--- a/core/src/main/java/org/apache/brooklyn/enricher/stock/Transformer.java
+++ b/core/src/main/java/org/apache/brooklyn/enricher/stock/Transformer.java
@@ -43,6 +43,8 @@ public class Transformer<T,U> extends AbstractTransformer<T,U>
{
     public static ConfigKey<?> TARGET_VALUE = ConfigKeys.newConfigKey(Object.class,
"enricher.targetValue");
     public static ConfigKey<Function<?, ?>> TRANSFORMATION_FROM_VALUE = ConfigKeys.newConfigKey(new
TypeToken<Function<?, ?>>() {}, "enricher.transformation");
     public static ConfigKey<Function<?, ?>> TRANSFORMATION_FROM_EVENT = ConfigKeys.newConfigKey(new
TypeToken<Function<?, ?>>() {}, "enricher.transformation.fromevent");
+
+    public Transformer() { }
     
     /** returns a function for transformation, for immediate use only (not for caching, as
it may change) */
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6fbdd7f3/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
index 1408d13..39b7ab5 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
@@ -245,7 +245,7 @@ public class DslAndRebindYamlTest extends AbstractYamlTest {
 
 
     /*
-           - type: org.apache.brooklyn.enricher.stock.Transformer
+        - type: org.apache.brooklyn.enricher.stock.Transformer
           brooklyn.config:
             enricher.sourceSensor: $brooklyn:sensor("mongodb.server.replicaSet.primary.endpoint")
             enricher.targetSensor: $brooklyn:sensor("justtheport")

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6fbdd7f3/utils/common/src/main/java/org/apache/brooklyn/util/text/StringFunctions.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/text/StringFunctions.java
b/utils/common/src/main/java/org/apache/brooklyn/util/text/StringFunctions.java
index dd9a980..ec2c023 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/text/StringFunctions.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/text/StringFunctions.java
@@ -383,16 +383,33 @@ public class StringFunctions {
     }
     
     protected static class ConvertCaseFunction implements Function<String, String>
{
-        private final CaseFormat src;
-        private final CaseFormat target;
+       private final CaseFormat src;
+       private final CaseFormat target;
 
-        public ConvertCaseFunction(CaseFormat src, CaseFormat target) {
-            this.src = src;
-            this.target = target;
+       public ConvertCaseFunction(CaseFormat src, CaseFormat target) {
+          this.src = src;
+          this.target = target;
+       }
+
+       @Override
+       public String apply(String input) {
+          return src.to(target, input);
+       }
+    }
+
+    public static class RegexReplacer implements Function<String, String> {
+        private final String pattern;
+        private final String replacement;
+
+        public RegexReplacer(String pattern, String replacement) {
+            this.pattern = pattern;
+            this.replacement = replacement;
         }
+
+        @Nullable
         @Override
-        public String apply(String input) {
-            return src.to(target, input);
+        public String apply(@Nullable String s) {
+            return Strings.replaceAllRegex(s, pattern, replacement);
         }
     }
 }


Mime
View raw message