Skip to content

Commit 6060676

Browse files
authored
Use ImmutableKit emptyMap and emptyList (#2829)
* Use ImmutableKit empttMap * Use ImmutableKit emptyList
1 parent 671caf5 commit 6060676

File tree

55 files changed

+125
-118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+125
-118
lines changed

src/main/java/graphql/ExecutionInput.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package graphql;
22

33
import graphql.cachecontrol.CacheControl;
4+
import graphql.collect.ImmutableKit;
45
import graphql.execution.ExecutionId;
56
import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentationState;
67
import org.dataloader.DataLoaderRegistry;
78

8-
import java.util.Collections;
99
import java.util.Locale;
1010
import java.util.Map;
1111
import java.util.function.Consumer;
@@ -209,8 +209,8 @@ public static class Builder {
209209
private Object context = graphQLContext; // we make these the same object on purpose - legacy code will get the same object if this change nothing
210210
private Object localContext;
211211
private Object root;
212-
private Map<String, Object> variables = Collections.emptyMap();
213-
public Map<String, Object> extensions = Collections.emptyMap();
212+
private Map<String, Object> variables = ImmutableKit.emptyMap();
213+
public Map<String, Object> extensions = ImmutableKit.emptyMap();
214214
//
215215
// this is important - it allows code to later known if we never really set a dataloader and hence it can optimize
216216
// dataloader field tracking away.

src/main/java/graphql/ParseAndValidateResult.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package graphql;
22

3+
import graphql.collect.ImmutableKit;
34
import graphql.execution.instrumentation.DocumentAndVariables;
45
import graphql.language.Document;
56
import graphql.parser.InvalidSyntaxException;
67
import graphql.validation.ValidationError;
78

89
import java.util.ArrayList;
9-
import java.util.Collections;
1010
import java.util.List;
1111
import java.util.Map;
1212
import java.util.function.Consumer;
@@ -25,9 +25,9 @@ public class ParseAndValidateResult {
2525

2626
private ParseAndValidateResult(Builder builder) {
2727
this.document = builder.document;
28-
this.variables = builder.variables == null ? Collections.emptyMap() : builder.variables;
28+
this.variables = builder.variables == null ? ImmutableKit.emptyMap() : builder.variables;
2929
this.syntaxException = builder.syntaxException;
30-
this.validationErrors = builder.validationErrors == null ? Collections.emptyList() : builder.validationErrors;
30+
this.validationErrors = builder.validationErrors == null ? ImmutableKit.emptyList() : builder.validationErrors;
3131
}
3232

3333
/**
@@ -102,9 +102,9 @@ public static Builder newResult() {
102102

103103
public static class Builder {
104104
private Document document;
105-
private Map<String, Object> variables = Collections.emptyMap();
105+
private Map<String, Object> variables = ImmutableKit.emptyMap();
106106
private InvalidSyntaxException syntaxException;
107-
private List<ValidationError> validationErrors = Collections.emptyList();
107+
private List<ValidationError> validationErrors = ImmutableKit.emptyList();
108108

109109
public Builder document(Document document) {
110110
this.document = document;

src/main/java/graphql/collect/ImmutableMapWithNullValues.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private ImmutableMapWithNullValues(Map<K, V> values) {
3636
* Only used to construct the singleton empty map
3737
*/
3838
private ImmutableMapWithNullValues() {
39-
this(Collections.emptyMap());
39+
this(ImmutableKit.emptyMap());
4040
}
4141

4242

src/main/java/graphql/execution/AbortExecutionException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import java.util.List;
1414

1515
import static graphql.Assert.assertNotNull;
16-
import static java.util.Collections.emptyList;
16+
import static graphql.collect.ImmutableKit.emptyList;
1717

1818
/**
1919
* This Exception indicates that the current execution should be aborted.

src/main/java/graphql/execution/ExecutionStrategy.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import graphql.TrivialDataFetcher;
1111
import graphql.TypeMismatchError;
1212
import graphql.UnresolvedTypeError;
13+
import graphql.collect.ImmutableKit;
1314
import graphql.execution.directives.QueryDirectives;
1415
import graphql.execution.directives.QueryDirectivesImpl;
1516
import graphql.execution.instrumentation.Instrumentation;
@@ -354,9 +355,9 @@ protected <T> CompletableFuture<T> handleFetchingException(ExecutionContext exec
354355

355356
private <T> CompletableFuture<T> asyncHandleException(DataFetcherExceptionHandler handler, DataFetcherExceptionHandlerParameters handlerParameters, ExecutionContext executionContext) {
356357
//noinspection unchecked
357-
return handler.handleException(handlerParameters)
358-
.thenApply(handlerResult -> (T) DataFetcherResult.<FetchedValue>newResult().errors(handlerResult.getErrors()).build()
359-
);
358+
return handler.handleException(handlerParameters)
359+
.thenApply(handlerResult -> (T) DataFetcherResult.<FetchedValue>newResult().errors(handlerResult.getErrors()).build()
360+
);
360361
}
361362

362363
/**
@@ -810,7 +811,7 @@ protected ExecutionStepInfo createExecutionStepInfo(ExecutionContext executionCo
810811
ExecutionStepInfo parentStepInfo = parameters.getExecutionStepInfo();
811812
GraphQLOutputType fieldType = fieldDefinition.getType();
812813
List<GraphQLArgument> fieldArgDefs = fieldDefinition.getArguments();
813-
Supplier<Map<String, Object>> argumentValues = Collections::emptyMap;
814+
Supplier<Map<String, Object>> argumentValues = ImmutableKit::emptyMap;
814815
//
815816
// no need to create args at all if there are none on the field def
816817
//

src/main/java/graphql/execution/ValuesResolver.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import graphql.Internal;
77
import graphql.Scalars;
88
import graphql.VisibleForTesting;
9+
import graphql.collect.ImmutableKit;
910
import graphql.language.Argument;
1011
import graphql.language.ArrayValue;
1112
import graphql.language.BooleanValue;
@@ -162,7 +163,7 @@ public Map<String, NormalizedInputValue> getNormalizedArgumentValues(List<GraphQ
162163
List<Argument> arguments,
163164
Map<String, NormalizedInputValue> normalizedVariables) {
164165
if (argumentTypes.isEmpty()) {
165-
return Collections.emptyMap();
166+
return ImmutableKit.emptyMap();
166167
}
167168

168169
Map<String, NormalizedInputValue> result = new LinkedHashMap<>();
@@ -399,7 +400,7 @@ private Map<String, Object> externalValueToInternalValueForVariables(GraphQLSche
399400
boolean hasValue = rawVariables.containsKey(variableName);
400401
Object value = rawVariables.get(variableName);
401402
if (!hasValue && defaultValue != null) {
402-
Object coercedDefaultValue = literalToInternalValue(fieldVisibility, variableType, defaultValue, Collections.emptyMap());
403+
Object coercedDefaultValue = literalToInternalValue(fieldVisibility, variableType, defaultValue, ImmutableKit.emptyMap());
403404
coercedValues.put(variableName, coercedDefaultValue);
404405
} else if (isNonNull(variableType) && (!hasValue || value == null)) {
405406
throw new NonNullableValueCoercedAsNullException(variableDefinition, variableType);
@@ -433,7 +434,7 @@ private Map<String, Object> getArgumentValuesImpl(GraphqlFieldVisibility fieldVi
433434
Map<String, Object> coercedVariables
434435
) {
435436
if (argumentTypes.isEmpty()) {
436-
return Collections.emptyMap();
437+
return ImmutableKit.emptyMap();
437438
}
438439

439440
Map<String, Object> coercedValues = new LinkedHashMap<>();
@@ -813,7 +814,7 @@ private Object defaultValueToInternalValue(GraphqlFieldVisibility fieldVisibilit
813814
}
814815
if (defaultValue.isLiteral()) {
815816
// default value literals can't reference variables, this is why the variables are empty
816-
return literalToInternalValue(fieldVisibility, type, (Value) defaultValue.getValue(), Collections.emptyMap());
817+
return literalToInternalValue(fieldVisibility, type, (Value) defaultValue.getValue(), ImmutableKit.emptyMap());
817818
}
818819
if (defaultValue.isExternal()) {
819820
// performs validation too

src/main/java/graphql/execution/directives/QueryDirectivesImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import java.util.List;
1717
import java.util.Map;
1818

19-
import static java.util.Collections.emptyList;
19+
import static graphql.collect.ImmutableKit.emptyList;
2020

2121
/**
2222
* These objects are ALWAYS in the context of a single MergedField

src/main/java/graphql/execution/instrumentation/dataloader/DataLoaderDispatcherInstrumentation.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import graphql.ExecutionResult;
44
import graphql.ExecutionResultImpl;
55
import graphql.PublicApi;
6-
import graphql.execution.Async;
6+
import graphql.collect.ImmutableKit;
77
import graphql.execution.AsyncExecutionStrategy;
88
import graphql.execution.ExecutionContext;
99
import graphql.execution.ExecutionStrategy;
@@ -25,7 +25,6 @@
2525
import org.slf4j.Logger;
2626
import org.slf4j.LoggerFactory;
2727

28-
import java.util.Collections;
2928
import java.util.LinkedHashMap;
3029
import java.util.Map;
3130
import java.util.concurrent.CompletableFuture;
@@ -160,7 +159,7 @@ public CompletableFuture<ExecutionResult> instrumentExecutionResult(ExecutionRes
160159
}
161160
DataLoaderDispatcherInstrumentationState state = parameters.getInstrumentationState();
162161
Map<Object, Object> currentExt = executionResult.getExtensions();
163-
Map<Object, Object> statsMap = new LinkedHashMap<>(currentExt == null ? Collections.emptyMap() : currentExt);
162+
Map<Object, Object> statsMap = new LinkedHashMap<>(currentExt == null ? ImmutableKit.emptyMap() : currentExt);
164163
Map<Object, Object> dataLoaderStats = buildStatsMap(state);
165164
statsMap.put("dataloader", dataLoaderStats);
166165

src/main/java/graphql/execution/instrumentation/nextgen/InstrumentationExecutionParameters.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import graphql.ExecutionInput;
44
import graphql.GraphQLContext;
55
import graphql.Internal;
6+
import graphql.collect.ImmutableKit;
67
import graphql.execution.instrumentation.InstrumentationState;
78
import graphql.schema.GraphQLSchema;
89

9-
import java.util.Collections;
1010
import java.util.Map;
1111

1212
/**
@@ -29,7 +29,7 @@ public InstrumentationExecutionParameters(ExecutionInput executionInput, GraphQL
2929
this.operation = executionInput.getOperationName();
3030
this.context = executionInput.getContext();
3131
this.graphQLContext = executionInput.getGraphQLContext();
32-
this.variables = executionInput.getVariables() != null ? executionInput.getVariables() : Collections.emptyMap();
32+
this.variables = executionInput.getVariables() != null ? executionInput.getVariables() : ImmutableKit.emptyMap();
3333
this.instrumentationState = instrumentationState;
3434
this.schema = schema;
3535
}
@@ -59,6 +59,7 @@ public String getOperation() {
5959

6060
/**
6161
* @param <T> for two
62+
*
6263
* @return the legacy context
6364
*
6465
* @deprecated use {@link #getGraphQLContext()} instead

src/main/java/graphql/execution/instrumentation/parameters/InstrumentationExecutionParameters.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import graphql.ExecutionInput;
44
import graphql.GraphQLContext;
55
import graphql.PublicApi;
6+
import graphql.collect.ImmutableKit;
67
import graphql.execution.instrumentation.Instrumentation;
78
import graphql.execution.instrumentation.InstrumentationState;
89
import graphql.schema.GraphQLSchema;
910

10-
import java.util.Collections;
1111
import java.util.Map;
1212

1313
/**
@@ -30,7 +30,7 @@ public InstrumentationExecutionParameters(ExecutionInput executionInput, GraphQL
3030
this.operation = executionInput.getOperationName();
3131
this.context = executionInput.getContext();
3232
this.graphQLContext = executionInput.getGraphQLContext();
33-
this.variables = executionInput.getVariables() != null ? executionInput.getVariables() : Collections.emptyMap();
33+
this.variables = executionInput.getVariables() != null ? executionInput.getVariables() : ImmutableKit.emptyMap();
3434
this.instrumentationState = instrumentationState;
3535
this.schema = schema;
3636
}
@@ -60,6 +60,7 @@ public String getOperation() {
6060

6161
/**
6262
* @param <T> for two
63+
*
6364
* @return the legacy context
6465
*
6566
* @deprecated use {@link #getGraphQLContext()} instead

0 commit comments

Comments
 (0)