Class AnnotationAwareOrderComparator
java.lang.Object
org.springframework.core.OrderComparator
org.springframework.core.annotation.AnnotationAwareOrderComparator
- All Implemented Interfaces:
Comparator<Object>
AnnotationAwareOrderComparator is an extension of
OrderComparator that supports Spring's
Ordered interface as well as the
@Order and @Priority
annotations, with an order value provided by an Ordered
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
FieldsModifier and TypeFieldDescriptionstatic final AnnotationAwareOrderComparatorShared default instance ofAnnotationAwareOrderComparator. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected IntegergetPriority(Object obj) static voidSort the given array with a default AnnotationAwareOrderComparator.static voidSort the given list with a defaultAnnotationAwareOrderComparator.static voidsortIfNecessary(Object value) Sort the given array or List with a default AnnotationAwareOrderComparator, if necessary.Methods inherited from class org.springframework.core.OrderComparator
compare, getOrder, withSourceProviderMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
INSTANCE
Shared default instance ofAnnotationAwareOrderComparator.
-
-
Constructor Details
-
AnnotationAwareOrderComparator
public AnnotationAwareOrderComparator()
-
-
Method Details
-
findOrder
This implementation checks for@Orderor@Priorityon various kinds of elements, in addition to theOrderedcheck in the superclass.- Overrides:
findOrderin classOrderComparator- Parameters:
obj- the object to check- Returns:
- the order value, or
nullif none found
-
getPriority
This implementation retrieves an @Priorityvalue, allowing for additional semantics over the regular @Orderannotation: typically, selecting one object over another in case of multiple matches but only one object to be returned.- Overrides:
getPriorityin classOrderComparator- Parameters:
obj- the object to check- Returns:
- the priority value, or
nullif none
-
sort
Sort the given list with a defaultAnnotationAwareOrderComparator.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:
-
sort
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:
-
sortIfNecessary
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:
-