From 94f1fbbbc8efe4e17efe7967cbc3652e8a541fb3 Mon Sep 17 00:00:00 2001 From: Rostislav Svoboda Date: Mon, 11 Apr 2022 16:02:19 +0200 Subject: [PATCH 1/2] Use Files.readString shortcut --- .../java/io/quarkus/devtools/codestarts/CodestartResource.java | 3 +-- .../main/java/io/quarkus/maven/utilities/PomTransformer.java | 2 +- .../main/java/io/quarkus/devtools/testing/SnapshotTesting.java | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartResource.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartResource.java index 193e463fd62c5..f3e0138c49b29 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartResource.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartResource.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.io.UncheckedIOException; -import java.nio.charset.StandardCharsets; import java.nio.file.CopyOption; import java.nio.file.Files; import java.nio.file.Path; @@ -93,7 +92,7 @@ public String pathName() { @Override public String read(String codestartRelativePath) { try { - return new String(Files.readAllBytes(codestartDir.resolve(codestartRelativePath)), StandardCharsets.UTF_8); + return Files.readString(codestartDir.resolve(codestartRelativePath)); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/PomTransformer.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/PomTransformer.java index 2fbb0f0da750e..93f8e99c5a34a 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/PomTransformer.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/PomTransformer.java @@ -75,7 +75,7 @@ public void transform(Transformation... transformations) { public void transform(Collection transformations) { transform(transformations, path, () -> { try { - return new String(Files.readAllBytes(path), charset); + return Files.readString(path, charset); } catch (IOException e) { throw new RuntimeException(String.format("Could not read DOM from [%s]", path), e); } diff --git a/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/SnapshotTesting.java b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/SnapshotTesting.java index a26bcf2767105..6e19c702aa46b 100644 --- a/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/SnapshotTesting.java +++ b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/SnapshotTesting.java @@ -269,7 +269,7 @@ public static ListAssert assertThatDirectoryTreeMatchSnapshots(String sn public static String getTextContent(Path file) { try { - return new String(Files.readAllBytes(file), StandardCharsets.UTF_8); + return Files.readString(file); } catch (IOException e) { throw new UncheckedIOException("Unable to read " + file.toString(), e); } From 3fe15ba0d2a2f650c70ad4f417987c0cfea637d0 Mon Sep 17 00:00:00 2001 From: Rostislav Svoboda Date: Mon, 11 Apr 2022 16:42:52 +0200 Subject: [PATCH 2/2] Use .addAll method instead of the for-each construct --- .../main/java/io/quarkus/arc/processor/DisposerInfo.java | 3 +-- .../main/java/io/quarkus/arc/processor/ObserverInfo.java | 2 +- .../java/io/quarkus/bootstrap/model/PathsCollection.java | 8 ++------ .../src/main/java/io/quarkus/paths/PathList.java | 8 ++------ .../src/main/java/io/quarkus/qute/IfSectionHelper.java | 4 ++-- .../qute/core/src/main/java/io/quarkus/qute/Qute.java | 2 +- 6 files changed, 9 insertions(+), 18 deletions(-) diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/DisposerInfo.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/DisposerInfo.java index 175bae52a50ea..47d40d9d83345 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/DisposerInfo.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/DisposerInfo.java @@ -74,8 +74,7 @@ void init(List errors) { Collection getDisposedParameterQualifiers() { Set resultingQualifiers = new HashSet<>(); Annotations.getParameterAnnotations(declaringBean.getDeployment(), disposerMethod, disposedParameter.position()) - .stream().forEach(a -> declaringBean.getDeployment().extractQualifiers(a) - .forEach(resultingQualifiers::add)); + .stream().forEach(a -> resultingQualifiers.addAll(declaringBean.getDeployment().extractQualifiers(a))); return resultingQualifiers; } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ObserverInfo.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ObserverInfo.java index c475e08274c5d..781377bafa4d4 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ObserverInfo.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ObserverInfo.java @@ -293,7 +293,7 @@ static Set initQualifiers(BeanDeployment beanDeployment, Met Set qualifiers = new HashSet<>(); for (AnnotationInstance annotation : getParameterAnnotations(beanDeployment, observerMethod, eventParameter.position())) { - beanDeployment.extractQualifiers(annotation).forEach(qualifiers::add); + qualifiers.addAll(beanDeployment.extractQualifiers(annotation)); } return qualifiers; } diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/PathsCollection.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/PathsCollection.java index a5f7f81aa1483..46619f101922f 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/PathsCollection.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/PathsCollection.java @@ -86,18 +86,14 @@ public boolean contains(Path path) { public PathsCollection add(Path... paths) { final List list = new ArrayList<>(this.paths.size() + paths.length); list.addAll(this.paths); - for (int i = 0; i < paths.length; ++i) { - list.add(paths[i]); - } + Collections.addAll(list, paths); return new PathsCollection(list); } @Override public PathsCollection addFirst(Path... paths) { final List list = new ArrayList<>(this.paths.size() + paths.length); - for (int i = 0; i < paths.length; ++i) { - list.add(paths[i]); - } + Collections.addAll(list, paths); list.addAll(this.paths); return new PathsCollection(list); } diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/paths/PathList.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/paths/PathList.java index 59eb42f6ad350..b659d29f8c3b3 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/paths/PathList.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/paths/PathList.java @@ -95,17 +95,13 @@ public boolean contains(Path path) { public PathList add(Path... paths) { final List list = new ArrayList<>(this.paths.size() + paths.length); list.addAll(this.paths); - for (int i = 0; i < paths.length; ++i) { - list.add(paths[i]); - } + Collections.addAll(list, paths); return new PathList(list); } public PathList addFirst(Path... paths) { final List list = new ArrayList<>(this.paths.size() + paths.length); - for (int i = 0; i < paths.length; ++i) { - list.add(paths[i]); - } + Collections.addAll(list, paths); list.addAll(this.paths); return new PathList(list); } diff --git a/independent-projects/qute/core/src/main/java/io/quarkus/qute/IfSectionHelper.java b/independent-projects/qute/core/src/main/java/io/quarkus/qute/IfSectionHelper.java index ec7f1cd42e6a7..a799e2ddcc716 100644 --- a/independent-projects/qute/core/src/main/java/io/quarkus/qute/IfSectionHelper.java +++ b/independent-projects/qute/core/src/main/java/io/quarkus/qute/IfSectionHelper.java @@ -535,7 +535,7 @@ static List parseParams(List params, ParserDelegate parserDelega if (prevIdx > lastGroupdIdx) { int from = lastGroupdIdx > 0 ? lastGroupdIdx + 1 : 0; int to = op.isBinary() ? prevIdx : prevIdx + 1; - params.subList(from, to).forEach(ret::add); + ret.addAll(params.subList(from, to)); } } else if (op.precedence < highestPrecedence) { if (highestGroup != null) { @@ -555,7 +555,7 @@ static List parseParams(List params, ParserDelegate parserDelega } else { // Add all remaining non-grouped elements if (lastGroupdIdx + 1 != params.size()) { - params.subList(lastGroupdIdx + 1, params.size()).forEach(ret::add); + ret.addAll(params.subList(lastGroupdIdx + 1, params.size())); } } return parseParams(ret, parserDelegate); diff --git a/independent-projects/qute/core/src/main/java/io/quarkus/qute/Qute.java b/independent-projects/qute/core/src/main/java/io/quarkus/qute/Qute.java index fd4747c6215b7..20cdd46328184 100644 --- a/independent-projects/qute/core/src/main/java/io/quarkus/qute/Qute.java +++ b/independent-projects/qute/core/src/main/java/io/quarkus/qute/Qute.java @@ -235,7 +235,7 @@ public Fmt dataArray(Object... data) { } public Fmt dataMap(Map data) { - data.forEach(dataMap::put); + dataMap.putAll(data); return this; }