Use Map::computeIfAbsent to simplify scope implementations
Closes gh-25038
This commit is contained in:
parent
f5d011cb82
commit
50a4fdac6e
|
@ -67,12 +67,7 @@ public class SimpleThreadScope implements Scope {
|
|||
@Override
|
||||
public Object get(String name, ObjectFactory<?> objectFactory) {
|
||||
Map<String, Object> scope = this.threadScope.get();
|
||||
Object scopedObject = scope.get(name);
|
||||
if (scopedObject == null) {
|
||||
scopedObject = objectFactory.getObject();
|
||||
scope.put(name, scopedObject);
|
||||
}
|
||||
return scopedObject;
|
||||
return scope.computeIfAbsent(name, k -> objectFactory.getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -50,12 +50,7 @@ public class SimpleTransactionScope implements Scope {
|
|||
TransactionSynchronizationManager.registerSynchronization(new CleanupSynchronization(scopedObjects));
|
||||
TransactionSynchronizationManager.bindResource(this, scopedObjects);
|
||||
}
|
||||
Object scopedObject = scopedObjects.scopedInstances.get(name);
|
||||
if (scopedObject == null) {
|
||||
scopedObject = objectFactory.getObject();
|
||||
scopedObjects.scopedInstances.put(name, scopedObject);
|
||||
}
|
||||
return scopedObject;
|
||||
return scopedObjects.scopedInstances.computeIfAbsent(name, k -> objectFactory.getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue