From d113b0ba63e1335ca4aa007036e0b0678934841f Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Wed, 29 May 2013 10:20:46 -0700 Subject: [PATCH] Remove Strings2.replaceAll(String, Pattern, String) Replace with direct calls to Pattern.matcher(String).replaceAll(String). --- .../main/java/org/jclouds/atmos/filters/SignRequest.java | 2 +- .../storage/filters/SharedKeyLiteAuthentication.java | 2 +- .../binders/BindAddInternetServiceToXmlPayload.java | 4 ++-- .../binders/BindAddNodeServiceToXmlPayload.java | 2 +- core/src/main/java/org/jclouds/util/Strings2.java | 8 +------- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/filters/SignRequest.java b/apis/atmos/src/main/java/org/jclouds/atmos/filters/SignRequest.java index 7380d802bc..8caff86cc0 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/filters/SignRequest.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/filters/SignRequest.java @@ -147,7 +147,7 @@ public class SignRequest implements HttpRequestFilter { // newline characters and extra embedded white spaces in the value. for (String value : request.getHeaders().get(header)) { value = value.replace(" ", " "); - value = Strings2.replaceAll(value, NEWLINE_PATTERN, ""); + value = NEWLINE_PATTERN.matcher(value).replaceAll(""); toSign.append(value).append(' '); } toSign.deleteCharAt(toSign.lastIndexOf(" ")); diff --git a/common/azure/src/main/java/org/jclouds/azure/storage/filters/SharedKeyLiteAuthentication.java b/common/azure/src/main/java/org/jclouds/azure/storage/filters/SharedKeyLiteAuthentication.java index 2c6188e121..f6d61e1e28 100644 --- a/common/azure/src/main/java/org/jclouds/azure/storage/filters/SharedKeyLiteAuthentication.java +++ b/common/azure/src/main/java/org/jclouds/azure/storage/filters/SharedKeyLiteAuthentication.java @@ -158,7 +158,7 @@ public class SharedKeyLiteAuthentication implements HttpRequestFilter { if (header.startsWith("x-ms-")) { toSign.append(header.toLowerCase()).append(":"); for (String value : request.getHeaders().get(header)) { - toSign.append(Strings2.replaceAll(value, NEWLINE_PATTERN, "")).append(","); + toSign.append(NEWLINE_PATTERN.matcher(value).replaceAll("")).append(","); } toSign.deleteCharAt(toSign.lastIndexOf(",")); toSign.append("\n"); diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/binders/BindAddInternetServiceToXmlPayload.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/binders/BindAddInternetServiceToXmlPayload.java index cffe5f26b8..30fc2cecae 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/binders/BindAddInternetServiceToXmlPayload.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/binders/BindAddInternetServiceToXmlPayload.java @@ -62,9 +62,9 @@ public class BindAddInternetServiceToXmlPayload implements MapBinder { String payload = Strings2.replaceTokens(xmlTemplate, ImmutableMap.of("name", name, "protocol", protocol, "port", port, "enabled", enabled, "ns", ns)); try { - payload = Strings2.replaceAll(payload, Patterns.TOKEN_TO_PATTERN.get("description"), description == null ? "" + payload = Patterns.TOKEN_TO_PATTERN.get("description").matcher(payload).replaceAll(description == null ? "" : String.format("\n\t%s", description)); - payload = Strings2.replaceAll(payload, Patterns.TOKEN_TO_PATTERN.get("monitor"), getMonitorString(postParams)); + payload = Patterns.TOKEN_TO_PATTERN.get("monitor").matcher(payload).replaceAll(getMonitorString(postParams)); } catch (ExecutionException e) { Throwables.propagate(e); } diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/binders/BindAddNodeServiceToXmlPayload.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/binders/BindAddNodeServiceToXmlPayload.java index dd80d2d709..03477d1866 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/binders/BindAddNodeServiceToXmlPayload.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/binders/BindAddNodeServiceToXmlPayload.java @@ -63,7 +63,7 @@ public class BindAddNodeServiceToXmlPayload implements MapBinder { String payload = Strings2.replaceTokens(xmlTemplate, ImmutableMap.of("name", name, "ipAddress", ipAddress, "port", port, "enabled", enabled, "ns", ns)); try { - payload = Strings2.replaceAll(payload, Patterns.TOKEN_TO_PATTERN.get("description"), description == null ? "" + payload = Patterns.TOKEN_TO_PATTERN.get("description").matcher(payload).replaceAll(description == null ? "" : String.format("\n %s", description)); } catch (ExecutionException e) { Throwables.propagate(e); diff --git a/core/src/main/java/org/jclouds/util/Strings2.java b/core/src/main/java/org/jclouds/util/Strings2.java index 3b3b09ec65..8b85b5320c 100644 --- a/core/src/main/java/org/jclouds/util/Strings2.java +++ b/core/src/main/java/org/jclouds/util/Strings2.java @@ -113,12 +113,6 @@ public class Strings2 { } } - public static String replaceAll(String returnVal, Pattern pattern, String replace) { - Matcher m = pattern.matcher(returnVal); - returnVal = m.replaceAll(replace); - return returnVal; - } - public static String toString(InputSupplier supplier) throws IOException { return CharStreams.toString(CharStreams.newReaderSupplier(supplier, @@ -173,7 +167,7 @@ public class Strings2 { public static String replaceTokens(String input, Multimap tokenValues) { for (Entry tokenValue : tokenValues.entries()) { Pattern pattern = TOKEN_TO_PATTERN.getUnchecked(tokenValue.getKey()); - input = replaceAll(input, pattern, tokenValue.getValue().toString()); + input = pattern.matcher(input).replaceAll(tokenValue.getValue().toString()); } return input; }