Skip to content

Commit d40ae31

Browse files
committed
Touch-ups and naming things
1 parent 3086e45 commit d40ae31

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

junit-platform-engine/src/main/java/org/junit/platform/engine/support/store/NamespacedHierarchicalStore.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,16 @@ public void close() {
214214
public <K, V extends @Nullable Object> @Nullable Object getOrComputeIfAbsent(N namespace, K key,
215215
Function<? super K, ? extends V> defaultCreator) {
216216
Preconditions.notNull(defaultCreator, "defaultCreator must not be null");
217-
CompositeKey<N> compositeKey = new CompositeKey<>(namespace, key);
218-
StoredValue storedValue = getStoredValue(compositeKey);
219-
if (storedValue != null) {
220-
return storedValue.evaluate();
217+
var compositeKey = new CompositeKey<>(namespace, key);
218+
var currentStoredValue = getStoredValue(compositeKey);
219+
if (currentStoredValue != null) {
220+
return currentStoredValue.evaluate();
221221
}
222222
var candidateStoredValue = newStoredSuppliedNullableValue(() -> {
223223
rejectIfClosed();
224224
return defaultCreator.apply(key);
225225
});
226-
var newStoredValue = this.storedValues.compute(compositeKey, //
226+
var storedValue = this.storedValues.compute(compositeKey, //
227227
(__, oldStoredValue) -> {
228228
// guard against race conditions, repeated from getStoredValue
229229
// this filters out failures inserted by computeIfAbsent
@@ -235,10 +235,10 @@ public void close() {
235235
});
236236

237237
// Only the caller that created the candidateStoredValue may run it
238-
if (candidateStoredValue.equals(newStoredValue)) {
239-
candidateStoredValue.run();
238+
if (candidateStoredValue.equals(storedValue)) {
239+
return candidateStoredValue.execute();
240240
}
241-
return requireNonNull(newStoredValue.evaluate());
241+
return storedValue.evaluate();
242242
}
243243

244244
/**
@@ -259,17 +259,17 @@ public void close() {
259259
@API(status = MAINTAINED, since = "6.0")
260260
public <K, V> Object computeIfAbsent(N namespace, K key, Function<? super K, ? extends V> defaultCreator) {
261261
Preconditions.notNull(defaultCreator, "defaultCreator must not be null");
262-
CompositeKey<N> compositeKey = new CompositeKey<>(namespace, key);
263-
StoredValue storedValue = getStoredValue(compositeKey);
264-
var result = StoredValue.evaluateIfNotNull(storedValue);
262+
var compositeKey = new CompositeKey<>(namespace, key);
263+
var currentStoredValue = getStoredValue(compositeKey);
264+
var result = StoredValue.evaluateIfNotNull(currentStoredValue);
265265
if (result != null) {
266266
return result;
267267
}
268268
var candidateStoredValue = newStoredSuppliedValue(() -> {
269269
rejectIfClosed();
270270
return Preconditions.notNull(defaultCreator.apply(key), "defaultCreator must not return null");
271271
});
272-
var newStoredValue = this.storedValues.compute(compositeKey, (__, oldStoredValue) -> {
272+
var storedValue = storedValues.compute(compositeKey, (__, oldStoredValue) -> {
273273
// guard against race conditions
274274
// computeIfAbsent replaces both null and absent values
275275
if (StoredValue.evaluateIfNotNull(oldStoredValue) != null) {
@@ -281,13 +281,12 @@ public <K, V> Object computeIfAbsent(N namespace, K key, Function<? super K, ? e
281281

282282
// Only the caller that created the candidateStoredValue may run it
283283
// and see the exception.
284-
if (candidateStoredValue.equals(newStoredValue)) {
285-
candidateStoredValue.run();
286-
return candidateStoredValue.getOrThrow();
284+
if (candidateStoredValue.equals(storedValue)) {
285+
return candidateStoredValue.execute();
287286
}
288287
// In a race condition either put, getOrComputeIfAbsent, or another
289-
// computeIfAbsent call put the value in the store
290-
return requireNonNull(newStoredValue.evaluate());
288+
// computeIfAbsent call put a non-null value in the store
289+
return requireNonNull(storedValue.evaluate());
291290
}
292291

293292
/**
@@ -532,8 +531,10 @@ public boolean isPresent() {
532531
return true;
533532
}
534533

535-
void run() {
534+
@Nullable
535+
Object execute() {
536536
delegate.run();
537+
return delegate.getOrThrow();
537538
}
538539

539540
@Override
@@ -564,11 +565,8 @@ public boolean isPresent() {
564565
return evaluate() != null;
565566
}
566567

567-
void run() {
568+
Object execute() {
568569
delegate.run();
569-
}
570-
571-
Object getOrThrow() {
572570
// Delegate does not produce null
573571
return requireNonNull(delegate.getOrThrow());
574572
}

0 commit comments

Comments
 (0)