public class

OrderComparator

extends Object
implements Comparator<T>
java.lang.Object
   ↳ org.springframework.core.OrderComparator
Known Direct Subclasses

Class Overview

Comparator implementation for Ordered objects, sorting by order value ascending (resp. by priority descending).

Non-Ordered objects are treated as greatest order values, thus ending up at the end of the list, in arbitrary order (just like same order values of Ordered objects).

Summary

Fields
public static OrderComparator INSTANCE Shared default instance of OrderComparator.
Public Constructors
OrderComparator()
Public Methods
int compare(Object o1, Object o2)
static void sort(List<?> list)
Sort the given List with a default OrderComparator.
static void sort(Object[] array)
Sort the given array with a default OrderComparator.
Protected Methods
int getOrder(Object obj)
Determine the order value for the given object.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.util.Comparator

Fields

public static OrderComparator INSTANCE

Also: SpringCore

Shared default instance of OrderComparator.

Public Constructors

public OrderComparator ()

Also: SpringCore

Public Methods

public int compare (Object o1, Object o2)

Also: SpringCore

public static void sort (List<?> list)

Also: SpringCore

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

public static void sort (Object[] array)

Also: SpringCore

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

Protected Methods

protected int getOrder (Object obj)

Also: SpringCore

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