@Autowired/@Inject with array/List value gets sorted against Ordered/@Order

Issue: SPR-5574
This commit is contained in:
Juergen Hoeller
2013-08-22 16:43:10 +02:00
parent 486a56dc1f
commit 4a9af233ae
4 changed files with 215 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
@@ -98,4 +98,21 @@ public class OrderComparator implements Comparator<Object> {
}
}
/**
* Sort the given array or List with a default OrderComparator,
* if necessary. Simply skips sorting when given any other value.
* <p>Optimized to skip sorting for lists with size 0 or 1,
* in order to avoid unnecessary array extraction.
* @param value the array or List to sort
* @see java.util.Arrays#sort(Object[], java.util.Comparator)
*/
public static void sortIfNecessary(Object value) {
if (value instanceof Object[]) {
sort((Object[]) value);
}
else if (value instanceof List) {
sort((List) value);
}
}
}

View File

@@ -86,4 +86,21 @@ public class AnnotationAwareOrderComparator extends OrderComparator {
}
}
/**
* Sort the given array or List with a default AnnotationAwareOrderComparator,
* if necessary. Simply skips sorting when given any other value.
* <p>Optimized to skip sorting for lists with size 0 or 1,
* in order to avoid unnecessary array extraction.
* @param value the array or List to sort
* @see java.util.Arrays#sort(Object[], java.util.Comparator)
*/
public static void sortIfNecessary(Object value) {
if (value instanceof Object[]) {
sort((Object[]) value);
}
else if (value instanceof List) {
sort((List) value);
}
}
}