Polish "Use String.repeat instead of explicit cycle"

See gh-31802
This commit is contained in:
Stéphane Nicoll 2023-12-18 13:58:14 +01:00
parent 63b2787da6
commit d0574197ea
7 changed files with 16 additions and 12 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -98,7 +98,7 @@ public final class ParseState {
for (ParseState.Entry entry : this.state) { for (ParseState.Entry entry : this.state) {
if (i > 0) { if (i > 0) {
sb.append('\n'); sb.append('\n');
sb.append("\t".repeat(i)); sb.append("\t".repeat(i));
sb.append("-> "); sb.append("-> ");
} }
sb.append(entry); sb.append(entry);

View File

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

View File

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

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -68,7 +68,7 @@ public class PatternParseException extends IllegalArgumentException {
public String toDetailedString() { public String toDetailedString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(this.pattern).append('\n'); sb.append(this.pattern).append('\n');
sb.append(" ".repeat(Math.max(0, this.position))); sb.append(" ".repeat(Math.max(0, this.position)));
sb.append("^\n"); sb.append("^\n");
sb.append(getMessage()); sb.append(getMessage());
return sb.toString(); return sb.toString();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -81,7 +81,7 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi
} }
private void indent() { private void indent() {
this.builder.append(" ".repeat(Math.max(0, this.indent))); this.builder.append(" ".repeat(Math.max(0, this.indent)));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -80,7 +80,7 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi
} }
private void indent() { private void indent() {
this.builder.append(" ".repeat(Math.max(0, this.indent))); this.builder.append(" ".repeat(Math.max(0, this.indent)));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -59,7 +59,7 @@ public abstract class AbstractSockJsMessageCodec implements SockJsMessageCodec {
if (isSockJsSpecialChar(c)) { if (isSockJsSpecialChar(c)) {
result.append('\\').append('u'); result.append('\\').append('u');
String hex = Integer.toHexString(c).toLowerCase(); String hex = Integer.toHexString(c).toLowerCase();
result.append("0".repeat(Math.max(0, (4 - hex.length())))); result.append("0".repeat(Math.max(0, (4 - hex.length()))));
result.append(hex); result.append(hex);
} }
else { else {