Skip to content

Commit 8c5456c

Browse files
committed
Replace for loops with String.repeat where appropriate
1 parent a63755b commit 8c5456c

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDaoTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2022 the original author or authors.
2+
* Copyright 2008-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,9 +49,7 @@ protected JobRepository getJobRepository() {
4949
void testTruncateExitDescription() {
5050

5151
StringBuilder sb = new StringBuilder();
52-
for (int i = 0; i < 100; i++) {
53-
sb.append("too long exit description");
54-
}
52+
sb.append("too long exit description".repeat(100));
5553
String longDescription = sb.toString();
5654

5755
ExitStatus exitStatus = ExitStatus.FAILED.addExitDescription(longDescription);

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/FormatterLineAggregatorTests.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* Unit tests for {@link FormatterLineAggregator}
2727
*
2828
* @author Dave Syer
29+
* @author Mahmoud Ben Hassine
2930
*/
3031
class FormatterLineAggregatorTests {
3132

@@ -120,9 +121,7 @@ public Object[] extract(String[] item) {
120121
strings[i] = item[i];
121122
if (item[i].length() < widths[i]) {
122123
StringBuilder buffer = new StringBuilder(strings[i]);
123-
for (int j = 0; j < (widths[i] - item[i].length() + 1) / 2; j++) {
124-
buffer.append(" ");
125-
}
124+
buffer.append(" ".repeat(Math.max(0, (widths[i] - item[i].length() + 1) / 2)));
126125
strings[i] = buffer.toString();
127126
}
128127
}
@@ -155,9 +154,7 @@ public Object[] extract(String[] item) {
155154
strings[i] = item[i];
156155
if (item[i].length() < widths[i]) {
157156
StringBuilder buffer = new StringBuilder(strings[i]);
158-
for (int j = 0; j < widths[i] - item[i].length(); j++) {
159-
buffer.append(".");
160-
}
157+
buffer.append(".".repeat(Math.max(0, widths[i] - item[i].length())));
161158
strings[i] = buffer.toString();
162159
}
163160
}

0 commit comments

Comments
 (0)