Top Description Fields Constructors Methods
org.springframework.core.annotation

public Class AnnotationAwareOrderComparator

extends OrderComparator
Class Inheritance
Imports
java.lang.reflect.AnnotatedElement, java.util.Arrays, .List, org.springframework.core.DecoratingProxy, .OrderComparator, org.springframework.core.annotation.MergedAnnotations.SearchStrategy, org.springframework.lang.Nullable

AnnotationAwareOrderComparator is an extension of OrderComparator that supports Spring's org.springframework.core.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.

Authors
Juergen Hoeller, Oliver Gierke, Stephane Nicoll
Since
2.0.1
See Also
org.springframework.core.Ordered, org.springframework.core.annotation.Order, jakarta.annotation.Priority

Field Summary

Modifier and TypeField and Description
public static final AnnotationAwareOrderComparator
INSTANCE

Hides org.springframework.core.OrderComparator.INSTANCE.

Shared default instance of AnnotationAwareOrderComparator.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected Integer
findOrder(Object
the object to check
obj
)

Overrides org.springframework.core.OrderComparator.findOrder.

This implementation checks for @Order or @Priority on various kinds of elements, in addition to the org.springframework.core.Ordered check in the superclass.

private Integer
public Integer
getPriority(Object
the object to check
obj
)

Overrides org.springframework.core.OrderComparator.getPriority.

This implementation retrieves an @jakarta.annotation.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.

public static void
sort(List<?>
the List to sort
list
)

Hides org.springframework.core.OrderComparator.sort.

Sort the given list with a default AnnotationAwareOrderComparator.

public static void
sort(Object[]
the array to sort
array
)

Hides org.springframework.core.OrderComparator.sort.

Sort the given array with a default AnnotationAwareOrderComparator.

public static void
sortIfNecessary(Object
the array or List to sort
value
)

Hides org.springframework.core.OrderComparator.sortIfNecessary.

Sort the given array or List with a default AnnotationAwareOrderComparator, if necessary.

Inherited from org.springframework.core.OrderComparator:
comparegetOrderwithSourceProvider

Field Detail

INSTANCEback to summary
public static final AnnotationAwareOrderComparator INSTANCE

Hides org.springframework.core.OrderComparator.INSTANCE.

Shared default instance of AnnotationAwareOrderComparator.

Constructor Detail

AnnotationAwareOrderComparatorback to summary
public AnnotationAwareOrderComparator()

Method Detail

findOrderback to summary
protected Integer findOrder(Object obj)

Overrides org.springframework.core.OrderComparator.findOrder.

This implementation checks for @Order or @Priority on various kinds of elements, in addition to the org.springframework.core.Ordered check in the superclass.

Parameters
obj:Object

Doc from org.springframework.core.OrderComparator.findOrder.

the object to check

Returns:Integer

Doc from org.springframework.core.OrderComparator.findOrder.

the order value, or null if none found

Annotations
@Override
@Nullable
findOrderFromAnnotationback to summary
private Integer findOrderFromAnnotation(Object obj)
Annotations
@Nullable
getPriorityback to summary
public Integer getPriority(Object obj)

Overrides org.springframework.core.OrderComparator.getPriority.

This implementation retrieves an @jakarta.annotation.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.

Parameters
obj:Object

Doc from org.springframework.core.OrderComparator.getPriority.

the object to check

Returns:Integer

Doc from org.springframework.core.OrderComparator.getPriority.

the priority value, or null if none

Annotations
@Override
@Nullable
sortback to summary
public static void sort(List<?> list)

Hides org.springframework.core.OrderComparator.sort.

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:List<?>

the List to sort

See Also
java.util.List#sort(java.util.Comparator)
sortback to summary
public static void sort(Object[] array)

Hides org.springframework.core.OrderComparator.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:Object[]

the array to sort

See Also
java.util.Arrays#sort(Object[], java.util.Comparator)
sortIfNecessaryback to summary
public static void sortIfNecessary(Object value)

Hides org.springframework.core.OrderComparator.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:Object

the array or List to sort

See Also
java.util.Arrays#sort(Object[], java.util.Comparator)