Skip to content

Commit

Permalink
Merge pull request spring-projects#8002 from Christoph Dreis
Browse files Browse the repository at this point in the history
* spring-projectsgh-8002:
  Improve performance of RelaxedNames
  • Loading branch information
wilkinsona committed Jan 18, 2017
2 parents ba8f721 + 93f9771 commit 0ae2972
Showing 1 changed file with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -91,7 +91,7 @@ public String apply(String value) {

@Override
public String apply(String value) {
return value.toLowerCase();
return value.isEmpty() ? value : value.toLowerCase();
}

},
Expand All @@ -100,7 +100,7 @@ public String apply(String value) {

@Override
public String apply(String value) {
return value.toUpperCase();
return value.isEmpty() ? value : value.toUpperCase();
}

};
Expand All @@ -127,7 +127,7 @@ public String apply(String value) {

@Override
public String apply(String value) {
return value.replace("-", "_");
return value.indexOf('-') != -1 ? value.replace("-", "_") : value;
}

},
Expand All @@ -136,7 +136,7 @@ public String apply(String value) {

@Override
public String apply(String value) {
return value.replace("_", ".");
return value.indexOf('_') != -1 ? value.replace("_", ".") : value;
}

},
Expand All @@ -145,7 +145,7 @@ public String apply(String value) {

@Override
public String apply(String value) {
return value.replace(".", "_");
return value.indexOf('.') != -1 ? value.replace(".", "_") : value;
}

},
Expand All @@ -154,7 +154,14 @@ public String apply(String value) {

@Override
public String apply(String value) {
if (value.isEmpty()) {
return value;
}
Matcher matcher = CAMEL_CASE_PATTERN.matcher(value);
if (!matcher.find()) {
return value;
}
matcher = matcher.reset();
StringBuffer result = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(result, matcher.group(1) + '_'
Expand All @@ -170,7 +177,14 @@ public String apply(String value) {

@Override
public String apply(String value) {
if (value.isEmpty()) {
return value;
}
Matcher matcher = CAMEL_CASE_PATTERN.matcher(value);
if (!matcher.find()) {
return value;
}
matcher = matcher.reset();
StringBuffer result = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(result, matcher.group(1) + '-'
Expand Down Expand Up @@ -206,7 +220,7 @@ public String apply(String value) {

private static String separatedToCamelCase(String value,
boolean caseInsensitive) {
if (value.length() == 0) {
if (value.isEmpty()) {
return value;
}
StringBuilder builder = new StringBuilder();
Expand All @@ -233,7 +247,7 @@ private static String separatedToCamelCase(String value,
* @return the relaxed names
*/
public static RelaxedNames forCamelCase(String name) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
for (char c : name.toCharArray()) {
result.append(Character.isUpperCase(c) && result.length() > 0
&& result.charAt(result.length() - 1) != '-'
Expand Down

0 comments on commit 0ae2972

Please sign in to comment.