org.springframework.core

Class OrderComparator

    • Field Detail

      • INSTANCE

        public static final OrderComparator INSTANCE
        Shared default instance of OrderComparator.
    • Constructor Detail

      • OrderComparator

        public OrderComparator()
    • Method Detail

      • getOrder

        protected int getOrder(Object obj)
        Determine the order value for the given object.

        The default implementation checks against the Ordered interface. Can be overridden in subclasses.

        Parameters:
        obj - the object to check
        Returns:
        the order value, or Ordered.LOWEST_PRECEDENCE as fallback
      • sort

        public static void sort(List<?> list)
        Sort the given List with a default OrderComparator.

        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 OrderComparator.

        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)