Skip to content

Commit d5441c5

Browse files
committed
Change to use Stream API, Optional API and lambda expression If possible
1 parent 70cba26 commit d5441c5

File tree

4 files changed

+10
-21
lines changed

4 files changed

+10
-21
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/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/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)