Skip to content

Commit 7965c19

Browse files
committed
Merge pull request #31802 from Drezir
* pr/31802: Polish "Use String.repeat instead of explicit cycle" Use String.repeat instead of explicit cycle Closes gh-31802
2 parents 1ff683b + d057419 commit 7965c19

File tree

5 files changed

+10
-20
lines changed

5 files changed

+10
-20
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-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.
@@ -98,9 +98,7 @@ public String toString() {
9898
for (ParseState.Entry entry : this.state) {
9999
if (i > 0) {
100100
sb.append('\n');
101-
for (int j = 0; j < i; j++) {
102-
sb.append('\t');
103-
}
101+
sb.append("\t".repeat(i));
104102
sb.append("-> ");
105103
}
106104
sb.append(entry);

spring-web/src/main/java/org/springframework/web/util/pattern/PatternParseException.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-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.
@@ -68,9 +68,7 @@ public String getMessage() {
6868
public String toDetailedString() {
6969
StringBuilder sb = new StringBuilder();
7070
sb.append(this.pattern).append('\n');
71-
for (int i = 0; i < this.position; i++) {
72-
sb.append(' ');
73-
}
71+
sb.append(" ".repeat(Math.max(0, this.position)));
7472
sb.append("^\n");
7573
sb.append(getMessage());
7674
return sb.toString();

spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ToStringVisitor.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-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.
@@ -81,9 +81,7 @@ public void unknown(RouterFunction<?> routerFunction) {
8181
}
8282

8383
private void indent() {
84-
for (int i = 0; i < this.indent; i++) {
85-
this.builder.append(' ');
86-
}
84+
this.builder.append(" ".repeat(Math.max(0, this.indent)));
8785
}
8886

8987

spring-webmvc/src/main/java/org/springframework/web/servlet/function/ToStringVisitor.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-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.
@@ -80,9 +80,7 @@ public void unknown(RouterFunction<?> routerFunction) {
8080
}
8181

8282
private void indent() {
83-
for (int i = 0; i < this.indent; i++) {
84-
this.builder.append(' ');
85-
}
83+
this.builder.append(" ".repeat(Math.max(0, this.indent)));
8684
}
8785

8886

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/AbstractSockJsMessageCodec.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-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.
@@ -59,9 +59,7 @@ private String escapeSockJsSpecialChars(char[] characters) {
5959
if (isSockJsSpecialChar(c)) {
6060
result.append('\\').append('u');
6161
String hex = Integer.toHexString(c).toLowerCase();
62-
for (int i = 0; i < (4 - hex.length()); i++) {
63-
result.append('0');
64-
}
62+
result.append("0".repeat(Math.max(0, (4 - hex.length()))));
6563
result.append(hex);
6664
}
6765
else {

0 commit comments

Comments
 (0)