Consistent use of StringUtils.toStringArray

This commit is contained in:
Juergen Hoeller 2018-02-16 19:48:43 +01:00
parent 350f318d2e
commit 6d11b40353
27 changed files with 125 additions and 137 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -553,7 +553,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
results.add(beanName);
}
}
return results.toArray(new String[results.size()]);
return StringUtils.toStringArray(results);
}
@Override
@ -1009,7 +1009,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
}
if (!autowireCandidates.isEmpty()) {
candidateNames = autowireCandidates.toArray(new String[autowireCandidates.size()]);
candidateNames = StringUtils.toStringArray(autowireCandidates);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -504,7 +504,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
if (dependenciesForBean == null) {
return new String[0];
}
return dependenciesForBean.toArray(new String[dependenciesForBean.size()]);
return StringUtils.toStringArray(dependenciesForBean);
}
public void destroySingletons() {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -333,7 +333,7 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
results.add(beanName);
}
}
return results.toArray(new String[results.size()]);
return StringUtils.toStringArray(results);
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -42,6 +42,7 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.core.io.Resource;
import org.springframework.tests.sample.beans.IndexedTestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.StringUtils;
import static org.junit.Assert.*;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.*;
@ -838,12 +839,12 @@ public class PropertyResourceConfigurerTests {
@Override
protected String[] keysSpi() throws BackingStoreException {
return values.keySet().toArray(new String[values.size()]);
return StringUtils.toStringArray(values.keySet());
}
@Override
protected String[] childrenNamesSpi() throws BackingStoreException {
return children.keySet().toArray(new String[values.size()]);
return StringUtils.toStringArray(children.keySet());
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -23,6 +23,7 @@ import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.AdviceModeImportSelector;
import org.springframework.context.annotation.AutoProxyRegistrar;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
/**
* Selects which implementation of {@link AbstractCachingConfiguration} should be used
@ -84,7 +85,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
if (jsr107Present && jcacheImplPresent) {
result.add(PROXY_JCACHE_CONFIGURATION_CLASS);
}
return result.toArray(new String[result.size()]);
return StringUtils.toStringArray(result);
}
/**
@ -97,7 +98,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
if (jsr107Present && jcacheImplPresent) {
result.add(JCACHE_ASPECT_CONFIGURATION_CLASS_NAME);
}
return result.toArray(new String[result.size()]);
return StringUtils.toStringArray(result);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Support class for {@link AttributeAccessor AttributeAccessors}, providing
@ -70,7 +71,7 @@ public abstract class AttributeAccessorSupport implements AttributeAccessor, Ser
@Override
public String[] attributeNames() {
return this.attributes.keySet().toArray(new String[this.attributes.size()]);
return StringUtils.toStringArray(this.attributes.keySet());
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,6 +18,8 @@ package org.springframework.core.env;
import java.util.List;
import org.springframework.util.StringUtils;
/**
* {@link CommandLinePropertySource} implementation backed by a simple String array.
*
@ -100,7 +102,7 @@ public class SimpleCommandLinePropertySource extends CommandLinePropertySource<C
*/
@Override
public String[] getPropertyNames() {
return source.getOptionNames().toArray(new String[source.getOptionNames().size()]);
return StringUtils.toStringArray(this.source.getOptionNames());
}
@Override

View File

@ -25,6 +25,7 @@ import org.springframework.beans.NotReadablePropertyException;
import org.springframework.beans.PropertyAccessor;
import org.springframework.beans.PropertyAccessorFactory;
import org.springframework.jdbc.core.StatementCreatorUtils;
import org.springframework.util.StringUtils;
/**
* {@link SqlParameterSource} implementation that obtains parameter values
@ -98,7 +99,7 @@ public class BeanPropertySqlParameterSource extends AbstractSqlParameterSource {
names.add(pd.getName());
}
}
this.propertyNames = names.toArray(new String[names.size()]);
this.propertyNames = StringUtils.toStringArray(names);
}
return this.propertyNames;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -51,6 +51,7 @@ import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractorAdapter;
import org.springframework.util.LinkedCaseInsensitiveMap;
import org.springframework.util.StringUtils;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
@ -229,7 +230,7 @@ public class JdbcTemplateTests {
this.list.add(rs.getString(1));
}
public String[] getStrings() {
return this.list.toArray(new String[this.list.size()]);
return StringUtils.toStringArray(this.list);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -38,6 +38,7 @@ import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.Customer;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.util.StringUtils;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
@ -763,9 +764,7 @@ public class SqlQueryTests {
}
public String[] run() {
List<String> list = execute();
String[] results = list.toArray(new String[list.size()]);
return results;
return StringUtils.toStringArray(execute());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -22,6 +22,7 @@ import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.StubMessageChannel;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
import org.springframework.util.StringUtils;
import static org.junit.Assert.*;
@ -33,7 +34,6 @@ import static org.junit.Assert.*;
*/
public class StompBrokerRelayRegistrationTests {
@Test
public void test() {
@ -52,7 +52,7 @@ public class StompBrokerRelayRegistrationTests {
StompBrokerRelayMessageHandler handler = registration.getMessageHandler(new StubMessageChannel());
assertArrayEquals(prefixes, handler.getDestinationPrefixes().toArray(new String[2]));
assertArrayEquals(prefixes, StringUtils.toStringArray(handler.getDestinationPrefixes()));
assertEquals("clientlogin", handler.getClientLogin());
assertEquals("clientpasscode", handler.getClientPasscode());
assertEquals("syslogin", handler.getSystemLogin());

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,6 +30,7 @@ import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Mock implementation of the {@link javax.servlet.http.HttpSession} interface.
@ -172,7 +173,7 @@ public class MockHttpSession implements HttpSession {
@Override
public String[] getValueNames() {
assertIsValid();
return this.attributes.keySet().toArray(new String[this.attributes.size()]);
return StringUtils.toStringArray(this.attributes.keySet());
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -32,8 +32,8 @@ import static org.springframework.test.util.AssertionErrors.*;
* A collection of assertions intended to simplify testing scenarios dealing
* with Spring Web MVC {@link org.springframework.web.servlet.ModelAndView
* ModelAndView} objects.
* <p>
* Intended for use with JUnit 4 and TestNG. All {@code assert*()} methods
*
* <p>Intended for use with JUnit 4 and TestNG. All {@code assert*()} methods
* throw {@link AssertionError}s.
*
* @author Sam Brannen
@ -48,94 +48,82 @@ public abstract class ModelAndViewAssert {
* Checks whether the model value under the given {@code modelName}
* exists and checks it type, based on the {@code expectedType}. If the
* model entry exists and the type matches, the model value is returned.
*
* @param mav ModelAndView to test against (never {@code null})
* @param modelName name of the object to add to the model (never
* {@code null})
* @param modelName name of the object to add to the model (never {@code null})
* @param expectedType expected type of the model value
* @return the model value
*/
@SuppressWarnings("unchecked")
public static <T> T assertAndReturnModelAttributeOfType(ModelAndView mav, String modelName, Class<T> expectedType) {
assertTrue("ModelAndView is null", mav != null);
assertTrue("Model is null", mav.getModel() != null);
Object obj = mav.getModel().get(modelName);
assertTrue("Model attribute with name '" + modelName + "' is null", obj != null);
assertTrue("Model attribute is not of expected type '" + expectedType.getName() + "' but rather of type '"
+ obj.getClass().getName() + "'", expectedType.isAssignableFrom(obj.getClass()));
assertTrue("Model attribute is not of expected type '" + expectedType.getName() + "' but rather of type '" +
obj.getClass().getName() + "'", expectedType.isAssignableFrom(obj.getClass()));
return (T) obj;
}
/**
* Compare each individual entry in a list, without first sorting the lists.
*
* @param mav ModelAndView to test against (never {@code null})
* @param modelName name of the object to add to the model (never
* {@code null})
* @param modelName name of the object to add to the model (never {@code null})
* @param expectedList the expected list
*/
@SuppressWarnings("rawtypes")
public static void assertCompareListModelAttribute(ModelAndView mav, String modelName, List expectedList) {
assertTrue("ModelAndView is null", mav != null);
List modelList = assertAndReturnModelAttributeOfType(mav, modelName, List.class);
assertTrue(
"Size of model list is '" + modelList.size() + "' while size of expected list is '" + expectedList.size()
+ "'", expectedList.size() == modelList.size());
assertTrue("Size of model list is '" + modelList.size() + "' while size of expected list is '" +
expectedList.size() + "'", expectedList.size() == modelList.size());
assertTrue("List in model under name '" + modelName + "' is not equal to the expected list.",
expectedList.equals(modelList));
expectedList.equals(modelList));
}
/**
* Assert whether or not a model attribute is available.
*
* @param mav ModelAndView to test against (never {@code null})
* @param modelName name of the object to add to the model (never
* {@code null})
* @param modelName name of the object to add to the model (never {@code null})
*/
public static void assertModelAttributeAvailable(ModelAndView mav, String modelName) {
assertTrue("ModelAndView is null", mav != null);
assertTrue("Model is null", mav.getModel() != null);
assertTrue("Model attribute with name '" + modelName + "' is not available",
mav.getModel().containsKey(modelName));
mav.getModel().containsKey(modelName));
}
/**
* Compare a given {@code expectedValue} to the value from the model
* bound under the given {@code modelName}.
*
* @param mav ModelAndView to test against (never {@code null})
* @param modelName name of the object to add to the model (never
* {@code null})
* @param modelName name of the object to add to the model (never {@code null})
* @param expectedValue the model value
*/
public static void assertModelAttributeValue(ModelAndView mav, String modelName, Object expectedValue) {
assertTrue("ModelAndView is null", mav != null);
Object modelValue = assertAndReturnModelAttributeOfType(mav, modelName, Object.class);
assertTrue("Model value with name '" + modelName + "' is not the same as the expected value which was '"
+ expectedValue + "'", modelValue.equals(expectedValue));
assertTrue("Model value with name '" + modelName + "' is not the same as the expected value which was '" +
expectedValue + "'", modelValue.equals(expectedValue));
}
/**
* Inspect the {@code expectedModel} to see if all elements in the
* model appear and are equal.
*
* @param mav ModelAndView to test against (never {@code null})
* @param expectedModel the expected model
*/
public static void assertModelAttributeValues(ModelAndView mav, Map<String, Object> expectedModel) {
assertTrue("ModelAndView is null", mav != null);
assertTrue("Model is null", mav.getModel() != null);
Map<String, Object> model = mav.getModel();
if (!mav.getModel().keySet().equals(expectedModel.keySet())) {
if (!model.keySet().equals(expectedModel.keySet())) {
StringBuilder sb = new StringBuilder("Keyset of expected model does not match.\n");
appendNonMatchingSetsErrorMessage(expectedModel.keySet(), mav.getModel().keySet(), sb);
appendNonMatchingSetsErrorMessage(expectedModel.keySet(), model.keySet(), sb);
fail(sb.toString());
}
StringBuilder sb = new StringBuilder();
for (String modelName : mav.getModel().keySet()) {
for (String modelName : model.keySet()) {
Object assertionValue = expectedModel.get(modelName);
Object mavValue = mav.getModel().get(modelName);
Object mavValue = model.get(modelName);
if (!assertionValue.equals(mavValue)) {
sb.append("Value under name '").append(modelName).append("' differs, should have been '").append(
assertionValue).append("' but was '").append(mavValue).append("'\n");
@ -151,25 +139,20 @@ public abstract class ModelAndViewAssert {
/**
* Compare each individual entry in a list after having sorted both lists
* (optionally using a comparator).
*
* @param mav ModelAndView to test against (never {@code null})
* @param modelName name of the object to add to the model (never
* {@code null})
* @param modelName name of the object to add to the model (never {@code null})
* @param expectedList the expected list
* @param comparator the comparator to use (may be {@code null}). If
* not specifying the comparator, both lists will be sorted not using any
* comparator.
* @param comparator the comparator to use (may be {@code null}). If not
* specifying the comparator, both lists will be sorted not using any comparator.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void assertSortAndCompareListModelAttribute(ModelAndView mav, String modelName, List expectedList,
Comparator comparator) {
@SuppressWarnings({"unchecked", "rawtypes"})
public static void assertSortAndCompareListModelAttribute(
ModelAndView mav, String modelName, List expectedList, Comparator comparator) {
assertTrue("ModelAndView is null", mav != null);
List modelList = assertAndReturnModelAttributeOfType(mav, modelName, List.class);
assertTrue(
"Size of model list is '" + modelList.size() + "' while size of expected list is '" + expectedList.size()
+ "'", expectedList.size() == modelList.size());
assertTrue("Size of model list is '" + modelList.size() + "' while size of expected list is '" +
expectedList.size() + "'", expectedList.size() == modelList.size());
if (comparator != null) {
Collections.sort(modelList, comparator);
@ -181,30 +164,29 @@ public abstract class ModelAndViewAssert {
}
assertTrue("List in model under name '" + modelName + "' is not equal to the expected list.",
expectedList.equals(modelList));
expectedList.equals(modelList));
}
/**
* Check to see if the view name in the ModelAndView matches the given
* {@code expectedName}.
*
* @param mav ModelAndView to test against (never {@code null})
* @param expectedName the name of the model value
*/
public static void assertViewName(ModelAndView mav, String expectedName) {
assertTrue("ModelAndView is null", mav != null);
assertTrue("View name is not equal to '" + expectedName + "' but was '" + mav.getViewName() + "'",
ObjectUtils.nullSafeEquals(expectedName, mav.getViewName()));
ObjectUtils.nullSafeEquals(expectedName, mav.getViewName()));
}
private static void appendNonMatchingSetsErrorMessage(Set<String> assertionSet, Set<String> incorrectSet,
StringBuilder sb) {
Set<String> tempSet = new HashSet<String>();
tempSet.addAll(incorrectSet);
private static void appendNonMatchingSetsErrorMessage(
Set<String> assertionSet, Set<String> incorrectSet, StringBuilder sb) {
Set<String> tempSet = new HashSet<String>(incorrectSet);
tempSet.removeAll(assertionSet);
if (tempSet.size() > 0) {
if (!tempSet.isEmpty()) {
sb.append("Set has too many elements:\n");
for (Object element : tempSet) {
sb.append('-');
@ -213,11 +195,10 @@ public abstract class ModelAndViewAssert {
}
}
tempSet = new HashSet<String>();
tempSet.addAll(assertionSet);
tempSet = new HashSet<String>(assertionSet);
tempSet.removeAll(incorrectSet);
if (tempSet.size() > 0) {
if (!tempSet.isEmpty()) {
sb.append("Set is missing elements:\n");
for (Object element : tempSet) {
sb.append('-');

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -57,6 +57,7 @@ import org.springframework.util.ClassUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Errors;
@ -205,7 +206,7 @@ public class HandlerMethodInvoker {
Map<String, Object> model = (mavModel != null ? mavModel : implicitModel);
if (model != null) {
try {
String[] originalAttrNames = model.keySet().toArray(new String[model.size()]);
String[] originalAttrNames = StringUtils.toStringArray(model.keySet());
for (String attrName : originalAttrNames) {
Object attrValue = model.get(attrName);
boolean isSessionAttr = this.methodResolver.isSessionAttribute(

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -215,7 +215,7 @@ public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWe
logger.info("Scanning base packages: [" +
StringUtils.collectionToCommaDelimitedString(this.basePackages) + "]");
}
scanner.scan(this.basePackages.toArray(new String[this.basePackages.size()]));
scanner.scan(StringUtils.toStringArray(this.basePackages));
}
String[] configLocations = getConfigLocations();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -42,6 +42,7 @@ import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.util.Assert;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
/**
* {@link javax.servlet.Filter} that makes form encoded data available through
@ -168,13 +169,13 @@ public class HttpPutFormContentFilter extends OncePerRequestFilter {
return parameterValues;
}
if (parameterValues == null || getQueryString() == null) {
return formParam.toArray(new String[formParam.size()]);
return StringUtils.toStringArray(formParam);
}
else {
List<String> result = new ArrayList<String>(parameterValues.length + formParam.size());
result.addAll(Arrays.asList(parameterValues));
result.addAll(formParam);
return result.toArray(new String[result.size()]);
return StringUtils.toStringArray(result);
}
}
}

View File

@ -773,7 +773,7 @@ final class HierarchicalUriComponents extends UriComponents {
@Override
public void copyToUriComponentsBuilder(UriComponentsBuilder builder) {
builder.pathSegment(getPathSegments().toArray(new String[getPathSegments().size()]));
builder.pathSegment(StringUtils.toStringArray(getPathSegments()));
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,6 +30,7 @@ import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Mock implementation of the {@link javax.servlet.http.HttpSession} interface.
@ -172,7 +173,7 @@ public class MockHttpSession implements HttpSession {
@Override
public String[] getValueNames() {
assertIsValid();
return this.attributes.keySet().toArray(new String[this.attributes.size()]);
return StringUtils.toStringArray(this.attributes.keySet());
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
/**
@ -60,7 +61,7 @@ public class FreeMarkerConfigurerBeanDefinitionParser extends AbstractSingleBean
if (locations.isEmpty()) {
locations.add("/WEB-INF/");
}
builder.addPropertyValue("templateLoaderPaths", locations.toArray(new String[locations.size()]));
builder.addPropertyValue("templateLoaderPaths", StringUtils.toStringArray(locations));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,6 +26,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
/**
@ -58,7 +59,7 @@ public class ScriptTemplateConfigurerBeanDefinitionParser extends AbstractSimple
for (Element childElement : childElements) {
locations.add(childElement.getAttribute("location"));
}
builder.addPropertyValue("scripts", locations.toArray(new String[locations.size()]));
builder.addPropertyValue("scripts", StringUtils.toStringArray(locations));
}
builder.addPropertyValue("engineName", element.getAttribute("engine-name"));
if (element.hasAttribute("render-object")) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
/**
@ -58,7 +59,7 @@ public class TilesConfigurerBeanDefinitionParser extends AbstractSingleBeanDefin
for (Element childElement : childElements) {
locations.add(childElement.getAttribute("location"));
}
builder.addPropertyValue("definitions", locations.toArray(new String[locations.size()]));
builder.addPropertyValue("definitions", StringUtils.toStringArray(locations));
}
if (element.hasAttribute("check-refresh")) {
builder.addPropertyValue("checkRefresh", element.getAttribute("check-refresh"));

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,8 +21,8 @@ import java.util.Arrays;
import java.util.List;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.PathMatcher;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.handler.MappedInterceptor;
@ -88,8 +88,8 @@ public class InterceptorRegistration {
return this.interceptor;
}
String[] include = toArray(this.includePatterns);
String[] exclude = toArray(this.excludePatterns);
String[] include = StringUtils.toStringArray(this.includePatterns);
String[] exclude = StringUtils.toStringArray(this.excludePatterns);
MappedInterceptor mappedInterceptor = new MappedInterceptor(include, exclude, this.interceptor);
if (this.pathMatcher != null) {
@ -99,8 +99,4 @@ public class InterceptorRegistration {
return mappedInterceptor;
}
private static String[] toArray(List<String> list) {
return (CollectionUtils.isEmpty(list) ? null : list.toArray(new String[list.size()]));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -31,11 +31,10 @@ import org.springframework.web.servlet.ModelAndView;
* Also provides matching logic to test if the interceptor applies to a given request path.
*
* <p>A MappedInterceptor can be registered directly with any
* {@link org.springframework.web.servlet.handler.AbstractHandlerMethodMapping
* AbstractHandlerMethodMapping}. Furthermore, beans of type MappedInterceptor
* are automatically detected by {@code AbstractHandlerMethodMapping} (including
* ancestor ApplicationContext's) which effectively means the interceptor is
* registered "globally" with all handler mappings.
* {@link org.springframework.web.servlet.handler.AbstractHandlerMethodMapping}.
* Furthermore, beans of type {@code MappedInterceptor} are automatically detected by
* {@code AbstractHandlerMethodMapping} (including ancestor ApplicationContext's) which
* effectively means the interceptor is registered "globally" with all handler mappings.
*
* @author Keith Donald
* @author Rossen Stoyanchev
@ -55,7 +54,7 @@ public final class MappedInterceptor implements HandlerInterceptor {
/**
* Create a new MappedInterceptor instance.
* @param includePatterns the path patterns to map with a {@code null} value matching to all paths
* @param includePatterns the path patterns to map (empty for matching to all paths)
* @param interceptor the HandlerInterceptor instance to map to the given patterns
*/
public MappedInterceptor(String[] includePatterns, HandlerInterceptor interceptor) {
@ -64,8 +63,8 @@ public final class MappedInterceptor implements HandlerInterceptor {
/**
* Create a new MappedInterceptor instance.
* @param includePatterns the path patterns to map with a {@code null} value matching to all paths
* @param excludePatterns the path patterns to exclude
* @param includePatterns the path patterns to map (empty for matching to all paths)
* @param excludePatterns the path patterns to exclude (empty for no specific excludes)
* @param interceptor the HandlerInterceptor instance to map to the given patterns
*/
public MappedInterceptor(String[] includePatterns, String[] excludePatterns, HandlerInterceptor interceptor) {
@ -132,8 +131,8 @@ public final class MappedInterceptor implements HandlerInterceptor {
* @param pathMatcher a path matcher for path pattern matching
*/
public boolean matches(String lookupPath, PathMatcher pathMatcher) {
PathMatcher pathMatcherToUse = (this.pathMatcher != null) ? this.pathMatcher : pathMatcher;
if (this.excludePatterns != null) {
PathMatcher pathMatcherToUse = (this.pathMatcher != null ? this.pathMatcher : pathMatcher);
if (!ObjectUtils.isEmpty(this.excludePatterns)) {
for (String pattern : this.excludePatterns) {
if (pathMatcherToUse.match(pattern, lookupPath)) {
return false;
@ -143,14 +142,12 @@ public final class MappedInterceptor implements HandlerInterceptor {
if (ObjectUtils.isEmpty(this.includePatterns)) {
return true;
}
else {
for (String pattern : this.includePatterns) {
if (pathMatcherToUse.match(pattern, lookupPath)) {
return true;
}
for (String pattern : this.includePatterns) {
if (pathMatcherToUse.match(pattern, lookupPath)) {
return true;
}
return false;
}
return false;
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -131,7 +131,7 @@ public class VersionResourceResolver extends AbstractResourceResolver {
prefixedPatterns.add(versionPrefix + pattern);
}
}
return addVersionStrategy(new FixedVersionStrategy(version), prefixedPatterns.toArray(new String[0]));
return addVersionStrategy(new FixedVersionStrategy(version), StringUtils.toStringArray(prefixedPatterns));
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import org.springframework.util.Assert;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.HandshakeHandler;
import org.springframework.web.socket.server.HandshakeInterceptor;
@ -109,8 +110,7 @@ public abstract class AbstractWebSocketHandlerRegistration<M> implements WebSock
this.sockJsServiceRegistration.setTransportHandlerOverrides(transportHandler);
}
if (!this.allowedOrigins.isEmpty()) {
this.sockJsServiceRegistration.setAllowedOrigins(
this.allowedOrigins.toArray(new String[this.allowedOrigins.size()]));
this.sockJsServiceRegistration.setAllowedOrigins(StringUtils.toStringArray(this.allowedOrigins));
}
return this.sockJsServiceRegistration;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import org.springframework.util.Assert;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.HandshakeHandler;
@ -106,7 +107,7 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
this.registration.setTransportHandlerOverrides(handler);
}
if (!this.allowedOrigins.isEmpty()) {
this.registration.setAllowedOrigins(this.allowedOrigins.toArray(new String[this.allowedOrigins.size()]));
this.registration.setAllowedOrigins(StringUtils.toStringArray(this.allowedOrigins));
}
return this.registration;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -183,7 +183,7 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life
* Return the list of supported sub-protocols.
*/
public String[] getSupportedProtocols() {
return this.supportedProtocols.toArray(new String[this.supportedProtocols.size()]);
return StringUtils.toStringArray(this.supportedProtocols);
}
@Override
@ -404,8 +404,8 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life
* @param attributes handshake attributes to pass to the WebSocket session
* @return the user for the WebSocket session, or {@code null} if not available
*/
protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler,
Map<String, Object> attributes) {
protected Principal determineUser(
ServerHttpRequest request, WebSocketHandler wsHandler, Map<String, Object> attributes) {
return request.getPrincipal();
}