Comparator implementation for Ordered objects, sorting
by order value ascending, respectively by priority descending.
PriorityOrdered ObjectsPriorityOrdered objects will be sorted with higher priority than
plain Ordered objects.
Objects that have the same order value will be sorted with arbitrary ordering with respect to other objects with the same order value.
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.
Ordered, PriorityOrdered, org.springframework.core.annotation.AnnotationAwareOrderComparator , java.util.List#sort(java.util.Comparator) , java.util.Arrays#sort(Object[], java.util.Comparator)
| Modifier and Type | Class and Description |
|---|---|
| public static interface | OrderComparator.
Strategy interface to provide an order source for a given object. |
| Modifier and Type | Field and Description |
|---|---|
| public static final OrderComparator | INSTANCE
Shared default instance of |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public int | compare(Object
the first object to be compared. o1, Object the second object to be compared. o2)Implements java. Compares its two arguments for order. |
| private int | |
| protected Integer | |
| private int | Returns: the order value, orOrdered.LOWEST_PRECEDENCE as fallbackthe object to check obj, OrderComparator.Determine the order value for the given object. |
| protected int | |
| public Integer | Returns: the priority value, ornull if nonethe object to check obj)Determine a priority value for the given object, if any. |
| public static void | |
| public static void | |
| public static void | sortIfNecessary(Object
the array or List to sort value)Sort the given array or List with a default OrderComparator, if necessary. |
| public Comparator | Returns: the adapted comparatorthe order source provider to use sourceProviderBuild an adapted order comparator with the given source provider. |
| INSTANCE | back to summary |
|---|---|
| public static final OrderComparator INSTANCE Shared default instance of | |
| OrderComparator | back to summary |
|---|---|
| public OrderComparator() | |
| compare | back to summary |
|---|---|
| public int compare(Object o1, Object o2) Implements java. Doc from java. Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
The implementor must ensure that
The implementor must also ensure that the relation is transitive:
Finally, the implementor must ensure that | |
| doCompare | back to summary |
|---|---|
| private int doCompare(Object o1, Object o2, OrderComparator. | |
| findOrder | back to summary |
|---|---|
| protected Integer findOrder(Object obj) Find an order value indicated by the given object. The default implementation checks against the | |
| getOrder | back to summary |
|---|---|
| private int getOrder(Object obj, OrderComparator. Determine the order value for the given object. The default implementation checks against the given
| |
| getOrder | back to summary |
|---|---|
| protected int getOrder(Object obj) Determine the order value for the given object. The default implementation checks against the
| |
| getPriority | back to summary |
|---|---|
| public Integer getPriority(Object obj) Determine a priority value for the given object, if any. The default implementation always returns | |
| sort | back to summary |
|---|---|
| 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.
| |
| sort | back to summary |
|---|---|
| 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.
| |
| sortIfNecessary | back to summary |
|---|---|
| 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.
| |
| withSourceProvider | back to summary |
|---|---|
| public Comparator Build an adapted order comparator with the given source provider.
| |
| Modifier and Type | Method and Description |
|---|---|
| public Object | Returns: the order source for that object, ornull if none foundthe object to find an order source for obj)Return an order source for the specified object, i.e. an object that should be checked for an order value as a replacement to the given object. |
| getOrderSource | back to summary |
|---|---|
| public Object getOrderSource(Object obj) Return an order source for the specified object, i.e. an object that should be checked for an order value as a replacement to the given object. Can also be an array of order source objects. If the returned object does not indicate any order, the comparator will fall back to checking the original object. | |