This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new e0a574c Replace unnecessary guava joiner (#11763)
e0a574c is described below
commit e0a574c44d83382639f31f053465db078552ce42
Author: 吴伟杰 <[email protected]>
AuthorDate: Wed Aug 11 18:04:55 2021 +0800
Replace unnecessary guava joiner (#11763)
* Replace unnecessary joiner
* Refactor String concatenation
* Rename variable
---
.../algorithm/sharding/inline/InlineExpressionParser.java | 3 +--
.../infra/config/datasource/DataSourceConfiguration.java | 3 +--
.../infra/rewrite/sql/token/pojo/generic/InsertColumnsToken.java | 9 +++++++--
.../infra/rewrite/sql/token/pojo/generic/InsertValue.java | 9 ++++-----
.../transaction/xa/jta/datasource/swapper/DataSourceSwapper.java | 5 ++---
5 files changed, 15 insertions(+), 14 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineExpressionParser.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineExpressionParser.java
index 916760a..590c362 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineExpressionParser.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineExpressionParser.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.sharding.algorithm.sharding.inline;
-import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import com.google.common.collect.Collections2;
import com.google.common.collect.Sets;
@@ -74,7 +73,7 @@ public final class InlineExpressionParser {
* @return closure
*/
public Closure<?> evaluateClosure() {
- return (Closure) evaluate(Joiner.on("").join("{it -> \"",
inlineExpression, "\"}"));
+ return (Closure) evaluate("{it -> \"" + inlineExpression + "\"}");
}
private List<Object> evaluate(final List<String> inlineExpressions) {
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourceConfiguration.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourceConfiguration.java
index ae722e3..30dd124 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourceConfiguration.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourceConfiguration.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.infra.config.datasource;
import com.google.common.base.CaseFormat;
-import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.collect.Sets;
import lombok.Getter;
@@ -150,7 +149,7 @@ public final class DataSourceConfiguration {
}
private Optional<Method> findSetterMethod(final Method[] methods, final
String property) {
- String setterMethodName = Joiner.on("").join(SETTER_PREFIX,
CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, property));
+ String setterMethodName = SETTER_PREFIX +
CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, property);
return Arrays.stream(methods)
.filter(each -> each.getName().equals(setterMethodName) && 1
== each.getParameterTypes().length)
.findFirst();
diff --git
a/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/InsertColumnsToken.java
b/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/InsertColumnsToken.java
index af2aa4c..d7b9992 100644
---
a/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/InsertColumnsToken.java
+++
b/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/InsertColumnsToken.java
@@ -17,11 +17,11 @@
package org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic;
-import com.google.common.base.Joiner;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.Attachable;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
import java.util.List;
+import java.util.StringJoiner;
/**
* Insert columns token.
@@ -37,6 +37,11 @@ public final class InsertColumnsToken extends SQLToken
implements Attachable {
@Override
public String toString() {
- return columns.isEmpty() ? "" : String.format(", %s", Joiner.on(",
").join(columns));
+ if (columns.isEmpty()) {
+ return "";
+ }
+ StringJoiner result = new StringJoiner(", ", ", ", "");
+ columns.forEach(result::add);
+ return result.toString();
}
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/InsertValue.java
b/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/InsertValue.java
index 009dedc..d7a24e3 100644
---
a/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/InsertValue.java
+++
b/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/InsertValue.java
@@ -26,6 +26,7 @@ import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.L
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
import java.util.List;
+import java.util.StringJoiner;
/**
* Insert value.
@@ -38,12 +39,10 @@ public class InsertValue {
@Override
public final String toString() {
- StringBuilder result = new StringBuilder();
- result.append("(");
+ StringJoiner result = new StringJoiner(", ", "(", ")");
for (int i = 0; i < values.size(); i++) {
- result.append(getValue(i)).append(", ");
+ result.add(getValue(i));
}
- result.delete(result.length() - 2, result.length()).append(")");
return result.toString();
}
@@ -53,7 +52,7 @@ public class InsertValue {
return "?";
} else if (expressionSegment instanceof LiteralExpressionSegment) {
Object literals = ((LiteralExpressionSegment)
expressionSegment).getLiterals();
- return literals instanceof String ? String.format("'%s'",
((LiteralExpressionSegment) expressionSegment).getLiterals()) :
literals.toString();
+ return literals instanceof String ? "'" +
((LiteralExpressionSegment) expressionSegment).getLiterals() + "'" :
literals.toString();
} else if (expressionSegment instanceof BinaryOperationExpression) {
return ((BinaryOperationExpression) expressionSegment).getText();
}
diff --git
a/shardingsphere-transaction/shardingsphere-transaction-2pc/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/datasource/swapper/DataSourceSwapper.java
b/shardingsphere-transaction/shardingsphere-transaction-2pc/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/datasource/swapper/DataSourceSwapper.java
index 746a274..72b7435 100644
---
a/shardingsphere-transaction/shardingsphere-transaction-2pc/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/datasource/swapper/DataSourceSwapper.java
+++
b/shardingsphere-transaction/shardingsphere-transaction-2pc/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/datasource/swapper/DataSourceSwapper.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.transaction.xa.jta.datasource.swapper;
import com.google.common.base.CaseFormat;
-import com.google.common.base.Joiner;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
@@ -122,14 +121,14 @@ public final class DataSourceSwapper {
}
private Method findGetterMethod(final DataSource dataSource, final String
propertyName) throws NoSuchMethodException {
- String getterMethodName = Joiner.on("").join(GETTER_PREFIX,
CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, propertyName));
+ String getterMethodName = GETTER_PREFIX +
CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, propertyName);
Method result = dataSource.getClass().getMethod(getterMethodName);
result.setAccessible(true);
return result;
}
private Optional<Method> findSetterMethod(final Method[] methods, final
String property) {
- String setterMethodName = Joiner.on("").join(SETTER_PREFIX,
CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, property));
+ String setterMethodName = SETTER_PREFIX +
CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, property);
return Arrays.stream(methods)
.filter(each -> each.getName().equals(setterMethodName) && 1
== each.getParameterTypes().length)
.findFirst();