Skip to content

Commit ab240f5

Browse files
a.yazychyansbrannen
a.yazychyan
authored andcommitted
Use String.repeat() and pattern matching instanceof
Closes gh-27834
1 parent 7021eb5 commit ab240f5

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgumentTypePreparedStatementSetter.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ public void setValues(PreparedStatement ps) throws SQLException {
6161
if (this.args != null && this.argTypes != null) {
6262
for (int i = 0; i < this.args.length; i++) {
6363
Object arg = this.args[i];
64-
if (arg instanceof Collection && this.argTypes[i] != Types.ARRAY) {
65-
Collection<?> entries = (Collection<?>) arg;
64+
if (arg instanceof Collection<?> entries && this.argTypes[i] != Types.ARRAY) {
6665
for (Object entry : entries) {
6766
if (entry instanceof Object[] valueArray) {
6867
for (Object argValue : valueArray) {

spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,7 @@ public void setValues(PreparedStatement ps) throws SQLException {
265265
}
266266
declaredParameter = declaredParameters.get(i);
267267
}
268-
if (in instanceof Iterable && declaredParameter.getSqlType() != Types.ARRAY) {
269-
Iterable<?> entries = (Iterable<?>) in;
268+
if (in instanceof Iterable<?> entries && declaredParameter.getSqlType() != Types.ARRAY) {
270269
for (Object entry : entries) {
271270
if (entry instanceof Object[] valueArray) {
272271
for (Object argValue : valueArray) {

spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/AbstractDataFieldMaxValueIncrementer.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -133,12 +133,7 @@ public String nextStringValue() throws DataAccessException {
133133
String s = Long.toString(getNextKey());
134134
int len = s.length();
135135
if (len < this.paddingLength) {
136-
StringBuilder sb = new StringBuilder(this.paddingLength);
137-
for (int i = 0; i < this.paddingLength - len; i++) {
138-
sb.append('0');
139-
}
140-
sb.append(s);
141-
s = sb.toString();
136+
s = "0".repeat(this.paddingLength - len) + s;
142137
}
143138
return s;
144139
}

0 commit comments

Comments
 (0)