Use String.repeat instead of explicit cycle

See gh-31802
This commit is contained in:
Adam Ostrožlík 2023-12-09 16:01:37 +01:00 committed by Stéphane Nicoll
parent 1ff683b259
commit 63b2787da6
7 changed files with 7 additions and 21 deletions

View File

@ -98,9 +98,7 @@ public final class ParseState {
for (ParseState.Entry entry : this.state) {
if (i > 0) {
sb.append('\n');
for (int j = 0; j < i; j++) {
sb.append('\t');
}
sb.append("\t".repeat(i));
sb.append("-> ");
}
sb.append(entry);

View File

@ -462,9 +462,7 @@ public final class Type {
return "double";
case ARRAY:
StringBuilder stringBuilder = new StringBuilder(getElementType().getClassName());
for (int i = getDimensions(); i > 0; --i) {
stringBuilder.append("[]");
}
stringBuilder.append("[]".repeat(Math.max(0, getDimensions())));
return stringBuilder.toString();
case OBJECT:
case INTERNAL:

View File

@ -218,9 +218,7 @@ public class ReflectUtils {
dimensions++;
}
StringBuilder brackets = new StringBuilder(className.length() - dimensions);
for (int i = 0; i < dimensions; i++) {
brackets.append('[');
}
brackets.append("[".repeat(Math.max(0, dimensions)));
className = className.substring(0, className.length() - 2 * dimensions);
String prefix = (dimensions > 0) ? brackets + "L" : "";

View File

@ -68,9 +68,7 @@ public class PatternParseException extends IllegalArgumentException {
public String toDetailedString() {
StringBuilder sb = new StringBuilder();
sb.append(this.pattern).append('\n');
for (int i = 0; i < this.position; i++) {
sb.append(' ');
}
sb.append(" ".repeat(Math.max(0, this.position)));
sb.append("^\n");
sb.append(getMessage());
return sb.toString();

View File

@ -81,9 +81,7 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi
}
private void indent() {
for (int i = 0; i < this.indent; i++) {
this.builder.append(' ');
}
this.builder.append(" ".repeat(Math.max(0, this.indent)));
}

View File

@ -80,9 +80,7 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi
}
private void indent() {
for (int i = 0; i < this.indent; i++) {
this.builder.append(' ');
}
this.builder.append(" ".repeat(Math.max(0, this.indent)));
}

View File

@ -59,9 +59,7 @@ public abstract class AbstractSockJsMessageCodec implements SockJsMessageCodec {
if (isSockJsSpecialChar(c)) {
result.append('\\').append('u');
String hex = Integer.toHexString(c).toLowerCase();
for (int i = 0; i < (4 - hex.length()); i++) {
result.append('0');
}
result.append("0".repeat(Math.max(0, (4 - hex.length()))));
result.append(hex);
}
else {