Skip to content

Some very simple improvements regarding usage of ArrayList #22418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ protected StringBuilder getOperationDescription() {


private static List<CacheParameterDetail> initializeAllParameterDetails(Method method) {
List<CacheParameterDetail> result = new ArrayList<>();
for (int i = 0; i < method.getParameterCount(); i++) {
int parameterCount = method.getParameterCount();
List<CacheParameterDetail> result = new ArrayList<>(parameterCount);
for (int i = 0; i < parameterCount; i++) {
CacheParameterDetail detail = new CacheParameterDetail(method, i);
result.add(detail);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,7 @@ public static String[] mergeStringArrays(@Nullable String[] array1, @Nullable St
return array1;
}

List<String> result = new ArrayList<>();
result.addAll(Arrays.asList(array1));
List<String> result = new ArrayList<>(Arrays.asList(array1));
for (String str : array2) {
if (!result.contains(str)) {
result.add(str);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -373,12 +374,13 @@ public void removeHeaders(String... headerPatterns) {
}

private List<String> getMatchingHeaderNames(String pattern, @Nullable Map<String, Object> headers) {
if (headers == null) {
return Collections.emptyList();
}
List<String> matchingHeaderNames = new ArrayList<>();
if (headers != null) {
for (String key : headers.keySet()) {
if (PatternMatchUtils.simpleMatch(pattern, key)) {
matchingHeaderNames.add(key);
}
for (String key : headers.keySet()) {
if (PatternMatchUtils.simpleMatch(pattern, key)) {
matchingHeaderNames.add(key);
}
}
return matchingHeaderNames;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ protected void renderDefaultContent(TagWriter tagWriter) throws JspException {
*/
@Override
protected void exposeAttributes() throws JspException {
List<String> errorMessages = new ArrayList<>();
errorMessages.addAll(Arrays.asList(getBindStatus().getErrorMessages()));
List<String> errorMessages = new ArrayList<>(Arrays.asList(getBindStatus().getErrorMessages()));
this.oldMessages = this.pageContext.getAttribute(MESSAGES_ATTRIBUTE, PageContext.PAGE_SCOPE);
this.pageContext.setAttribute(MESSAGES_ATTRIBUTE, errorMessages, PageContext.PAGE_SCOPE);
this.errorMessagesWereExposed = true;
Expand Down