Class AnnotationAwareOrderComparator
- java.lang.Object
- org.springframework.core.OrderComparator
- org.springframework.core.annotation.AnnotationAwareOrderComparator
- All Implemented Interfaces:
Comparator<Object>
public class AnnotationAwareOrderComparator extends OrderComparator
AnnotationAwareOrderComparator
is an extension ofOrderComparator
that supports Spring'sOrdered
interface as well as the@Order
and@Priority
annotations, with an order value provided by anOrdered
instance overriding a statically defined annotation value (if any).Consult the Javadoc for
OrderComparator
for details on the sort semantics for non-ordered objects.
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.core.OrderComparator
OrderComparator.OrderSourceProvider
Field Summary
Fields Modifier and Type Field Description static AnnotationAwareOrderComparator
INSTANCE
Shared default instance ofAnnotationAwareOrderComparator
.
Constructor Summary
Constructors Constructor Description AnnotationAwareOrderComparator()
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Integer
findOrder(Object obj)
Integer
getPriority(Object obj)
static void
sort(Object[] array)
Sort the given array with a default AnnotationAwareOrderComparator.static void
sort(List<?> list)
Sort the given List with a default AnnotationAwareOrderComparator.static void
sortIfNecessary(Object value)
Sort the given array or List with a default AnnotationAwareOrderComparator, if necessary.Methods inherited from class org.springframework.core.OrderComparator
compare, getOrder, withSourceProvider
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
Field Detail
INSTANCE
public static final AnnotationAwareOrderComparator INSTANCE
Shared default instance ofAnnotationAwareOrderComparator
.
Constructor Detail
AnnotationAwareOrderComparator
public AnnotationAwareOrderComparator()
Method Detail
findOrder
protected Integer findOrder(Object obj)
This implementation checks for@Order
or@Priority
on various kinds of elements, in addition to theOrdered
check in the superclass.- Overrides:
findOrder
in classOrderComparator
- Parameters:
obj
- the object to check- Returns:
- the order value, or
null
if none found
getPriority
public Integer getPriority(Object obj)
This implementation retrieves an @Priority
value, allowing for additional semantics over the regular @Order
annotation: typically, selecting one object over another in case of multiple matches but only one object to be returned.- Overrides:
getPriority
in classOrderComparator
- Parameters:
obj
- the object to check- Returns:
- the priority value, or
null
if none
sort
public static void sort(List<?> list)
Sort the given List with a default AnnotationAwareOrderComparator.Optimized to skip sorting for lists with size 0 or 1, in order to avoid unnecessary array extraction.
- Parameters:
list
- the List to sort- See Also:
Collections.sort(java.util.List, java.util.Comparator)
sort
public static void sort(Object[] array)
Sort the given array with a default AnnotationAwareOrderComparator.Optimized to skip sorting for lists with size 0 or 1, in order to avoid unnecessary array extraction.
- Parameters:
array
- the array to sort- See Also:
Arrays.sort(Object[], java.util.Comparator)
sortIfNecessary
public static void sortIfNecessary(Object value)
Sort the given array or List with a default AnnotationAwareOrderComparator, if necessary. Simply skips sorting when given any other value.Optimized to skip sorting for lists with size 0 or 1, in order to avoid unnecessary array extraction.
- Parameters:
value
- the array or List to sort- See Also:
Arrays.sort(Object[], java.util.Comparator)