From 8ab3d042246ddb57d4b952fb8519961b2e150634 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Tue, 18 Apr 2023 09:46:10 +0100 Subject: [PATCH] Polishing for Java 17 baseline --- .../graphql/client/ResponseMapGraphQlResponse.java | 8 ++++---- .../graphql/data/query/PropertySelection.java | 5 ++--- .../support/DefaultExecutionGraphQlResponse.java | 12 +++--------- .../graphql/support/ResourceDocumentSource.java | 10 +++++----- .../client/DefaultGraphQlClientResponseTests.java | 4 ++-- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/ResponseMapGraphQlResponse.java b/spring-graphql/src/main/java/org/springframework/graphql/client/ResponseMapGraphQlResponse.java index 8df91d5b..529831d0 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/ResponseMapGraphQlResponse.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/ResponseMapGraphQlResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,7 +61,7 @@ class ResponseMapGraphQlResponse extends AbstractGraphQlResponse { private static List wrapErrors(Map map) { List> errors = (List>) map.get("errors"); errors = (errors != null ? errors : Collections.emptyList()); - return errors.stream().map(Error::new).collect(Collectors.toList()); + return errors.stream().map(MapResponseError::new).collect(Collectors.toList()); } @@ -112,7 +112,7 @@ class ResponseMapGraphQlResponse extends AbstractGraphQlResponse { /** * {@link GraphQLError} that wraps a deserialized the GraphQL response map. */ - private static final class Error implements ResponseError { + private static final class MapResponseError implements ResponseError { private final Map errorMap; @@ -120,7 +120,7 @@ class ResponseMapGraphQlResponse extends AbstractGraphQlResponse { private final String path; - Error(Map errorMap) { + MapResponseError(Map errorMap) { Assert.notNull(errorMap, "'errorMap' is required"); this.errorMap = errorMap; this.locations = initLocations(errorMap); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/query/PropertySelection.java b/spring-graphql/src/main/java/org/springframework/graphql/data/query/PropertySelection.java index 84872023..e44b8e42 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/query/PropertySelection.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/query/PropertySelection.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -107,8 +107,7 @@ class PropertySelection { * @return the property paths as list. */ public List toList() { - return this.propertyPaths.stream().map(PropertyPath::toDotPath) - .collect(Collectors.toList()); + return this.propertyPaths.stream().map(PropertyPath::toDotPath).collect(Collectors.toList()); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/support/DefaultExecutionGraphQlResponse.java b/spring-graphql/src/main/java/org/springframework/graphql/support/DefaultExecutionGraphQlResponse.java index 3bcee12f..addb7909 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/support/DefaultExecutionGraphQlResponse.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/support/DefaultExecutionGraphQlResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -89,7 +89,7 @@ public class DefaultExecutionGraphQlResponse extends AbstractGraphQlResponse imp @Override public List getErrors() { - return this.result.getErrors().stream().map(Error::new).collect(Collectors.toList()); + return this.result.getErrors().stream().map(GraphQLErrorResponseError::new).collect(Collectors.toList()); } @Override @@ -111,13 +111,7 @@ public class DefaultExecutionGraphQlResponse extends AbstractGraphQlResponse imp /** * {@link GraphQLError} that wraps a {@link GraphQLError}. */ - private static class Error implements ResponseError { - - private final GraphQLError delegate; - - Error(GraphQLError delegate) { - this.delegate = delegate; - } + private record GraphQLErrorResponseError(GraphQLError delegate) implements ResponseError { @Override public String getMessage() { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/support/ResourceDocumentSource.java b/spring-graphql/src/main/java/org/springframework/graphql/support/ResourceDocumentSource.java index 048fb754..72bd93b7 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/support/ResourceDocumentSource.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/support/ResourceDocumentSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -97,7 +97,7 @@ public class ResourceDocumentSource implements DocumentSource { .switchIfEmpty(Mono.fromRunnable(() -> { throw new IllegalStateException( "Failed to find document, name='" + name + "', under location(s)=" + - this.locations.stream().map(Resource::toString).collect(Collectors.toList())); + this.locations.stream().map(Resource::toString).toList()); })) .subscribeOn(Schedulers.boundedElastic()); } @@ -117,9 +117,9 @@ public class ResourceDocumentSource implements DocumentSource { private String resourceToString(Resource resource) { try { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - FileCopyUtils.copy(resource.getInputStream(), out); - return new String(out.toByteArray(), StandardCharsets.UTF_8); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + FileCopyUtils.copy(resource.getInputStream(), outputStream); + return outputStream.toString(StandardCharsets.UTF_8); } catch (IOException ex) { throw new IllegalArgumentException( diff --git a/spring-graphql/src/test/java/org/springframework/graphql/client/DefaultGraphQlClientResponseTests.java b/spring-graphql/src/test/java/org/springframework/graphql/client/DefaultGraphQlClientResponseTests.java index a198a527..291e8bea 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/client/DefaultGraphQlClientResponseTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/client/DefaultGraphQlClientResponseTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -151,7 +151,7 @@ public class DefaultGraphQlClientResponseTests { } private ClientResponseField getFieldOnErrorResponse(String path, GraphQLError... errors) { - List list = Arrays.stream(errors).map(GraphQLError::toSpecification).collect(Collectors.toList()); + List list = Arrays.stream(errors).map(GraphQLError::toSpecification).toList(); ClientGraphQlResponse response = creatResponse(Collections.singletonMap("errors", list)); return response.field(path); }