类 OrderComparator
- java.lang.Object
- org.springframework.core.OrderComparator
- 所有已实现的接口:
Comparator<Object>
public class OrderComparator extends Object implements Comparator<Object>
Comparatorimplementation forOrderedobjects, sorting by order value ascending, respectively by priority descending.Same Order Objects
Objects that have the same order value will be sorted with arbitrary ordering with respect to other objects with the same order value.
Non-ordered Objects
Any object that does not provide its own order value is implicitly assigned a value of
Ordered.LOWEST_PRECEDENCE, thus ending up at the end of a sorted collection in arbitrary order with respect to other objects with the same order value.- 从以下版本开始:
- 07.04.2003
- 作者:
- Juergen Hoeller, Sam Brannen
- 另请参阅:
Ordered,AnnotationAwareOrderComparator,Collections.sort(java.util.List, java.util.Comparator),Arrays.sort(Object[], java.util.Comparator)
嵌套类概要
嵌套类 修饰符和类型 类 说明 static interfaceOrderComparator.OrderSourceProviderStrategy interface to provide an order source for a given object.
字段概要
字段 修饰符和类型 字段 说明 static OrderComparatorINSTANCEShared default instance ofOrderComparator.
构造器概要
构造器 构造器 说明 OrderComparator()
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 intcompare(Object o1, Object o2)protected IntegerfindOrder(Object obj)Find an order value indicated by the given object.protected intgetOrder(Object obj)Determine the order value for the given object.IntegergetPriority(Object obj)Determine a priority value for the given object, if any.static voidsort(Object[] array)Sort the given array with a default OrderComparator.static voidsort(List<?> list)Sort the given List with a default OrderComparator.static voidsortIfNecessary(Object value)Sort the given array or List with a default OrderComparator, if necessary.Comparator<Object>withSourceProvider(OrderComparator.OrderSourceProvider sourceProvider)Build an adapted order comparator with the given source provider.从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
字段详细资料
INSTANCE
public static final OrderComparator INSTANCE
Shared default instance ofOrderComparator.
构造器详细资料
OrderComparator
public OrderComparator()
方法详细资料
withSourceProvider
public Comparator<Object> withSourceProvider(OrderComparator.OrderSourceProvider sourceProvider)
Build an adapted order comparator with the given source provider.- 参数:
sourceProvider- the order source provider to use- 返回:
- the adapted comparator
- 从以下版本开始:
- 4.1
getOrder
protected int getOrder(Object obj)
Determine the order value for the given object.The default implementation checks against the
Orderedinterface through delegating tofindOrder(java.lang.Object). Can be overridden in subclasses.- 参数:
obj- the object to check- 返回:
- the order value, or
Ordered.LOWEST_PRECEDENCEas fallback
findOrder
protected Integer findOrder(Object obj)
Find an order value indicated by the given object.The default implementation checks against the
Orderedinterface. Can be overridden in subclasses.- 参数:
obj- the object to check- 返回:
- the order value, or
nullif none found
getPriority
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.- 参数:
obj- the object to check- 返回:
- the priority value, or
nullif none - 从以下版本开始:
- 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.
- 参数:
list- the List to sort- 另请参阅:
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.
- 参数:
array- the array to sort- 另请参阅:
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.
- 参数:
value- the array or List to sort- 另请参阅:
Arrays.sort(Object[], java.util.Comparator)