Browse Source

Use String.repeat() and pattern matching instanceof

Closes gh-27834
pull/27884/head
a.yazychyan 4 years ago committed by Sam Brannen
parent
commit
ab240f5d8e
  1. 3
      spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgumentTypePreparedStatementSetter.java
  2. 3
      spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java
  3. 9
      spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/AbstractDataFieldMaxValueIncrementer.java

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

@ -61,8 +61,7 @@ public class ArgumentTypePreparedStatementSetter implements PreparedStatementSet @@ -61,8 +61,7 @@ public class ArgumentTypePreparedStatementSetter implements PreparedStatementSet
if (this.args != null && this.argTypes != null) {
for (int i = 0; i < this.args.length; i++) {
Object arg = this.args[i];
if (arg instanceof Collection && this.argTypes[i] != Types.ARRAY) {
Collection<?> entries = (Collection<?>) arg;
if (arg instanceof Collection<?> entries && this.argTypes[i] != Types.ARRAY) {
for (Object entry : entries) {
if (entry instanceof Object[] valueArray) {
for (Object argValue : valueArray) {

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

@ -265,8 +265,7 @@ public class PreparedStatementCreatorFactory { @@ -265,8 +265,7 @@ public class PreparedStatementCreatorFactory {
}
declaredParameter = declaredParameters.get(i);
}
if (in instanceof Iterable && declaredParameter.getSqlType() != Types.ARRAY) {
Iterable<?> entries = (Iterable<?>) in;
if (in instanceof Iterable<?> entries && declaredParameter.getSqlType() != Types.ARRAY) {
for (Object entry : entries) {
if (entry instanceof Object[] valueArray) {
for (Object argValue : valueArray) {

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2021 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.
@ -133,12 +133,7 @@ public abstract class AbstractDataFieldMaxValueIncrementer implements DataFieldM @@ -133,12 +133,7 @@ public abstract class AbstractDataFieldMaxValueIncrementer implements DataFieldM
String s = Long.toString(getNextKey());
int len = s.length();
if (len < this.paddingLength) {
StringBuilder sb = new StringBuilder(this.paddingLength);
for (int i = 0; i < this.paddingLength - len; i++) {
sb.append('0');
}
sb.append(s);
s = sb.toString();
s = "0".repeat(this.paddingLength - len) + s;
}
return s;
}

Loading…
Cancel
Save