Prefer List.sort(Comparator) over Collections.sort(List, Comparator)
This commit is contained in:
@@ -30,7 +30,6 @@ import java.security.PrivilegedAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -1201,7 +1200,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());
|
||||
Object result = converter.convertIfNecessary(matchingBeans.values(), type);
|
||||
if (getDependencyComparator() != null && result instanceof List) {
|
||||
Collections.sort((List<?>) result, adaptDependencyComparator(matchingBeans));
|
||||
((List<?>) result).sort(adaptDependencyComparator(matchingBeans));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.beans.support;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -135,7 +134,7 @@ public class PropertyComparator<T> implements Comparator<T> {
|
||||
*/
|
||||
public static void sort(List<?> source, SortDefinition sortDefinition) throws BeansException {
|
||||
if (StringUtils.hasText(sortDefinition.getProperty())) {
|
||||
Collections.sort(source, new PropertyComparator<>(sortDefinition));
|
||||
source.sort(new PropertyComparator<>(sortDefinition));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user