Prefer List.sort(Comparator) over Collections.sort(List, Comparator)
This commit is contained in:
@@ -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.
|
||||
@@ -20,7 +20,6 @@ import java.io.Serializable;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -155,7 +154,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
methods.add(method);
|
||||
}
|
||||
});
|
||||
Collections.sort(methods, METHOD_COMPARATOR);
|
||||
methods.sort(METHOD_COMPARATOR);
|
||||
return methods;
|
||||
}
|
||||
|
||||
@@ -164,7 +163,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
* for the given introduction field.
|
||||
* <p>Resulting Advisors will need to be evaluated for targets.
|
||||
* @param introductionField the field to introspect
|
||||
* @return {@code null} if not an Advisor
|
||||
* @return the Advisor instance, or {@code null} if not an Advisor
|
||||
*/
|
||||
@Nullable
|
||||
private Advisor getDeclareParentsAdvisor(Field introductionField) {
|
||||
@@ -293,6 +292,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
springAdvice.setArgumentNamesFromStringArray(argNames);
|
||||
}
|
||||
springAdvice.calculateArgumentBindings();
|
||||
|
||||
return springAdvice;
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
|
||||
public SyntheticInstantiationAdvisor(final MetadataAwareAspectInstanceFactory aif) {
|
||||
super(aif.getAspectMetadata().getPerClausePointcut(), (MethodBeforeAdvice)
|
||||
(method, args, target) -> aif.getAspectInstance());// Simply instantiate the aspect
|
||||
(method, args, target) -> aif.getAspectInstance());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -540,7 +540,7 @@ class ConfigurationClassParser {
|
||||
return;
|
||||
}
|
||||
|
||||
Collections.sort(deferredImports, DEFERRED_IMPORT_COMPARATOR);
|
||||
deferredImports.sort(DEFERRED_IMPORT_COMPARATOR);
|
||||
for (DeferredImportSelectorHolder deferredImport : deferredImports) {
|
||||
ConfigurationClass configClass = deferredImport.getConfigurationClass();
|
||||
try {
|
||||
|
||||
@@ -365,7 +365,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Stopping beans in phase " + this.phase);
|
||||
}
|
||||
Collections.sort(this.members, Collections.reverseOrder());
|
||||
this.members.sort(Collections.reverseOrder());
|
||||
CountDownLatch latch = new CountDownLatch(this.smartMemberCount);
|
||||
Set<String> countDownBeanNames = Collections.synchronizedSet(new LinkedHashSet<>());
|
||||
for (LifecycleGroupMember member : this.members) {
|
||||
|
||||
@@ -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.
|
||||
@@ -260,7 +260,7 @@ class PostProcessorRegistrationDelegate {
|
||||
if (comparatorToUse == null) {
|
||||
comparatorToUse = OrderComparator.INSTANCE;
|
||||
}
|
||||
Collections.sort(postProcessors, comparatorToUse);
|
||||
postProcessors.sort(comparatorToUse);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -88,9 +87,8 @@ public class ExceptionDepthComparator implements Comparator<Class<? extends Thro
|
||||
if (exceptionTypes.size() == 1) {
|
||||
return exceptionTypes.iterator().next();
|
||||
}
|
||||
List<Class<? extends Throwable>> handledExceptions =
|
||||
new ArrayList<>(exceptionTypes);
|
||||
Collections.sort(handledExceptions, new ExceptionDepthComparator(targetException));
|
||||
List<Class<? extends Throwable>> handledExceptions = new ArrayList<>(exceptionTypes);
|
||||
handledExceptions.sort(new ExceptionDepthComparator(targetException));
|
||||
return handledExceptions.get(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -43,7 +42,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* @since 07.04.2003
|
||||
* @see Ordered
|
||||
* @see org.springframework.core.annotation.AnnotationAwareOrderComparator
|
||||
* @see java.util.Collections#sort(java.util.List, java.util.Comparator)
|
||||
* @see java.util.List#sort(java.util.Comparator)
|
||||
* @see java.util.Arrays#sort(Object[], java.util.Comparator)
|
||||
*/
|
||||
public class OrderComparator implements Comparator<Object> {
|
||||
@@ -165,11 +164,11 @@ public class OrderComparator implements Comparator<Object> {
|
||||
* <p>Optimized to skip sorting for lists with size 0 or 1,
|
||||
* in order to avoid unnecessary array extraction.
|
||||
* @param list the List to sort
|
||||
* @see java.util.Collections#sort(java.util.List, java.util.Comparator)
|
||||
* @see java.util.List#sort(java.util.Comparator)
|
||||
*/
|
||||
public static void sort(List<?> list) {
|
||||
if (list.size() > 1) {
|
||||
Collections.sort(list, INSTANCE);
|
||||
list.sort(INSTANCE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.core.annotation;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.core.DecoratingProxy;
|
||||
@@ -119,11 +118,11 @@ public class AnnotationAwareOrderComparator extends OrderComparator {
|
||||
* <p>Optimized to skip sorting for lists with size 0 or 1,
|
||||
* in order to avoid unnecessary array extraction.
|
||||
* @param list the List to sort
|
||||
* @see java.util.Collections#sort(java.util.List, java.util.Comparator)
|
||||
* @see java.util.List#sort(java.util.Comparator)
|
||||
*/
|
||||
public static void sort(List<?> list) {
|
||||
if (list.size() > 1) {
|
||||
Collections.sort(list, INSTANCE);
|
||||
list.sort(INSTANCE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -598,7 +598,7 @@ public class AntPathMatcher implements PathMatcher {
|
||||
/**
|
||||
* Given a full path, returns a {@link Comparator} suitable for sorting patterns in order of
|
||||
* explicitness.
|
||||
* <p>This{@code Comparator} will {@linkplain java.util.Collections#sort(List, Comparator) sort}
|
||||
* <p>This{@code Comparator} will {@linkplain java.util.List#sort(Comparator) sort}
|
||||
* a list so that more specific patterns (without uri templates or wild cards) come before
|
||||
* generic patterns. So given a list with the following patterns:
|
||||
* <ol>
|
||||
|
||||
@@ -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.
|
||||
@@ -308,7 +308,7 @@ public abstract class MimeTypeUtils {
|
||||
public static void sortBySpecificity(List<MimeType> mimeTypes) {
|
||||
Assert.notNull(mimeTypes, "'mimeTypes' must not be null");
|
||||
if (mimeTypes.size() > 1) {
|
||||
Collections.sort(mimeTypes, SPECIFICITY_COMPARATOR);
|
||||
mimeTypes.sort(SPECIFICITY_COMPARATOR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -104,9 +104,9 @@ public interface PathMatcher {
|
||||
/**
|
||||
* Given a full path, returns a {@link Comparator} suitable for sorting patterns
|
||||
* in order of explicitness for that path.
|
||||
* <p>The full algorithm used depends on the underlying implementation, but generally,
|
||||
* the returned {@code Comparator} will
|
||||
* {@linkplain java.util.Collections#sort(java.util.List, java.util.Comparator) sort}
|
||||
* <p>The full algorithm used depends on the underlying implementation,
|
||||
* but generally, the returned {@code Comparator} will
|
||||
* {@linkplain java.util.List#sort(java.util.Comparator) sort}
|
||||
* a list so that more specific patterns come before generic patterns.
|
||||
* @param path the full path to use for comparison
|
||||
* @return a comparator capable of sorting patterns in order of explicitness
|
||||
|
||||
@@ -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.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.jdbc.config;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
@@ -75,7 +74,7 @@ public class SortedResourcesFactoryBean extends AbstractFactoryBean<Resource[]>
|
||||
for (String location : this.locations) {
|
||||
List<Resource> resources = new ArrayList<>(
|
||||
Arrays.asList(this.resourcePatternResolver.getResources(location)));
|
||||
Collections.sort(resources, (r1, r2) -> {
|
||||
resources.sort((r1, r2) -> {
|
||||
try {
|
||||
return r1.getURL().toString().compareTo(r2.getURL().toString());
|
||||
}
|
||||
@@ -83,9 +82,7 @@ public class SortedResourcesFactoryBean extends AbstractFactoryBean<Resource[]>
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
for (Resource resource : resources) {
|
||||
scripts.add(resource);
|
||||
}
|
||||
scripts.addAll(resources);
|
||||
}
|
||||
return scripts.toArray(new Resource[scripts.size()]);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -168,7 +168,7 @@ public class DestinationPatternsMessageCondition
|
||||
return null;
|
||||
}
|
||||
|
||||
Collections.sort(matches, this.pathMatcher.getPatternComparator(destination));
|
||||
matches.sort(this.pathMatcher.getPatternComparator(destination));
|
||||
return new DestinationPatternsMessageCondition(matches, this.pathMatcher);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.messaging.handler.invocation;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -126,7 +125,7 @@ public abstract class AbstractExceptionHandlerMethodResolver {
|
||||
}
|
||||
}
|
||||
if (!matches.isEmpty()) {
|
||||
Collections.sort(matches, new ExceptionDepthComparator(exceptionType));
|
||||
matches.sort(new ExceptionDepthComparator(exceptionType));
|
||||
return this.mappedMethods.get(matches.get(0));
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -453,7 +453,7 @@ public abstract class AbstractMethodMessageHandler<T>
|
||||
return;
|
||||
}
|
||||
Comparator<Match> comparator = new MatchComparator(getMappingComparator(message));
|
||||
Collections.sort(matches, comparator);
|
||||
matches.sort(comparator);
|
||||
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Found " + matches.size() + " handler methods: " + matches);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.test.web;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -32,8 +31,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
|
||||
@@ -78,11 +77,10 @@ public abstract class ModelAndViewAssert {
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,28 +153,21 @@ public abstract class ModelAndViewAssert {
|
||||
* @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" })
|
||||
@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);
|
||||
Collections.sort(expectedList, comparator);
|
||||
}
|
||||
else {
|
||||
Collections.sort(modelList);
|
||||
Collections.sort(expectedList);
|
||||
}
|
||||
modelList.sort(comparator);
|
||||
expectedList.sort(comparator);
|
||||
|
||||
assertTrue("List in model under name '" + modelName + "' is not equal to the expected list.",
|
||||
expectedList.equals(modelList));
|
||||
expectedList.equals(modelList));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,15 +181,14 @@ public abstract class ModelAndViewAssert {
|
||||
fail("ModelAndView is 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<>();
|
||||
tempSet.addAll(incorrectSet);
|
||||
Set<String> tempSet = new HashSet<>(incorrectSet);
|
||||
tempSet.removeAll(assertionSet);
|
||||
|
||||
if (!tempSet.isEmpty()) {
|
||||
@@ -210,8 +200,7 @@ public abstract class ModelAndViewAssert {
|
||||
}
|
||||
}
|
||||
|
||||
tempSet = new HashSet<>();
|
||||
tempSet.addAll(assertionSet);
|
||||
tempSet = new HashSet<>(assertionSet);
|
||||
tempSet.removeAll(incorrectSet);
|
||||
|
||||
if (!tempSet.isEmpty()) {
|
||||
|
||||
@@ -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.
|
||||
@@ -622,7 +622,7 @@ public class MediaType extends MimeType implements Serializable {
|
||||
public static void sortBySpecificity(List<MediaType> mediaTypes) {
|
||||
Assert.notNull(mediaTypes, "'mediaTypes' must not be null");
|
||||
if (mediaTypes.size() > 1) {
|
||||
Collections.sort(mediaTypes, SPECIFICITY_COMPARATOR);
|
||||
mediaTypes.sort(SPECIFICITY_COMPARATOR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -649,7 +649,7 @@ public class MediaType extends MimeType implements Serializable {
|
||||
public static void sortByQualityValue(List<MediaType> mediaTypes) {
|
||||
Assert.notNull(mediaTypes, "'mediaTypes' must not be null");
|
||||
if (mediaTypes.size() > 1) {
|
||||
Collections.sort(mediaTypes, QUALITY_VALUE_COMPARATOR);
|
||||
mediaTypes.sort(QUALITY_VALUE_COMPARATOR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -662,8 +662,7 @@ public class MediaType extends MimeType implements Serializable {
|
||||
public static void sortBySpecificityAndQuality(List<MediaType> mediaTypes) {
|
||||
Assert.notNull(mediaTypes, "'mediaTypes' must not be null");
|
||||
if (mediaTypes.size() > 1) {
|
||||
Collections.sort(mediaTypes,
|
||||
MediaType.SPECIFICITY_COMPARATOR.thenComparing(MediaType.QUALITY_VALUE_COMPARATOR));
|
||||
mediaTypes.sort(MediaType.SPECIFICITY_COMPARATOR.thenComparing(MediaType.QUALITY_VALUE_COMPARATOR));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -169,7 +169,7 @@ public class ExceptionHandlerMethodResolver {
|
||||
}
|
||||
}
|
||||
if (!matches.isEmpty()) {
|
||||
Collections.sort(matches, new ExceptionDepthComparator(exceptionType));
|
||||
matches.sort(new ExceptionDepthComparator(exceptionType));
|
||||
return this.mappedMethods.get(matches.get(0));
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -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.
|
||||
@@ -23,7 +23,6 @@ import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -248,7 +247,7 @@ public class VersionResourceResolver extends AbstractResourceResolver {
|
||||
}
|
||||
if (!matchingPatterns.isEmpty()) {
|
||||
Comparator<String> comparator = this.pathMatcher.getPatternComparator(path);
|
||||
Collections.sort(matchingPatterns, comparator);
|
||||
matchingPatterns.sort(comparator);
|
||||
return this.versionStrategyMap.get(matchingPatterns.get(0));
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -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.
|
||||
@@ -353,10 +353,9 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
|
||||
if (!matches.isEmpty()) {
|
||||
Comparator<Match> comparator = new MatchComparator(getMappingComparator(request));
|
||||
Collections.sort(matches, comparator);
|
||||
matches.sort(comparator);
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Found " + matches.size() + " matching mapping(s) for [" +
|
||||
lookupPath + "] : " + matches);
|
||||
logger.trace("Found " + matches.size() + " matching mapping(s) for [" + lookupPath + "] : " + matches);
|
||||
}
|
||||
Match bestMatch = matches.get(0);
|
||||
if (matches.size() > 1) {
|
||||
|
||||
@@ -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.
|
||||
@@ -194,7 +194,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i
|
||||
String bestMatch = null;
|
||||
Comparator<String> patternComparator = getPathMatcher().getPatternComparator(urlPath);
|
||||
if (!matchingPatterns.isEmpty()) {
|
||||
Collections.sort(matchingPatterns, patternComparator);
|
||||
matchingPatterns.sort(patternComparator);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Matching patterns for request [" + urlPath + "] are " + matchingPatterns);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -228,7 +228,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
|
||||
matches.add(match);
|
||||
}
|
||||
}
|
||||
Collections.sort(matches, this.pathMatcher.getPatternComparator(lookupPath));
|
||||
matches.sort(this.pathMatcher.getPatternComparator(lookupPath));
|
||||
return matches;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -239,7 +239,7 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
|
||||
|
||||
if (!matchingPatterns.isEmpty()) {
|
||||
Comparator<String> patternComparator = getPathMatcher().getPatternComparator(lookupPath);
|
||||
Collections.sort(matchingPatterns, patternComparator);
|
||||
matchingPatterns.sort(patternComparator);
|
||||
for (String pattern : matchingPatterns) {
|
||||
String pathWithinMapping = getPathMatcher().extractPathWithinPattern(pattern, lookupPath);
|
||||
String pathMapping = lookupPath.substring(0, lookupPath.indexOf(pathWithinMapping));
|
||||
|
||||
@@ -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.
|
||||
@@ -23,7 +23,6 @@ import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -241,7 +240,7 @@ public class VersionResourceResolver extends AbstractResourceResolver {
|
||||
}
|
||||
if (!matchingPatterns.isEmpty()) {
|
||||
Comparator<String> comparator = this.pathMatcher.getPatternComparator(path);
|
||||
Collections.sort(matchingPatterns, comparator);
|
||||
matchingPatterns.sort(comparator);
|
||||
return this.versionStrategyMap.get(matchingPatterns.get(0));
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user