Class OrderComparator

    • Method Detail

      • getOrder

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

        The default implementation checks against the Ordered interface through delegating to findOrder(java.lang.Object). Can be overridden in subclasses.

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

        @Nullable
        protected Integer findOrder​(Object obj)
        Find an order value indicated by 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 null if none found
      • getPriority

        @Nullable
        public Integer getPriority​(Object obj)
        Determine a priority value for the given object, if any.

        The default implementation always returns null. Subclasses may override this to give specific kinds of values a 'priority' characteristic, in addition to their 'order' semantics. A priority indicates that it may be used for selecting one object over another, in addition to serving for ordering purposes in a list/array.

        Parameters:
        obj - the object to check
        Returns:
        the priority value, or null if none
        Since:
        4.1
      • 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:
        List.sort(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)
      • sortIfNecessary

        public static void sortIfNecessary​(Object value)
        Sort the given array or List with a default OrderComparator, 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)