Browse Source

Use String indexOf(char) and lastIndexOf(char) where possible

Closes gh-11416
pull/17440/head
Andy Wilkinson 7 years ago
parent
commit
4b2a116fa7
  1. 6
      spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/StringSequenceTests.java
  2. 4
      spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles-fork/src/main/java/org/test/SampleApplication.java
  3. 4
      spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles/src/main/java/org/test/SampleApplication.java
  4. 2
      spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BindFailureAnalyzerTests.java
  5. 2
      spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BindValidationFailureAnalyzerTests.java
  6. 2
      spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/UnboundConfigurationPropertyFailureAnalyzerTests.java
  7. 2
      spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CityServiceImpl.java

6
spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/StringSequenceTests.java

@ -127,9 +127,9 @@ class StringSequenceTests { @@ -127,9 +127,9 @@ class StringSequenceTests {
@Test
void indexOfStringShouldReturnIndexOf() {
StringSequence sequence = new StringSequence("aabbaacc");
assertThat(sequence.indexOf("a")).isEqualTo(0);
assertThat(sequence.indexOf("b")).isEqualTo(2);
assertThat(sequence.subSequence(2).indexOf("a")).isEqualTo(2);
assertThat(sequence.indexOf('a')).isEqualTo(0);
assertThat(sequence.indexOf('b')).isEqualTo(2);
assertThat(sequence.subSequence(2).indexOf('a')).isEqualTo(2);
}
@Test

4
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles-fork/src/main/java/org/test/SampleApplication.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 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.
@ -28,7 +28,7 @@ public class SampleApplication { @@ -28,7 +28,7 @@ public class SampleApplication {
if (!argument.startsWith("--spring.profiles.active=")) {
throw new IllegalArgumentException("Invalid argument " + argument);
}
int index = args[0].indexOf("=");
int index = args[0].indexOf('=');
String profile = argument.substring(index + 1);
System.out.println("I haz been run with profile(s) '" + profile + "'");
}

4
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles/src/main/java/org/test/SampleApplication.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 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.
@ -28,7 +28,7 @@ public class SampleApplication { @@ -28,7 +28,7 @@ public class SampleApplication {
if (!argument.startsWith("--spring.profiles.active=")) {
throw new IllegalArgumentException("Invalid argument " + argument);
}
int index = args[0].indexOf("=");
int index = args[0].indexOf('=');
String profile = argument.substring(index + 1);
System.out.println("I haz been run with profile(s) '" + profile + "'");
}

2
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BindFailureAnalyzerTests.java

@ -108,7 +108,7 @@ class BindFailureAnalyzerTests { @@ -108,7 +108,7 @@ class BindFailureAnalyzerTests {
MutablePropertySources sources = context.getEnvironment().getPropertySources();
Map<String, Object> map = new HashMap<>();
for (String pair : environment) {
int index = pair.indexOf("=");
int index = pair.indexOf('=');
String key = (index > 0) ? pair.substring(0, index) : pair;
String value = (index > 0) ? pair.substring(index + 1) : "";
map.put(key.trim(), value.trim());

2
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BindValidationFailureAnalyzerTests.java

@ -119,7 +119,7 @@ class BindValidationFailureAnalyzerTests { @@ -119,7 +119,7 @@ class BindValidationFailureAnalyzerTests {
MutablePropertySources sources = context.getEnvironment().getPropertySources();
Map<String, Object> map = new HashMap<>();
for (String pair : environment) {
int index = pair.indexOf("=");
int index = pair.indexOf('=');
String key = (index > 0) ? pair.substring(0, index) : pair;
String value = (index > 0) ? pair.substring(index + 1) : "";
map.put(key.trim(), value.trim());

2
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/UnboundConfigurationPropertyFailureAnalyzerTests.java

@ -91,7 +91,7 @@ class UnboundConfigurationPropertyFailureAnalyzerTests { @@ -91,7 +91,7 @@ class UnboundConfigurationPropertyFailureAnalyzerTests {
MutablePropertySources sources = context.getEnvironment().getPropertySources();
Map<String, Object> map = new HashMap<>();
for (String pair : environment) {
int index = pair.indexOf("=");
int index = pair.indexOf('=');
String key = (index > 0) ? pair.substring(0, index) : pair;
String value = (index > 0) ? pair.substring(index + 1) : "";
map.put(key.trim(), value.trim());

2
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CityServiceImpl.java

@ -50,7 +50,7 @@ class CityServiceImpl implements CityService { @@ -50,7 +50,7 @@ class CityServiceImpl implements CityService {
}
String country = "";
int splitPos = name.lastIndexOf(",");
int splitPos = name.lastIndexOf(',');
if (splitPos >= 0) {
country = name.substring(splitPos + 1);

Loading…
Cancel
Save