Remove Strings2.replaceAll(String, Pattern, String)

Replace with direct calls to
Pattern.matcher(String).replaceAll(String).
This commit is contained in:
Andrew Gaul 2013-05-29 10:20:46 -07:00
parent 64e9a4e4c6
commit d113b0ba63
5 changed files with 6 additions and 12 deletions

View File

@ -147,7 +147,7 @@ public class SignRequest implements HttpRequestFilter {
// newline characters and extra embedded white spaces in the value. // newline characters and extra embedded white spaces in the value.
for (String value : request.getHeaders().get(header)) { for (String value : request.getHeaders().get(header)) {
value = value.replace(" ", " "); value = value.replace(" ", " ");
value = Strings2.replaceAll(value, NEWLINE_PATTERN, ""); value = NEWLINE_PATTERN.matcher(value).replaceAll("");
toSign.append(value).append(' '); toSign.append(value).append(' ');
} }
toSign.deleteCharAt(toSign.lastIndexOf(" ")); toSign.deleteCharAt(toSign.lastIndexOf(" "));

View File

@ -158,7 +158,7 @@ public class SharedKeyLiteAuthentication implements HttpRequestFilter {
if (header.startsWith("x-ms-")) { if (header.startsWith("x-ms-")) {
toSign.append(header.toLowerCase()).append(":"); toSign.append(header.toLowerCase()).append(":");
for (String value : request.getHeaders().get(header)) { 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.deleteCharAt(toSign.lastIndexOf(","));
toSign.append("\n"); toSign.append("\n");

View File

@ -62,9 +62,9 @@ public class BindAddInternetServiceToXmlPayload implements MapBinder {
String payload = Strings2.replaceTokens(xmlTemplate, String payload = Strings2.replaceTokens(xmlTemplate,
ImmutableMap.of("name", name, "protocol", protocol, "port", port, "enabled", enabled, "ns", ns)); ImmutableMap.of("name", name, "protocol", protocol, "port", port, "enabled", enabled, "ns", ns));
try { 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<Description>%s</Description>", description)); : String.format("\n\t<Description>%s</Description>", 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) { } catch (ExecutionException e) {
Throwables.propagate(e); Throwables.propagate(e);
} }

View File

@ -63,7 +63,7 @@ public class BindAddNodeServiceToXmlPayload implements MapBinder {
String payload = Strings2.replaceTokens(xmlTemplate, String payload = Strings2.replaceTokens(xmlTemplate,
ImmutableMap.of("name", name, "ipAddress", ipAddress, "port", port, "enabled", enabled, "ns", ns)); ImmutableMap.of("name", name, "ipAddress", ipAddress, "port", port, "enabled", enabled, "ns", ns));
try { 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 <Description>%s</Description>", description)); : String.format("\n <Description>%s</Description>", description));
} catch (ExecutionException e) { } catch (ExecutionException e) {
Throwables.propagate(e); Throwables.propagate(e);

View File

@ -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<? extends InputStream> supplier) public static String toString(InputSupplier<? extends InputStream> supplier)
throws IOException { throws IOException {
return CharStreams.toString(CharStreams.newReaderSupplier(supplier, return CharStreams.toString(CharStreams.newReaderSupplier(supplier,
@ -173,7 +167,7 @@ public class Strings2 {
public static String replaceTokens(String input, Multimap<String, ?> tokenValues) { public static String replaceTokens(String input, Multimap<String, ?> tokenValues) {
for (Entry<String, ?> tokenValue : tokenValues.entries()) { for (Entry<String, ?> tokenValue : tokenValues.entries()) {
Pattern pattern = TOKEN_TO_PATTERN.getUnchecked(tokenValue.getKey()); 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; return input;
} }