SPR-17074 Replace pointless wrapping with Arrays.asList with iteration over array

This commit is contained in:
stsypanov
2018-08-01 23:04:05 +03:00
committed by Juergen Hoeller
parent 29ce6685ca
commit b5c691bdac
4 changed files with 10 additions and 7 deletions

View File

@@ -229,13 +229,14 @@ public abstract class AbstractDelegatingSmartContextLoader implements SmartConte
@Override
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {
Assert.notNull(mergedConfig, "mergedConfig must not be null");
List<SmartContextLoader> candidates = Arrays.asList(getXmlLoader(), getAnnotationConfigLoader());
Assert.state(!(mergedConfig.hasLocations() && mergedConfig.hasClasses()), () -> String.format(
"Neither %s nor %s supports loading an ApplicationContext from %s: " +
"declare either 'locations' or 'classes' but not both.", name(getXmlLoader()),
name(getAnnotationConfigLoader()), mergedConfig));
SmartContextLoader[] candidates = {getXmlLoader(), getAnnotationConfigLoader()};
for (SmartContextLoader loader : candidates) {
// Determine if each loader can load a context from the mergedConfig. If it
// can, let it; otherwise, keep iterating.

View File

@@ -23,6 +23,7 @@ import java.util.List;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.support.DefaultDataBinderFactory;
@@ -81,8 +82,8 @@ public class InitBinderDataBinderFactory extends DefaultDataBinderFactory {
protected boolean isBinderMethodApplicable(HandlerMethod binderMethod, WebDataBinder binder) {
InitBinder ann = binderMethod.getMethodAnnotation(InitBinder.class);
Assert.state(ann != null, "No InitBinder annotation");
Collection<String> names = Arrays.asList(ann.value());
return (names.isEmpty() || names.contains(binder.getObjectName()));
String[] names = ann.value();
return ObjectUtils.isEmpty(names) || Arrays.asList(names).contains(binder.getObjectName());
}
}

View File

@@ -22,6 +22,7 @@ import java.util.List;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.bind.support.SimpleSessionStatus;
@@ -78,8 +79,8 @@ class InitBinderBindingContext extends BindingContext {
.filter(binderMethod -> {
InitBinder ann = binderMethod.getMethodAnnotation(InitBinder.class);
Assert.state(ann != null, "No InitBinder annotation");
Collection<String> names = Arrays.asList(ann.value());
return (names.isEmpty() || names.contains(dataBinder.getObjectName()));
String[] names = ann.value();
return ObjectUtils.isEmpty(names) || Arrays.asList(names).contains(dataBinder.getObjectName());
})
.forEach(method -> invokeBinderMethod(dataBinder, exchange, method));

View File

@@ -122,7 +122,7 @@ class HandlersBeanDefinitionParser implements BeanDefinitionParser {
@Override
public void addMapping(Element element, ManagedMap<String, Object> urlMap, ParserContext context) {
String pathAttribute = element.getAttribute("path");
List<String> mappings = Arrays.asList(StringUtils.tokenizeToStringArray(pathAttribute, ","));
String[] mappings = StringUtils.tokenizeToStringArray(pathAttribute, ",");
RuntimeBeanReference handlerReference = new RuntimeBeanReference(element.getAttribute("handler"));
ConstructorArgumentValues cargs = new ConstructorArgumentValues();
@@ -153,7 +153,7 @@ class HandlersBeanDefinitionParser implements BeanDefinitionParser {
@Override
public void addMapping(Element element, ManagedMap<String, Object> urlMap, ParserContext context) {
String pathAttribute = element.getAttribute("path");
List<String> mappings = Arrays.asList(StringUtils.tokenizeToStringArray(pathAttribute, ","));
String[] mappings = StringUtils.tokenizeToStringArray(pathAttribute, ",");
RuntimeBeanReference handlerReference = new RuntimeBeanReference(element.getAttribute("handler"));
ConstructorArgumentValues cargs = new ConstructorArgumentValues();