Skip to content

Commit f3a2432

Browse files
committed
Remove redundant containsKey invocations, etc.
1 parent d1dca2a commit f3a2432

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/main/java/org/apache/ibatis/executor/resultset/PendingConstructorCreation.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ Collection<Object> initializeCollectionForResultMapping(ObjectFactory objectFact
6464
"Cannot add a collection result to non-collection based resultMapping: " + constructorMapping);
6565
}
6666

67-
final PendingCreationKey creationKey = new PendingCreationKey(constructorMapping);
68-
return linkedCollectionsByKey.computeIfAbsent(creationKey, (k) -> {
67+
return linkedCollectionsByKey.computeIfAbsent(new PendingCreationKey(constructorMapping), k -> {
6968
// this will allow us to verify the types of the collection before creating the final object
70-
linkedCollectionMetaInfo.put(index, new PendingCreationMetaInfo(resultMap.getType(), creationKey));
69+
linkedCollectionMetaInfo.put(index, new PendingCreationMetaInfo(resultMap.getType(), k));
7170

7271
// will be checked before we finally create the object) as we cannot reliably do that here
7372
return (Collection<Object>) objectFactory.create(parameterType);
@@ -77,7 +76,7 @@ Collection<Object> initializeCollectionForResultMapping(ObjectFactory objectFact
7776
void linkCreation(ResultMapping constructorMapping, PendingConstructorCreation pcc) {
7877
final PendingCreationKey creationKey = new PendingCreationKey(constructorMapping);
7978
final List<PendingConstructorCreation> pendingConstructorCreations = linkedCreationsByKey
80-
.computeIfAbsent(creationKey, (k) -> new ArrayList<>());
79+
.computeIfAbsent(creationKey, k -> new ArrayList<>());
8180

8281
if (pendingConstructorCreations.contains(pcc)) {
8382
throw new ExecutorException("Cannot link inner constructor creation with same value, MyBatis internal error!");
@@ -92,13 +91,10 @@ void linkCollectionValue(ResultMapping constructorMapping, Object value) {
9291
return;
9392
}
9493

95-
final PendingCreationKey creationKey = new PendingCreationKey(constructorMapping);
96-
if (!linkedCollectionsByKey.containsKey(creationKey)) {
94+
linkedCollectionsByKey.computeIfAbsent(new PendingCreationKey(constructorMapping), k -> {
9795
throw new ExecutorException("Cannot link collection value for key: " + constructorMapping
9896
+ ", resultMap has not been seen/initialized yet! Mybatis internal error!");
99-
}
100-
101-
linkedCollectionsByKey.get(creationKey).add(value);
97+
}).add(value);
10298
}
10399

104100
@Override
@@ -128,10 +124,10 @@ Object create(ObjectFactory objectFactory) {
128124

129125
// time to finally build this collection
130126
final PendingCreationKey pendingCreationKey = creationMetaInfo.getPendingCreationKey();
131-
if (linkedCreationsByKey.containsKey(pendingCreationKey)) {
127+
final List<PendingConstructorCreation> linkedCreations = linkedCreationsByKey.get(pendingCreationKey);
128+
if (linkedCreations != null) {
132129
@SuppressWarnings("unchecked")
133130
final Collection<Object> emptyCollection = (Collection<Object>) existingArg;
134-
final List<PendingConstructorCreation> linkedCreations = linkedCreationsByKey.get(pendingCreationKey);
135131

136132
for (PendingConstructorCreation linkedCreation : linkedCreations) {
137133
emptyCollection.add(linkedCreation.create(objectFactory));

0 commit comments

Comments
 (0)