Skip to content

Commit 8ab3d04

Browse files
committed
Polishing for Java 17 baseline
1 parent 3b1d1ab commit 8ab3d04

File tree

5 files changed

+16
-23
lines changed

5 files changed

+16
-23
lines changed

spring-graphql/src/main/java/org/springframework/graphql/client/ResponseMapGraphQlResponse.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -61,7 +61,7 @@ protected ResponseMapGraphQlResponse(GraphQlResponse response) {
6161
private static List<ResponseError> wrapErrors(Map<String, Object> map) {
6262
List<Map<String, Object>> errors = (List<Map<String, Object>>) map.get("errors");
6363
errors = (errors != null ? errors : Collections.emptyList());
64-
return errors.stream().map(Error::new).collect(Collectors.toList());
64+
return errors.stream().map(MapResponseError::new).collect(Collectors.toList());
6565
}
6666

6767

@@ -112,15 +112,15 @@ public String toString() {
112112
/**
113113
* {@link GraphQLError} that wraps a deserialized the GraphQL response map.
114114
*/
115-
private static final class Error implements ResponseError {
115+
private static final class MapResponseError implements ResponseError {
116116

117117
private final Map<String, Object> errorMap;
118118

119119
private final List<SourceLocation> locations;
120120

121121
private final String path;
122122

123-
Error(Map<String, Object> errorMap) {
123+
MapResponseError(Map<String, Object> errorMap) {
124124
Assert.notNull(errorMap, "'errorMap' is required");
125125
this.errorMap = errorMap;
126126
this.locations = initLocations(errorMap);

spring-graphql/src/main/java/org/springframework/graphql/data/query/PropertySelection.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -107,8 +107,7 @@ private static List<PropertyPath> collectPropertyPaths(TypeInformation<?> typeIn
107107
* @return the property paths as list.
108108
*/
109109
public List<String> toList() {
110-
return this.propertyPaths.stream().map(PropertyPath::toDotPath)
111-
.collect(Collectors.toList());
110+
return this.propertyPaths.stream().map(PropertyPath::toDotPath).collect(Collectors.toList());
112111
}
113112

114113

spring-graphql/src/main/java/org/springframework/graphql/support/DefaultExecutionGraphQlResponse.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -89,7 +89,7 @@ public <T> T getData() {
8989

9090
@Override
9191
public List<ResponseError> getErrors() {
92-
return this.result.getErrors().stream().map(Error::new).collect(Collectors.toList());
92+
return this.result.getErrors().stream().map(GraphQLErrorResponseError::new).collect(Collectors.toList());
9393
}
9494

9595
@Override
@@ -111,13 +111,7 @@ public String toString() {
111111
/**
112112
* {@link GraphQLError} that wraps a {@link GraphQLError}.
113113
*/
114-
private static class Error implements ResponseError {
115-
116-
private final GraphQLError delegate;
117-
118-
Error(GraphQLError delegate) {
119-
this.delegate = delegate;
120-
}
114+
private record GraphQLErrorResponseError(GraphQLError delegate) implements ResponseError {
121115

122116
@Override
123117
public String getMessage() {

spring-graphql/src/main/java/org/springframework/graphql/support/ResourceDocumentSource.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -97,7 +97,7 @@ public Mono<String> getDocument(String name) {
9797
.switchIfEmpty(Mono.fromRunnable(() -> {
9898
throw new IllegalStateException(
9999
"Failed to find document, name='" + name + "', under location(s)=" +
100-
this.locations.stream().map(Resource::toString).collect(Collectors.toList()));
100+
this.locations.stream().map(Resource::toString).toList());
101101
}))
102102
.subscribeOn(Schedulers.boundedElastic());
103103
}
@@ -117,9 +117,9 @@ private List<Resource> getCandidateResources(String name, Resource location) {
117117

118118
private String resourceToString(Resource resource) {
119119
try {
120-
ByteArrayOutputStream out = new ByteArrayOutputStream();
121-
FileCopyUtils.copy(resource.getInputStream(), out);
122-
return new String(out.toByteArray(), StandardCharsets.UTF_8);
120+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
121+
FileCopyUtils.copy(resource.getInputStream(), outputStream);
122+
return outputStream.toString(StandardCharsets.UTF_8);
123123
}
124124
catch (IOException ex) {
125125
throw new IllegalArgumentException(

spring-graphql/src/test/java/org/springframework/graphql/client/DefaultGraphQlClientResponseTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -151,7 +151,7 @@ private ClientResponseField getFieldOnDataResponse(String path, String dataJson)
151151
}
152152

153153
private ClientResponseField getFieldOnErrorResponse(String path, GraphQLError... errors) {
154-
List<?> list = Arrays.stream(errors).map(GraphQLError::toSpecification).collect(Collectors.toList());
154+
List<?> list = Arrays.stream(errors).map(GraphQLError::toSpecification).toList();
155155
ClientGraphQlResponse response = creatResponse(Collections.singletonMap("errors", list));
156156
return response.field(path);
157157
}

0 commit comments

Comments
 (0)