Commit b19dcb13 authored by andrey.onufreyko's avatar andrey.onufreyko Committed by Phillip Webb

Replace string arguments with char

Optimize method calls by replacing single character String arguments
with char.

Closes gh-11680
parent 2735f57b
...@@ -71,7 +71,7 @@ public class Token { ...@@ -71,7 +71,7 @@ public class Token {
} }
public byte[] getContent() { public byte[] getContent() {
return this.encoded.substring(0, this.encoded.lastIndexOf(".")).getBytes(); return this.encoded.substring(0, this.encoded.lastIndexOf('.')).getBytes();
} }
public byte[] getSignature() { public byte[] getSignature() {
......
...@@ -94,7 +94,7 @@ public class AuditEvent implements Serializable { ...@@ -94,7 +94,7 @@ public class AuditEvent implements Serializable {
private static Map<String, Object> convert(String[] data) { private static Map<String, Object> convert(String[] data) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
for (String entry : data) { for (String entry : data) {
int index = entry.indexOf("="); int index = entry.indexOf('=');
if (index != -1) { if (index != -1) {
result.put(entry.substring(0, index), entry.substring(index + 1)); result.put(entry.substring(0, index), entry.substring(index + 1));
} }
......
...@@ -891,7 +891,7 @@ public class RabbitProperties { ...@@ -891,7 +891,7 @@ public class RabbitProperties {
} }
private String parseVirtualHost(String input) { private String parseVirtualHost(String input) {
int hostIndex = input.indexOf("/"); int hostIndex = input.indexOf('/');
if (hostIndex >= 0) { if (hostIndex >= 0) {
this.virtualHost = input.substring(hostIndex + 1); this.virtualHost = input.substring(hostIndex + 1);
if (this.virtualHost.isEmpty()) { if (this.virtualHost.isEmpty()) {
......
...@@ -132,7 +132,7 @@ abstract class RedisConnectionConfiguration { ...@@ -132,7 +132,7 @@ abstract class RedisConnectionConfiguration {
String password = null; String password = null;
if (uri.getUserInfo() != null) { if (uri.getUserInfo() != null) {
password = uri.getUserInfo(); password = uri.getUserInfo();
int index = password.lastIndexOf(":"); int index = password.lastIndexOf(':');
if (index >= 0) { if (index >= 0) {
password = password.substring(index + 1); password = password.substring(index + 1);
} }
......
...@@ -33,8 +33,8 @@ class DataSourceBeanCreationFailureAnalyzer ...@@ -33,8 +33,8 @@ class DataSourceBeanCreationFailureAnalyzer
protected FailureAnalysis analyze(Throwable rootFailure, protected FailureAnalysis analyze(Throwable rootFailure,
DataSourceBeanCreationException cause) { DataSourceBeanCreationException cause) {
String message = cause.getMessage(); String message = cause.getMessage();
String description = message.substring(0, message.indexOf(".")).trim(); String description = message.substring(0, message.indexOf('.')).trim();
String action = message.substring(message.indexOf(".") + 1).trim(); String action = message.substring(message.indexOf('.') + 1).trim();
return new FailureAnalysis(description, action, cause); return new FailureAnalysis(description, action, cause);
} }
......
...@@ -292,7 +292,7 @@ public class ServerProperties { ...@@ -292,7 +292,7 @@ public class ServerProperties {
public String getServletPrefix() { public String getServletPrefix() {
String result = this.path; String result = this.path;
int index = result.indexOf("*"); int index = result.indexOf('*');
if (index != -1) { if (index != -1) {
result = result.substring(0, index); result = result.substring(0, index);
} }
......
...@@ -251,7 +251,7 @@ class InitializrService { ...@@ -251,7 +251,7 @@ class InitializrService {
int start = value.indexOf(FILENAME_HEADER_PREFIX); int start = value.indexOf(FILENAME_HEADER_PREFIX);
if (start != -1) { if (start != -1) {
value = value.substring(start + FILENAME_HEADER_PREFIX.length()); value = value.substring(start + FILENAME_HEADER_PREFIX.length());
int end = value.indexOf("\""); int end = value.indexOf('\"');
if (end != -1) { if (end != -1) {
return value.substring(0, end); return value.substring(0, end);
} }
......
...@@ -48,7 +48,7 @@ class RemoteUrlPropertyExtractor ...@@ -48,7 +48,7 @@ class RemoteUrlPropertyExtractor
ConfigurableEnvironment environment = event.getEnvironment(); ConfigurableEnvironment environment = event.getEnvironment();
String url = cleanRemoteUrl(environment.getProperty(NON_OPTION_ARGS)); String url = cleanRemoteUrl(environment.getProperty(NON_OPTION_ARGS));
Assert.state(StringUtils.hasLength(url), "No remote URL specified"); Assert.state(StringUtils.hasLength(url), "No remote URL specified");
Assert.state(url.indexOf(",") == -1, "Multiple URLs specified"); Assert.state(url.indexOf(',') == -1, "Multiple URLs specified");
try { try {
new URI(url); new URI(url);
} }
......
...@@ -78,7 +78,7 @@ final class SpringBootConfigurationFinder { ...@@ -78,7 +78,7 @@ final class SpringBootConfigurationFinder {
} }
private String getParentPackage(String sourcePackage) { private String getParentPackage(String sourcePackage) {
int lastDot = sourcePackage.lastIndexOf("."); int lastDot = sourcePackage.lastIndexOf('.');
return (lastDot == -1 ? "" : sourcePackage.substring(0, lastDot)); return (lastDot == -1 ? "" : sourcePackage.substring(0, lastDot));
} }
......
...@@ -91,8 +91,8 @@ public abstract class EnvironmentTestUtils { ...@@ -91,8 +91,8 @@ public abstract class EnvironmentTestUtils {
} }
private static int getSeparatorIndex(String pair) { private static int getSeparatorIndex(String pair) {
int colonIndex = pair.indexOf(":"); int colonIndex = pair.indexOf(':');
int equalIndex = pair.indexOf("="); int equalIndex = pair.indexOf('=');
if (colonIndex == -1) { if (colonIndex == -1) {
return equalIndex; return equalIndex;
} }
......
...@@ -267,8 +267,8 @@ public final class TestPropertyValues { ...@@ -267,8 +267,8 @@ public final class TestPropertyValues {
} }
private static int getSeparatorIndex(String pair) { private static int getSeparatorIndex(String pair) {
int colonIndex = pair.indexOf(":"); int colonIndex = pair.indexOf(':');
int equalIndex = pair.indexOf("="); int equalIndex = pair.indexOf('=');
if (colonIndex == -1) { if (colonIndex == -1) {
return equalIndex; return equalIndex;
} }
......
...@@ -30,7 +30,7 @@ class DescriptionExtractor { ...@@ -30,7 +30,7 @@ class DescriptionExtractor {
if (description == null) { if (description == null) {
return null; return null;
} }
int dot = description.indexOf("."); int dot = description.indexOf('.');
if (dot != -1) { if (dot != -1) {
BreakIterator breakIterator = BreakIterator.getSentenceInstance(Locale.US); BreakIterator breakIterator = BreakIterator.getSentenceInstance(Locale.US);
breakIterator.setText(description); breakIterator.setText(description);
......
...@@ -176,7 +176,7 @@ public class JavaCompilerFieldValuesParser implements FieldValuesParser { ...@@ -176,7 +176,7 @@ public class JavaCompilerFieldValuesParser implements FieldValuesParser {
Object instance = expression.getInstance(); Object instance = expression.getInstance();
if (instance != null && instance.toString().startsWith(DURATION_OF)) { if (instance != null && instance.toString().startsWith(DURATION_OF)) {
String type = instance.toString(); String type = instance.toString();
type = type.substring(DURATION_OF.length(), type.indexOf("(")); type = type.substring(DURATION_OF.length(), type.indexOf('('));
String suffix = DURATION_SUFFIX.get(type); String suffix = DURATION_SUFFIX.get(type);
return (suffix == null ? null : factoryValue + suffix); return (suffix == null ? null : factoryValue + suffix);
} }
......
...@@ -253,8 +253,8 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable { ...@@ -253,8 +253,8 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
else { else {
entry.setUnixMode(UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM); entry.setUnixMode(UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM);
} }
if (parent.lastIndexOf("/") != -1) { if (parent.lastIndexOf('/') != -1) {
parent = parent.substring(0, parent.lastIndexOf("/") + 1); parent = parent.substring(0, parent.lastIndexOf('/') + 1);
if (!parent.isEmpty()) { if (!parent.isEmpty()) {
writeEntry(new JarArchiveEntry(parent), null); writeEntry(new JarArchiveEntry(parent), null);
} }
......
...@@ -498,7 +498,7 @@ public class PropertiesLauncher extends Launcher { ...@@ -498,7 +498,7 @@ public class PropertiesLauncher extends Launcher {
// If home dir is same as parent archive, no need to add it twice. // If home dir is same as parent archive, no need to add it twice.
return null; return null;
} }
int index = root.indexOf("!"); int index = root.indexOf('!');
if (index != -1) { if (index != -1) {
File file = new File(this.home, root.substring(0, index)); File file = new File(this.home, root.substring(0, index));
if (root.startsWith("jar:file:")) { if (root.startsWith("jar:file:")) {
......
...@@ -112,8 +112,8 @@ public class JarFileArchive implements Archive { ...@@ -112,8 +112,8 @@ public class JarFileArchive implements Archive {
private Archive getUnpackedNestedArchive(JarEntry jarEntry) throws IOException { private Archive getUnpackedNestedArchive(JarEntry jarEntry) throws IOException {
String name = jarEntry.getName(); String name = jarEntry.getName();
if (name.lastIndexOf("/") != -1) { if (name.lastIndexOf('/') != -1) {
name = name.substring(name.lastIndexOf("/") + 1); name = name.substring(name.lastIndexOf('/') + 1);
} }
File file = new File(getTempUnpackFolder(), name); File file = new File(getTempUnpackFolder(), name);
if (!file.exists() || file.length() != jarEntry.getSize()) { if (!file.exists() || file.length() != jarEntry.getSize()) {
......
...@@ -243,7 +243,7 @@ class BeanDefinitionLoader { ...@@ -243,7 +243,7 @@ class BeanDefinitionLoader {
// a file list of the package content. We double check here that it's not // a file list of the package content. We double check here that it's not
// actually a package. // actually a package.
String path = ((ClassPathResource) resource).getPath(); String path = ((ClassPathResource) resource).getPath();
if (path.indexOf(".") == -1) { if (path.indexOf('.') == -1) {
try { try {
return Package.getPackage(path) == null; return Package.getPackage(path) == null;
} }
......
...@@ -93,7 +93,7 @@ class NoUniqueBeanDefinitionFailureAnalyzer ...@@ -93,7 +93,7 @@ class NoUniqueBeanDefinitionFailureAnalyzer
private String[] extractBeanNames(NoUniqueBeanDefinitionException cause) { private String[] extractBeanNames(NoUniqueBeanDefinitionException cause) {
if (cause.getMessage().indexOf("but found") > -1) { if (cause.getMessage().indexOf("but found") > -1) {
return StringUtils.commaDelimitedListToStringArray(cause.getMessage() return StringUtils.commaDelimitedListToStringArray(cause.getMessage()
.substring(cause.getMessage().lastIndexOf(":") + 1).trim()); .substring(cause.getMessage().lastIndexOf(':') + 1).trim());
} }
return null; return null;
} }
......
...@@ -69,7 +69,7 @@ class SpringPropertyAction extends Action { ...@@ -69,7 +69,7 @@ class SpringPropertyAction extends Action {
if (value != null) { if (value != null) {
return value; return value;
} }
int lastDot = source.lastIndexOf("."); int lastDot = source.lastIndexOf('.');
if (lastDot > 0) { if (lastDot > 0) {
String prefix = source.substring(0, lastDot + 1); String prefix = source.substring(0, lastDot + 1);
return this.environment.getProperty(prefix + source.substring(lastDot + 1), return this.environment.getProperty(prefix + source.substring(lastDot + 1),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment