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
|
@Override
|
||||||
public Object get(String name, ObjectFactory<?> objectFactory) {
|
public Object get(String name, ObjectFactory<?> objectFactory) {
|
||||||
Map<String, Object> scope = this.threadScope.get();
|
Map<String, Object> scope = this.threadScope.get();
|
||||||
Object scopedObject = scope.get(name);
|
return scope.computeIfAbsent(name, k -> objectFactory.getObject());
|
||||||
if (scopedObject == null) {
|
|
||||||
scopedObject = objectFactory.getObject();
|
|
||||||
scope.put(name, scopedObject);
|
|
||||||
}
|
|
||||||
return scopedObject;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -50,12 +50,7 @@ public class SimpleTransactionScope implements Scope {
|
||||||
TransactionSynchronizationManager.registerSynchronization(new CleanupSynchronization(scopedObjects));
|
TransactionSynchronizationManager.registerSynchronization(new CleanupSynchronization(scopedObjects));
|
||||||
TransactionSynchronizationManager.bindResource(this, scopedObjects);
|
TransactionSynchronizationManager.bindResource(this, scopedObjects);
|
||||||
}
|
}
|
||||||
Object scopedObject = scopedObjects.scopedInstances.get(name);
|
return scopedObjects.scopedInstances.computeIfAbsent(name, k -> objectFactory.getObject());
|
||||||
if (scopedObject == null) {
|
|
||||||
scopedObject = objectFactory.getObject();
|
|
||||||
scopedObjects.scopedInstances.put(name, scopedObject);
|
|
||||||
}
|
|
||||||
return scopedObject;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue