Skip to content

Commit 59c4753

Browse files
authored
Merge pull request #1467 from kazuki43zoo/polishing
Polishing codes
2 parents 0893fe6 + d5441c5 commit 59c4753

File tree

7 files changed

+17
-28
lines changed

7 files changed

+17
-28
lines changed

src/main/java/org/apache/ibatis/builder/xml/XMLIncludeTransformer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.util.HashMap;
1919
import java.util.Map;
20+
import java.util.Optional;
2021
import java.util.Properties;
2122

2223
import org.apache.ibatis.builder.BuilderException;
@@ -45,9 +46,7 @@ public XMLIncludeTransformer(Configuration configuration, MapperBuilderAssistant
4546
public void applyIncludes(Node source) {
4647
Properties variablesContext = new Properties();
4748
Properties configurationVariables = configuration.getVariables();
48-
if (configurationVariables != null) {
49-
variablesContext.putAll(configurationVariables);
50-
}
49+
Optional.ofNullable(configurationVariables).ifPresent(variablesContext::putAll);
5150
applyIncludes(source, variablesContext, false);
5251
}
5352

src/main/java/org/apache/ibatis/logging/jdbc/BaseJdbcLogger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public abstract class BaseJdbcLogger {
4848
private final List<Object> columnNames = new ArrayList<>();
4949
private final List<Object> columnValues = new ArrayList<>();
5050

51-
protected Log statementLog;
52-
protected int queryStack;
51+
protected final Log statementLog;
52+
protected final int queryStack;
5353

5454
/*
5555
* Default constructor

src/main/java/org/apache/ibatis/logging/jdbc/ResultSetLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*/
3939
public final class ResultSetLogger extends BaseJdbcLogger implements InvocationHandler {
4040

41-
private static Set<Integer> BLOB_TYPES = new HashSet<>();
41+
private static final Set<Integer> BLOB_TYPES = new HashSet<>();
4242
private boolean first = true;
4343
private int rows;
4444
private final ResultSet rs;

src/main/java/org/apache/ibatis/reflection/ParamNameUtil.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2018 the original author or authors.
2+
* Copyright 2009-2019 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.
@@ -19,8 +19,9 @@
1919
import java.lang.reflect.Executable;
2020
import java.lang.reflect.Method;
2121
import java.lang.reflect.Parameter;
22-
import java.util.ArrayList;
22+
import java.util.Arrays;
2323
import java.util.List;
24+
import java.util.stream.Collectors;
2425

2526
public class ParamNameUtil {
2627
public static List<String> getParamNames(Method method) {
@@ -32,12 +33,7 @@ public static List<String> getParamNames(Constructor<?> constructor) {
3233
}
3334

3435
private static List<String> getParameterNames(Executable executable) {
35-
final List<String> names = new ArrayList<>();
36-
final Parameter[] params = executable.getParameters();
37-
for (Parameter param : params) {
38-
names.add(param.getName());
39-
}
40-
return names;
36+
return Arrays.stream(executable.getParameters()).map(Parameter::getName).collect(Collectors.toList());
4137
}
4238

4339
private ParamNameUtil() {

src/main/java/org/apache/ibatis/reflection/Reflector.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class Reflector {
4848

4949
private final Class<?> type;
5050
private final String[] readablePropertyNames;
51-
private final String[] writeablePropertyNames;
51+
private final String[] writablePropertyNames;
5252
private final Map<String, Invoker> setMethods = new HashMap<>();
5353
private final Map<String, Invoker> getMethods = new HashMap<>();
5454
private final Map<String, Class<?>> setTypes = new HashMap<>();
@@ -64,11 +64,11 @@ public Reflector(Class<?> clazz) {
6464
addSetMethods(clazz);
6565
addFields(clazz);
6666
readablePropertyNames = getMethods.keySet().toArray(new String[getMethods.keySet().size()]);
67-
writeablePropertyNames = setMethods.keySet().toArray(new String[setMethods.keySet().size()]);
67+
writablePropertyNames = setMethods.keySet().toArray(new String[setMethods.keySet().size()]);
6868
for (String propName : readablePropertyNames) {
6969
caseInsensitivePropertyMap.put(propName.toUpperCase(Locale.ENGLISH), propName);
7070
}
71-
for (String propName : writeablePropertyNames) {
71+
for (String propName : writablePropertyNames) {
7272
caseInsensitivePropertyMap.put(propName.toUpperCase(Locale.ENGLISH), propName);
7373
}
7474
}
@@ -440,7 +440,7 @@ public String[] getGetablePropertyNames() {
440440
* @return The array
441441
*/
442442
public String[] getSetablePropertyNames() {
443-
return writeablePropertyNames;
443+
return writablePropertyNames;
444444
}
445445

446446
/**

src/main/java/org/apache/ibatis/scripting/xmltags/DynamicSqlSource.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2017 the original author or authors.
2+
* Copyright 2009-2019 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.
@@ -15,8 +15,6 @@
1515
*/
1616
package org.apache.ibatis.scripting.xmltags;
1717

18-
import java.util.Map;
19-
2018
import org.apache.ibatis.builder.SqlSourceBuilder;
2119
import org.apache.ibatis.mapping.BoundSql;
2220
import org.apache.ibatis.mapping.SqlSource;
@@ -43,9 +41,7 @@ public BoundSql getBoundSql(Object parameterObject) {
4341
Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
4442
SqlSource sqlSource = sqlSourceParser.parse(context.getSql(), parameterType, context.getBindings());
4543
BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
46-
for (Map.Entry<String, Object> entry : context.getBindings().entrySet()) {
47-
boundSql.setAdditionalParameter(entry.getKey(), entry.getValue());
48-
}
44+
context.getBindings().forEach(boundSql::setAdditionalParameter);
4945
return boundSql;
5046
}
5147

src/main/java/org/apache/ibatis/scripting/xmltags/MixedSqlNode.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2017 the original author or authors.
2+
* Copyright 2009-2019 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.
@@ -29,9 +29,7 @@ public MixedSqlNode(List<SqlNode> contents) {
2929

3030
@Override
3131
public boolean apply(DynamicContext context) {
32-
for (SqlNode sqlNode : contents) {
33-
sqlNode.apply(context);
34-
}
32+
contents.forEach(node -> node.apply(context));
3533
return true;
3634
}
3735
}

0 commit comments

Comments
 (0)