Deprecate BDC.Functions.RegexReplacer - duplicate of StringFunctions.RegexReplacer
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/498a58c0 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/498a58c0 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/498a58c0 Branch: refs/heads/master Commit: 498a58c05766374f2fa6484432122b766c1b3ef7 Parents: d71141e Author: Svetoslav Neykov <svetoslav.ney...@cloudsoftcorp.com> Authored: Mon Dec 12 16:38:31 2016 +0200 Committer: Svetoslav Neykov <svetoslav.ney...@cloudsoftcorp.com> Committed: Tue Dec 13 09:15:35 2016 +0200 ---------------------------------------------------------------------- .../spi/dsl/methods/BrooklynDslCommon.java | 19 ++++++------------- .../persist/deserializingClassRenames.properties | 3 +++ .../brooklyn/util/text/StringFunctions.java | 18 +++++++++++++++++- 3 files changed, 26 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/498a58c0/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java ---------------------------------------------------------------------- diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java index 1bf93d7..36b274c 100644 --- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java +++ b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java @@ -58,6 +58,7 @@ import org.apache.brooklyn.util.exceptions.Exceptions; import org.apache.brooklyn.util.guava.Maybe; import org.apache.brooklyn.util.javalang.Reflections; import org.apache.brooklyn.util.text.StringEscapes.JavaStringEscapes; +import org.apache.brooklyn.util.text.StringFunctions.RegexReplacer; import org.apache.brooklyn.util.text.Strings; import org.apache.commons.beanutils.BeanUtils; import org.slf4j.Logger; @@ -626,25 +627,17 @@ public class BrooklynDslCommon { public static class Functions { public static Object regexReplacement(final Object pattern, final Object replacement) { if (resolved(pattern, replacement)) { - return new RegexReplacer(String.valueOf(pattern), String.valueOf(replacement)); + return new org.apache.brooklyn.util.text.StringFunctions.RegexReplacer(String.valueOf(pattern), String.valueOf(replacement)); } else { return new DslRegexReplacer(pattern, replacement); } } - public static class RegexReplacer implements Function<String, String> { - private final String pattern; - private final String replacement; - + /** @deprecated since 0.11.0; use {@link org.apache.brooklyn.util.text.StringFunctions.RegexReplacer} instead */ + @Deprecated + public static class RegexReplacer extends org.apache.brooklyn.util.text.StringFunctions.RegexReplacer { public RegexReplacer(String pattern, String replacement) { - this.pattern = pattern; - this.replacement = replacement; - } - - @Nullable - @Override - public String apply(@Nullable String s) { - return s == null ? null : Strings.replaceAllRegex(s, pattern, replacement); + super(pattern, replacement); } } http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/498a58c0/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties ---------------------------------------------------------------------- diff --git a/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties b/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties index 300bba2..6d6fa61 100644 --- a/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties +++ b/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties @@ -1436,3 +1436,6 @@ org.apache.brooklyn.config.ConfigInheritance$Always org.apache.brooklyn.config.ConfigInheritance$Merged : org.apache.brooklyn.config.ConfigInheritance$Legacy$Merged org.apache.brooklyn.entity.software.base.lifecycle.MachineLifecycleEffectorTasks$ProvisioningTaskState : org.apache.brooklyn.core.entity.internal.AttributesInternal$ProvisioningTaskState + +# since 0.11.0 +org.apache.brooklyn.camp.brooklyn.spi.dsl.methods.BrooklynDslCommon.Functions.RegexReplacer : org.apache.brooklyn.util.text.StringFunctions.RegexReplacer http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/498a58c0/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 ec2c023..c9ec2a6 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 @@ -26,6 +26,7 @@ import com.google.common.base.CaseFormat; import com.google.common.base.CharMatcher; import com.google.common.base.Function; import com.google.common.base.Functions; +import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.common.collect.Iterables; @@ -409,7 +410,22 @@ public class StringFunctions { @Nullable @Override public String apply(@Nullable String s) { - return Strings.replaceAllRegex(s, pattern, replacement); + return s == null ? null : Strings.replaceAllRegex(s, pattern, replacement); } + + @Override + public int hashCode() { + return Objects.hashCode(pattern, replacement); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + RegexReplacer that = RegexReplacer.class.cast(obj); + return Objects.equal(this.pattern, that.pattern) && + Objects.equal(this.replacement, that.replacement); + } + } }