Skip to content

Commit

Permalink
Merge pull request #24876 from rsvoboda/misc.cleanup.2022-04-11
Browse files Browse the repository at this point in the history
Misc cleanup - use Files.readString and .addAll for collections
  • Loading branch information
gsmet authored Apr 12, 2022
2 parents 033704a + 3fe15ba commit d64111d
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ void init(List<Throwable> errors) {
Collection<AnnotationInstance> getDisposedParameterQualifiers() {
Set<AnnotationInstance> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ static Set<AnnotationInstance> initQualifiers(BeanDeployment beanDeployment, Met
Set<AnnotationInstance> qualifiers = new HashSet<>();
for (AnnotationInstance annotation : getParameterAnnotations(beanDeployment, observerMethod,
eventParameter.position())) {
beanDeployment.extractQualifiers(annotation).forEach(qualifiers::add);
qualifiers.addAll(beanDeployment.extractQualifiers(annotation));
}
return qualifiers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,14 @@ public boolean contains(Path path) {
public PathsCollection add(Path... paths) {
final List<Path> 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<Path> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,13 @@ public boolean contains(Path path) {
public PathList add(Path... paths) {
final List<Path> 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<Path> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ static List<Object> parseParams(List<Object> 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) {
Expand All @@ -555,7 +555,7 @@ static List<Object> parseParams(List<Object> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public Fmt dataArray(Object... data) {
}

public Fmt dataMap(Map<String, Object> data) {
data.forEach(dataMap::put);
dataMap.putAll(data);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void transform(Transformation... transformations) {
public void transform(Collection<Transformation> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public static ListAssert<String> 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);
}
Expand Down

0 comments on commit d64111d

Please sign in to comment.