org.springframework.core.annotation

Class AnnotationAwareOrderComparator

  • All Implemented Interfaces:
    java.util.Comparator<java.lang.Object>


    public class AnnotationAwareOrderComparator
    extends OrderComparator
    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.

    Since:
    2.0.1
    Author:
    Juergen Hoeller, Oliver Gierke, Stephane Nicoll
    See Also:
    Ordered, Order, Priority
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      protected java.lang.Integer findOrder(java.lang.Object obj)
      This implementation checks for @Order or @Priority on various kinds of elements, in addition to the Ordered check in the superclass.
      java.lang.Integer getPriority(java.lang.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.
      static void sort(java.util.List<?> list)
      Sort the given List with a default AnnotationAwareOrderComparator.
      static void sort(java.lang.Object[] array)
      Sort the given array with a default AnnotationAwareOrderComparator.
      static void sortIfNecessary(java.lang.Object value)
      Sort the given array or List with a default AnnotationAwareOrderComparator, if necessary.
      • 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

        comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Constructor Detail

      • AnnotationAwareOrderComparator

        public AnnotationAwareOrderComparator()
    • Method Detail

      • findOrder

        @Nullable
        protected java.lang.Integer findOrder(java.lang.Object obj)
        This implementation checks for @Order or @Priority on various kinds of elements, in addition to the Ordered check in the superclass.
        Overrides:
        findOrder in class OrderComparator
        Parameters:
        obj - the object to check
        Returns:
        the order value, or null if none found
      • getPriority

        @Nullable
        public java.lang.Integer getPriority(java.lang.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 class OrderComparator
        Parameters:
        obj - the object to check
        Returns:
        the priority value, or null if none
      • sort

        public static void sort(java.util.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:
        List.sort(java.util.Comparator)
      • sort

        public static void sort(java.lang.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(java.lang.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)