Skip to content

Commit d74d0bd

Browse files
authored
Merge pull request #1284 from wuwen5/minor-code-clean
minor code clean-up.
2 parents fd7fc5f + e67eac9 commit d74d0bd

File tree

70 files changed

+234
-320
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+234
-320
lines changed

src/main/java/org/apache/ibatis/binding/MapperProxy.java

Lines changed: 2 additions & 7 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-2018 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.
@@ -60,12 +60,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
6060
}
6161

6262
private MapperMethod cachedMapperMethod(Method method) {
63-
MapperMethod mapperMethod = methodCache.get(method);
64-
if (mapperMethod == null) {
65-
mapperMethod = new MapperMethod(mapperInterface, method, sqlSession.getConfiguration());
66-
methodCache.put(method, mapperMethod);
67-
}
68-
return mapperMethod;
63+
return methodCache.computeIfAbsent(method, k -> new MapperMethod(mapperInterface, method, sqlSession.getConfiguration()));
6964
}
7065

7166
@UsesJava7

src/main/java/org/apache/ibatis/binding/MapperProxyFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2015 the original author or authors.
2+
* Copyright 2009-2018 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.
@@ -28,7 +28,7 @@
2828
public class MapperProxyFactory<T> {
2929

3030
private final Class<T> mapperInterface;
31-
private final Map<Method, MapperMethod> methodCache = new ConcurrentHashMap<Method, MapperMethod>();
31+
private final Map<Method, MapperMethod> methodCache = new ConcurrentHashMap<>();
3232

3333
public MapperProxyFactory(Class<T> mapperInterface) {
3434
this.mapperInterface = mapperInterface;
@@ -48,7 +48,7 @@ protected T newInstance(MapperProxy<T> mapperProxy) {
4848
}
4949

5050
public T newInstance(SqlSession sqlSession) {
51-
final MapperProxy<T> mapperProxy = new MapperProxy<T>(sqlSession, mapperInterface, methodCache);
51+
final MapperProxy<T> mapperProxy = new MapperProxy<>(sqlSession, mapperInterface, methodCache);
5252
return newInstance(mapperProxy);
5353
}
5454

src/main/java/org/apache/ibatis/binding/MapperRegistry.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2015 the original author or authors.
2+
* Copyright 2009-2018 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.
@@ -34,7 +34,7 @@
3434
public class MapperRegistry {
3535

3636
private final Configuration config;
37-
private final Map<Class<?>, MapperProxyFactory<?>> knownMappers = new HashMap<Class<?>, MapperProxyFactory<?>>();
37+
private final Map<Class<?>, MapperProxyFactory<?>> knownMappers = new HashMap<>();
3838

3939
public MapperRegistry(Configuration config) {
4040
this.config = config;
@@ -90,7 +90,7 @@ public Collection<Class<?>> getMappers() {
9090
* @since 3.2.2
9191
*/
9292
public void addMappers(String packageName, Class<?> superType) {
93-
ResolverUtil<Class<?>> resolverUtil = new ResolverUtil<Class<?>>();
93+
ResolverUtil<Class<?>> resolverUtil = new ResolverUtil<>();
9494
resolverUtil.find(new ResolverUtil.IsA(superType), packageName);
9595
Set<Class<? extends Class<?>>> mapperSet = resolverUtil.getClasses();
9696
for (Class<?> mapperClass : mapperSet) {

src/main/java/org/apache/ibatis/builder/BaseBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected Integer integerValueOf(String value, Integer defaultValue) {
6060

6161
protected Set<String> stringSetValueOf(String value, String defaultValue) {
6262
value = (value == null ? defaultValue : value);
63-
return new HashSet<String>(Arrays.asList(value.split(",")));
63+
return new HashSet<>(Arrays.asList(value.split(",")));
6464
}
6565

6666
protected JdbcType resolveJdbcType(String alias) {

src/main/java/org/apache/ibatis/builder/MapperBuilderAssistant.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public ResultMap addResultMap(
188188
throw new IncompleteElementException("Could not find a parent resultmap with id '" + extend + "'");
189189
}
190190
ResultMap resultMap = configuration.getResultMap(extend);
191-
List<ResultMapping> extendedResultMappings = new ArrayList<ResultMapping>(resultMap.getResultMappings());
191+
List<ResultMapping> extendedResultMappings = new ArrayList<>(resultMap.getResultMappings());
192192
extendedResultMappings.removeAll(resultMappings);
193193
// Remove parent constructor if this resultMap declares a constructor.
194194
boolean declaresConstructor = false;
@@ -237,7 +237,7 @@ public Discriminator buildDiscriminator(
237237
null,
238238
null,
239239
false);
240-
Map<String, String> namespaceDiscriminatorMap = new HashMap<String, String>();
240+
Map<String, String> namespaceDiscriminatorMap = new HashMap<>();
241241
for (Map.Entry<String, String> e : discriminatorMap.entrySet()) {
242242
String resultMap = e.getValue();
243243
resultMap = applyCurrentNamespace(resultMap, true);
@@ -320,7 +320,7 @@ private ParameterMap getStatementParameterMap(
320320
throw new IncompleteElementException("Could not find parameter map " + parameterMapName, e);
321321
}
322322
} else if (parameterTypeClass != null) {
323-
List<ParameterMapping> parameterMappings = new ArrayList<ParameterMapping>();
323+
List<ParameterMapping> parameterMappings = new ArrayList<>();
324324
parameterMap = new ParameterMap.Builder(
325325
configuration,
326326
statementId + "-Inline",
@@ -336,7 +336,7 @@ private List<ResultMap> getStatementResultMaps(
336336
String statementId) {
337337
resultMap = applyCurrentNamespace(resultMap, true);
338338

339-
List<ResultMap> resultMaps = new ArrayList<ResultMap>();
339+
List<ResultMap> resultMaps = new ArrayList<>();
340340
if (resultMap != null) {
341341
String[] resultMapNames = resultMap.split(",");
342342
for (String resultMapName : resultMapNames) {
@@ -392,7 +392,7 @@ public ResultMapping buildResultMapping(
392392
}
393393

394394
private Set<String> parseMultipleColumnNames(String columnName) {
395-
Set<String> columns = new HashSet<String>();
395+
Set<String> columns = new HashSet<>();
396396
if (columnName != null) {
397397
if (columnName.indexOf(',') > -1) {
398398
StringTokenizer parser = new StringTokenizer(columnName, "{}, ", false);
@@ -408,7 +408,7 @@ private Set<String> parseMultipleColumnNames(String columnName) {
408408
}
409409

410410
private List<ResultMapping> parseCompositeColumnName(String columnName) {
411-
List<ResultMapping> composites = new ArrayList<ResultMapping>();
411+
List<ResultMapping> composites = new ArrayList<>();
412412
if (columnName != null && (columnName.indexOf('=') > -1 || columnName.indexOf(',') > -1)) {
413413
StringTokenizer parser = new StringTokenizer(columnName, "{}=, ", false);
414414
while (parser.hasMoreTokens()) {

src/main/java/org/apache/ibatis/builder/SqlSourceBuilder.java

Lines changed: 2 additions & 2 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-2018 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.
@@ -48,7 +48,7 @@ public SqlSource parse(String originalSql, Class<?> parameterType, Map<String, O
4848

4949
private static class ParameterMappingTokenHandler extends BaseBuilder implements TokenHandler {
5050

51-
private List<ParameterMapping> parameterMappings = new ArrayList<ParameterMapping>();
51+
private List<ParameterMapping> parameterMappings = new ArrayList<>();
5252
private Class<?> parameterType;
5353
private MetaObject metaParameters;
5454

src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ private String generateResultMapName(Method method) {
245245
}
246246

247247
private void applyResultMap(String resultMapId, Class<?> returnType, Arg[] args, Result[] results, TypeDiscriminator discriminator) {
248-
List<ResultMapping> resultMappings = new ArrayList<ResultMapping>();
248+
List<ResultMapping> resultMappings = new ArrayList<>();
249249
applyConstructorArgs(args, returnType, resultMappings);
250250
applyResults(results, returnType, resultMappings);
251251
Discriminator disc = applyDiscriminator(resultMapId, returnType, discriminator);
@@ -258,7 +258,7 @@ private void createDiscriminatorResultMaps(String resultMapId, Class<?> resultTy
258258
if (discriminator != null) {
259259
for (Case c : discriminator.cases()) {
260260
String caseResultMapId = resultMapId + "-" + c.value();
261-
List<ResultMapping> resultMappings = new ArrayList<ResultMapping>();
261+
List<ResultMapping> resultMappings = new ArrayList<>();
262262
// issue #136
263263
applyConstructorArgs(c.constructArgs(), resultType, resultMappings);
264264
applyResults(c.results(), resultType, resultMappings);
@@ -277,7 +277,7 @@ private Discriminator applyDiscriminator(String resultMapId, Class<?> resultType
277277
Class<? extends TypeHandler<?>> typeHandler = (Class<? extends TypeHandler<?>>)
278278
(discriminator.typeHandler() == UnknownTypeHandler.class ? null : discriminator.typeHandler());
279279
Case[] cases = discriminator.cases();
280-
Map<String, String> discriminatorMap = new HashMap<String, String>();
280+
Map<String, String> discriminatorMap = new HashMap<>();
281281
for (Case c : cases) {
282282
String value = c.value();
283283
String caseResultMapId = resultMapId + "-" + value;
@@ -537,7 +537,7 @@ private Class<? extends Annotation> chooseAnnotationType(Method method, Set<Clas
537537

538538
private void applyResults(Result[] results, Class<?> resultType, List<ResultMapping> resultMappings) {
539539
for (Result result : results) {
540-
List<ResultFlag> flags = new ArrayList<ResultFlag>();
540+
List<ResultFlag> flags = new ArrayList<>();
541541
if (result.id()) {
542542
flags.add(ResultFlag.ID);
543543
}
@@ -593,7 +593,7 @@ private boolean hasNestedSelect(Result result) {
593593

594594
private void applyConstructorArgs(Arg[] args, Class<?> resultType, List<ResultMapping> resultMappings) {
595595
for (Arg arg : args) {
596-
List<ResultFlag> flags = new ArrayList<ResultFlag>();
596+
List<ResultFlag> flags = new ArrayList<>();
597597
flags.add(ResultFlag.CONSTRUCTOR);
598598
if (arg.id()) {
599599
flags.add(ResultFlag.ID);

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

Lines changed: 2 additions & 2 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-2018 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.
@@ -120,7 +120,7 @@ private Properties getVariablesContext(Node node, Properties inheritedVariablesC
120120
// Replace variables inside
121121
String value = PropertyParser.parse(getStringAttribute(n, "value"), inheritedVariablesContext);
122122
if (declaredProperties == null) {
123-
declaredProperties = new HashMap<String, String>();
123+
declaredProperties = new HashMap<>();
124124
}
125125
if (declaredProperties.put(name, value) != null) {
126126
throw new BuilderException("Variable " + name + " defined twice in the same include definition");

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private void parameterMapElement(List<XNode> list) throws Exception {
217217
String type = parameterMapNode.getStringAttribute("type");
218218
Class<?> parameterClass = resolveClass(type);
219219
List<XNode> parameterNodes = parameterMapNode.evalNodes("parameter");
220-
List<ParameterMapping> parameterMappings = new ArrayList<ParameterMapping>();
220+
List<ParameterMapping> parameterMappings = new ArrayList<>();
221221
for (XNode parameterNode : parameterNodes) {
222222
String property = parameterNode.getStringAttribute("property");
223223
String javaType = parameterNode.getStringAttribute("javaType");
@@ -264,7 +264,7 @@ private ResultMap resultMapElement(XNode resultMapNode, List<ResultMapping> addi
264264
Boolean autoMapping = resultMapNode.getBooleanAttribute("autoMapping");
265265
Class<?> typeClass = resolveClass(type);
266266
Discriminator discriminator = null;
267-
List<ResultMapping> resultMappings = new ArrayList<ResultMapping>();
267+
List<ResultMapping> resultMappings = new ArrayList<>();
268268
resultMappings.addAll(additionalResultMappings);
269269
List<XNode> resultChildren = resultMapNode.getChildren();
270270
for (XNode resultChild : resultChildren) {
@@ -273,7 +273,7 @@ private ResultMap resultMapElement(XNode resultMapNode, List<ResultMapping> addi
273273
} else if ("discriminator".equals(resultChild.getName())) {
274274
discriminator = processDiscriminatorElement(resultChild, typeClass, resultMappings);
275275
} else {
276-
List<ResultFlag> flags = new ArrayList<ResultFlag>();
276+
List<ResultFlag> flags = new ArrayList<>();
277277
if ("id".equals(resultChild.getName())) {
278278
flags.add(ResultFlag.ID);
279279
}
@@ -292,7 +292,7 @@ private ResultMap resultMapElement(XNode resultMapNode, List<ResultMapping> addi
292292
private void processConstructorElement(XNode resultChild, Class<?> resultType, List<ResultMapping> resultMappings) throws Exception {
293293
List<XNode> argChildren = resultChild.getChildren();
294294
for (XNode argChild : argChildren) {
295-
List<ResultFlag> flags = new ArrayList<ResultFlag>();
295+
List<ResultFlag> flags = new ArrayList<>();
296296
flags.add(ResultFlag.CONSTRUCTOR);
297297
if ("idArg".equals(argChild.getName())) {
298298
flags.add(ResultFlag.ID);
@@ -310,7 +310,7 @@ private Discriminator processDiscriminatorElement(XNode context, Class<?> result
310310
@SuppressWarnings("unchecked")
311311
Class<? extends TypeHandler<?>> typeHandlerClass = (Class<? extends TypeHandler<?>>) resolveClass(typeHandler);
312312
JdbcType jdbcTypeEnum = resolveJdbcType(jdbcType);
313-
Map<String, String> discriminatorMap = new HashMap<String, String>();
313+
Map<String, String> discriminatorMap = new HashMap<>();
314314
for (XNode caseChild : context.getChildren()) {
315315
String value = caseChild.getStringAttribute("value");
316316
String resultMap = caseChild.getStringAttribute("resultMap", processNestedResultMappings(caseChild, resultMappings));

src/main/java/org/apache/ibatis/cache/CacheKey.java

Lines changed: 3 additions & 3 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-2018 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.
@@ -44,7 +44,7 @@ public CacheKey() {
4444
this.hashcode = DEFAULT_HASHCODE;
4545
this.multiplier = DEFAULT_MULTIPLYER;
4646
this.count = 0;
47-
this.updateList = new ArrayList<Object>();
47+
this.updateList = new ArrayList<>();
4848
}
4949

5050
public CacheKey(Object[] objects) {
@@ -122,7 +122,7 @@ public String toString() {
122122
@Override
123123
public CacheKey clone() throws CloneNotSupportedException {
124124
CacheKey clonedCacheKey = (CacheKey) super.clone();
125-
clonedCacheKey.updateList = new ArrayList<Object>(updateList);
125+
clonedCacheKey.updateList = new ArrayList<>(updateList);
126126
return clonedCacheKey;
127127
}
128128

0 commit comments

Comments
 (0)