Browse Source

Polish "Use String.repeat instead of explicit cycle"

See gh-31802
pull/31867/head
Stéphane Nicoll 2 years ago
parent
commit
d0574197ea
  1. 4
      spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java
  2. 4
      spring-core/src/main/java/org/springframework/asm/Type.java
  3. 4
      spring-core/src/main/java/org/springframework/cglib/core/ReflectUtils.java
  4. 4
      spring-web/src/main/java/org/springframework/web/util/pattern/PatternParseException.java
  5. 4
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ToStringVisitor.java
  6. 4
      spring-webmvc/src/main/java/org/springframework/web/servlet/function/ToStringVisitor.java
  7. 4
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/AbstractSockJsMessageCodec.java

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

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -98,7 +98,7 @@ public final class ParseState { @@ -98,7 +98,7 @@ public final class ParseState {
for (ParseState.Entry entry : this.state) {
if (i > 0) {
sb.append('\n');
sb.append("\t".repeat(i));
sb.append("\t".repeat(i));
sb.append("-> ");
}
sb.append(entry);

4
spring-core/src/main/java/org/springframework/asm/Type.java

@ -462,7 +462,9 @@ public final class Type { @@ -462,7 +462,9 @@ public final class Type {
return "double";
case ARRAY:
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();
case OBJECT:
case INTERNAL:

4
spring-core/src/main/java/org/springframework/cglib/core/ReflectUtils.java

@ -218,7 +218,9 @@ public class ReflectUtils { @@ -218,7 +218,9 @@ public class ReflectUtils {
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);
String prefix = (dimensions > 0) ? brackets + "L" : "";

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

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -68,7 +68,7 @@ public class PatternParseException extends IllegalArgumentException { @@ -68,7 +68,7 @@ public class PatternParseException extends IllegalArgumentException {
public String toDetailedString() {
StringBuilder sb = new StringBuilder();
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(getMessage());
return sb.toString();

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

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -81,7 +81,7 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi @@ -81,7 +81,7 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi
}
private void indent() {
this.builder.append(" ".repeat(Math.max(0, this.indent)));
this.builder.append(" ".repeat(Math.max(0, this.indent)));
}

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

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -80,7 +80,7 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi @@ -80,7 +80,7 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi
}
private void indent() {
this.builder.append(" ".repeat(Math.max(0, this.indent)));
this.builder.append(" ".repeat(Math.max(0, this.indent)));
}

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

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -59,7 +59,7 @@ public abstract class AbstractSockJsMessageCodec implements SockJsMessageCodec { @@ -59,7 +59,7 @@ public abstract class AbstractSockJsMessageCodec implements SockJsMessageCodec {
if (isSockJsSpecialChar(c)) {
result.append('\\').append('u');
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);
}
else {

Loading…
Cancel
Save