Skip to content

replace Collections.sort() by List.sort() #1325

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

Closed
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 @@ -403,8 +403,8 @@ private void initEndpointAdapters(ApplicationContext applicationContext) throws
Map<String, EndpointAdapter> matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext,
EndpointAdapter.class, true, false);
if (!matchingBeans.isEmpty()) {
endpointAdapters = new ArrayList<EndpointAdapter>(matchingBeans.values());
Collections.sort(endpointAdapters, new OrderComparator());
endpointAdapters = new ArrayList<>(matchingBeans.values());
endpointAdapters.sort(new OrderComparator());
} else {
endpointAdapters = defaultStrategiesHelper.getDefaultStrategies(EndpointAdapter.class, applicationContext);
if (logger.isDebugEnabled()) {
Expand All @@ -425,8 +425,8 @@ private void initEndpointExceptionResolvers(ApplicationContext applicationContex
Map<String, EndpointExceptionResolver> matchingBeans = BeanFactoryUtils
.beansOfTypeIncludingAncestors(applicationContext, EndpointExceptionResolver.class, true, false);
if (!matchingBeans.isEmpty()) {
endpointExceptionResolvers = new ArrayList<EndpointExceptionResolver>(matchingBeans.values());
Collections.sort(endpointExceptionResolvers, new OrderComparator());
endpointExceptionResolvers = new ArrayList<>(matchingBeans.values());
endpointExceptionResolvers.sort(new OrderComparator());
} else {
endpointExceptionResolvers = defaultStrategiesHelper.getDefaultStrategies(EndpointExceptionResolver.class,
applicationContext);
Expand All @@ -448,8 +448,8 @@ private void initEndpointMappings(ApplicationContext applicationContext) throws
Map<String, EndpointMapping> matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext,
EndpointMapping.class, true, false);
if (!matchingBeans.isEmpty()) {
endpointMappings = new ArrayList<EndpointMapping>(matchingBeans.values());
Collections.sort(endpointMappings, new OrderComparator());
endpointMappings = new ArrayList<>(matchingBeans.values());
endpointMappings.sort(new OrderComparator());
} else {
endpointMappings = defaultStrategiesHelper.getDefaultStrategies(EndpointMapping.class, applicationContext);
if (logger.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,29 +115,27 @@ public <T> List<T> getDefaultStrategies(Class<T> strategyInterface, ApplicationC
throws BeanInitializationException {
String key = strategyInterface.getName();
try {
List<T> result;
String value = defaultStrategies.getProperty(key);
if (value != null) {
String[] classNames = StringUtils.commaDelimitedListToStringArray(value);
result = new ArrayList<T>(classNames.length);
ClassLoader classLoader = null;
if (applicationContext != null) {
classLoader = applicationContext.getClassLoader();
}
if (classLoader == null) {
classLoader = DefaultStrategiesHelper.class.getClassLoader();
}
for (String className : classNames) {
Class<T> clazz = (Class<T>) ClassUtils.forName(className, classLoader);
Assert.isTrue(strategyInterface.isAssignableFrom(clazz),
clazz.getName() + " is not a " + strategyInterface.getName());
T strategy = instantiateBean(clazz, applicationContext);
result.add(strategy);
}
} else {
result = Collections.emptyList();
if (value == null) {
return Collections.emptyList();
}
Collections.sort(result, new OrderComparator());
String[] classNames = StringUtils.commaDelimitedListToStringArray(value);
List<T> result = new ArrayList<>(classNames.length);
ClassLoader classLoader = null;
if (applicationContext != null) {
classLoader = applicationContext.getClassLoader();
}
if (classLoader == null) {
classLoader = DefaultStrategiesHelper.class.getClassLoader();
}
for (String className : classNames) {
Class<T> clazz = (Class<T>) ClassUtils.forName(className, classLoader);
Assert.isTrue(strategyInterface.isAssignableFrom(clazz),
clazz.getName() + " is not a " + strategyInterface.getName());
T strategy = instantiateBean(clazz, applicationContext);
result.add(strategy);
}
result.sort(new OrderComparator());
return result;
} catch (ClassNotFoundException ex) {
throw new BeanInitializationException("Could not find default strategy class for interface [" + key + "]", ex);
Expand Down