Browse Source

Some very simple improvements regarding ArrayList

pull/22419/head
stsypanov 7 years ago committed by Juergen Hoeller
parent
commit
92053bb84e
  1. 5
      spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheOperation.java
  2. 3
      spring-core/src/main/java/org/springframework/util/StringUtils.java
  3. 6
      spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java
  4. 3
      spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java

5
spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheOperation.java vendored

@ -138,8 +138,9 @@ abstract class AbstractJCacheOperation<A extends Annotation> implements JCacheOp
private static List<CacheParameterDetail> initializeAllParameterDetails(Method method) { private static List<CacheParameterDetail> initializeAllParameterDetails(Method method) {
List<CacheParameterDetail> result = new ArrayList<>(); int parameterCount = method.getParameterCount();
for (int i = 0; i < method.getParameterCount(); i++) { List<CacheParameterDetail> result = new ArrayList<>(parameterCount);
for (int i = 0; i < parameterCount; i++) {
CacheParameterDetail detail = new CacheParameterDetail(method, i); CacheParameterDetail detail = new CacheParameterDetail(method, i);
result.add(detail); result.add(detail);
} }

3
spring-core/src/main/java/org/springframework/util/StringUtils.java

@ -936,8 +936,7 @@ public abstract class StringUtils {
return array1; return array1;
} }
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>(Arrays.asList(array1));
result.addAll(Arrays.asList(array1));
for (String str : array2) { for (String str : array2) {
if (!result.contains(str)) { if (!result.contains(str)) {
result.add(str); result.add(str);

6
spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java

@ -20,6 +20,7 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -373,14 +374,15 @@ public class MessageHeaderAccessor {
} }
private List<String> getMatchingHeaderNames(String pattern, @Nullable Map<String, Object> headers) { private List<String> getMatchingHeaderNames(String pattern, @Nullable Map<String, Object> headers) {
if (headers == null) {
return Collections.emptyList();
}
List<String> matchingHeaderNames = new ArrayList<>(); List<String> matchingHeaderNames = new ArrayList<>();
if (headers != null) {
for (String key : headers.keySet()) { for (String key : headers.keySet()) {
if (PatternMatchUtils.simpleMatch(pattern, key)) { if (PatternMatchUtils.simpleMatch(pattern, key)) {
matchingHeaderNames.add(key); matchingHeaderNames.add(key);
} }
} }
}
return matchingHeaderNames; return matchingHeaderNames;
} }

3
spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java

@ -317,8 +317,7 @@ public class ErrorsTag extends AbstractHtmlElementBodyTag implements BodyTag {
*/ */
@Override @Override
protected void exposeAttributes() throws JspException { protected void exposeAttributes() throws JspException {
List<String> errorMessages = new ArrayList<>(); List<String> errorMessages = new ArrayList<>(Arrays.asList(getBindStatus().getErrorMessages()));
errorMessages.addAll(Arrays.asList(getBindStatus().getErrorMessages()));
this.oldMessages = this.pageContext.getAttribute(MESSAGES_ATTRIBUTE, PageContext.PAGE_SCOPE); this.oldMessages = this.pageContext.getAttribute(MESSAGES_ATTRIBUTE, PageContext.PAGE_SCOPE);
this.pageContext.setAttribute(MESSAGES_ATTRIBUTE, errorMessages, PageContext.PAGE_SCOPE); this.pageContext.setAttribute(MESSAGES_ATTRIBUTE, errorMessages, PageContext.PAGE_SCOPE);
this.errorMessagesWereExposed = true; this.errorMessagesWereExposed = true;

Loading…
Cancel
Save