Skip to content

Commit d26ed00

Browse files
committed
Small code tweaks on recent PR
1 parent a1e93e4 commit d26ed00

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/main/java/graphql/execution/instrumentation/ChainedInstrumentation.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@ private <T> T chainedInstrument(InstrumentationState state, T input, ChainedInst
9090
}
9191

9292
protected <T> ImmutableList<T> chainedMapAndDropNulls(InstrumentationState state, BiFunction<Instrumentation, InstrumentationState, T> mapper) {
93+
ChainedInstrumentationState chainedInstrumentationState = (ChainedInstrumentationState) state;
9394
ImmutableList.Builder<T> result = ImmutableList.builderWithExpectedSize(instrumentations.size());
9495
for (int i = 0; i < instrumentations.size(); i++) {
9596
Instrumentation instrumentation = instrumentations.get(i);
96-
InstrumentationState specificState = ((ChainedInstrumentationState) state).getState(i);
97+
InstrumentationState specificState = chainedInstrumentationState.getState(i);
9798
T value = mapper.apply(instrumentation, specificState);
9899
if (value != null) {
99100
result.add(value);
@@ -102,10 +103,11 @@ protected <T> ImmutableList<T> chainedMapAndDropNulls(InstrumentationState state
102103
return result.build();
103104
}
104105

105-
protected <T> void chainedConsume(InstrumentationState state, BiConsumer<Instrumentation, InstrumentationState> stateConsumer) {
106+
protected void chainedConsume(InstrumentationState state, BiConsumer<Instrumentation, InstrumentationState> stateConsumer) {
107+
ChainedInstrumentationState chainedInstrumentationState = (ChainedInstrumentationState) state;
106108
for (int i = 0; i < instrumentations.size(); i++) {
107109
Instrumentation instrumentation = instrumentations.get(i);
108-
InstrumentationState specificState = ((ChainedInstrumentationState) state).getState(i);
110+
InstrumentationState specificState = chainedInstrumentationState.getState(i);
109111
stateConsumer.accept(instrumentation, specificState);
110112
}
111113
}
@@ -358,7 +360,7 @@ public CompletableFuture<ExecutionResult> instrumentExecutionResult(ExecutionRes
358360
CompletableFuture<List<ExecutionResult>> resultsFuture = Async.eachSequentially(entries, (entry, prevResults) -> {
359361
Instrumentation instrumentation = entry.getKey();
360362
InstrumentationState specificState = entry.getValue();
361-
ExecutionResult lastResult = prevResults.size() > 0 ? prevResults.get(prevResults.size() - 1) : executionResult;
363+
ExecutionResult lastResult = !prevResults.isEmpty() ? prevResults.get(prevResults.size() - 1) : executionResult;
362364
return instrumentation.instrumentExecutionResult(lastResult, parameters, specificState);
363365
});
364366
return resultsFuture.thenApply((results) -> results.isEmpty() ? executionResult : results.get(results.size() - 1));
@@ -483,10 +485,8 @@ public void onCompleted(Object result, Throwable t) {
483485
}
484486

485487
@FunctionalInterface
486-
private interface ChainedInstrumentationFunction<I, S, A, R> {
487-
488-
R apply(I t, S u, A v);
489-
488+
private interface ChainedInstrumentationFunction<I, S, V, R> {
489+
R apply(I instrumentation, S state, V value);
490490
}
491491

492492

src/test/groovy/graphql/execution/instrumentation/ChainedInstrumentationStateTest.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class ChainedInstrumentationStateTest extends Specification {
9090

9191
then:
9292

93+
chainedInstrumentation.getInstrumentations().size() == 4
94+
9395
a.executionList == expected
9496
b.executionList == expected
9597
c.executionList == expected

0 commit comments

Comments
 (0)