Class OrderUtil
Ordered
interface to lists or arrays.- Since:
- 1.0
- Author:
- Graeme Rocher
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator<Object>
Orders objects usinggetOrder(Object)
, i.e.static final Comparator<Object>
Orders objects usinggetOrderWithDefaultPrecedence(Object, int)
using zero as the default precedence.static final Comparator<Ordered>
The comparator of elements implementingOrdered
.static final Comparator<Object>
Provide a comparator, in reversed order, for collections.static final Comparator<Object>
Provide a comparator, in reversed order, for collections.static final Comparator<Ordered>
The reverse comparator of elements implementingOrdered
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
getOrder
(@NonNull AnnotationMetadata annotationMetadata) Get the order for the given annotation metadata.static int
getOrder
(AnnotationMetadata annotationMetadata, Object o) Get the order of the given object.static int
Deprecated, for removal: This API element is subject to removal in a future version.Inline methodstatic int
Get the order for the given bean instance orAnnotationMetadata
object.static int
getOrderWithDefaultPrecedence
(Object o, int defaultPrecedence) Get the order for the given bean instance if it implementsOrdered
, or for the givenAnnotationMetadata
object.static void
reverseSort
(Object[] array) Sort the given array in reverse order.static void
reverseSort
(List<?> list) Sort the given list.static <T extends Ordered>
voidreverseSortOrdered
(List<T> list) Sort the given list.static void
Sort the given array.static void
Sort the given array.static void
Sort the given list usingCOMPARATOR
.static <T> Stream<T>
Sort the given list.static <T extends Ordered>
voidsortOrdered
(List<T> list) Sort the given list.sortOrdered
(Stream<T> list) Sort the given stream.sortOrderedCollection
(Collection<T> list) Sort the given list.
-
Field Details
-
COMPARATOR
Orders objects usinggetOrder(Object)
, i.e. objects that don't implementOrdered
and which are notAnnotationMetadata
will be placed non-deterministically in the final position.You probably want to use
COMPARATOR_ZERO
instead, as with this comparator no object can sort itself to the back of the collection. -
COMPARATOR_ZERO
Orders objects usinggetOrderWithDefaultPrecedence(Object, int)
using zero as the default precedence. -
ORDERED_COMPARATOR
The comparator of elements implementingOrdered
. -
REVERSE_ORDERED_COMPARATOR
The reverse comparator of elements implementingOrdered
. -
REVERSE_COMPARATOR
Provide a comparator, in reversed order, for collections.You probably want to use
REVERSE_COMPARATOR_ZERO
instead, as with this comparator no object can sort itself to the front of the collection. -
REVERSE_COMPARATOR_ZERO
Provide a comparator, in reversed order, for collections.
-
-
Constructor Details
-
OrderUtil
public OrderUtil()
-
-
Method Details
-
sort
Sort the given list usingCOMPARATOR
.You should probably not use this method. Prefer calling
list.sort(OrderUtil.COMPARATOR_ZERO)
instead, which offers more intuitive behavior for beans that don't expose an ordering.- Parameters:
list
- The list to sort
-
sort
Sort the given list.You should probably not use this method. Prefer calling
stream.sorted(OrderUtil.COMPARATOR_ZERO)
instead, which offers more intuitive behavior for beans that don't expose an ordering.- Type Parameters:
T
- The stream generic type- Parameters:
list
- The list to sort- Returns:
- The sorted stream
-
sortOrdered
Sort the given stream.- Type Parameters:
T
- The stream generic type- Parameters:
list
- The list to sort- Returns:
- The sorted stream
- Since:
- 4.4.0
-
sortOrderedCollection
Sort the given list.- Type Parameters:
T
- The type- Parameters:
list
- The list to sort- Returns:
- The sorted collection
- Since:
- 4.4.0
-
sortOrdered
Sort the given list.- Type Parameters:
T
- The type- Parameters:
list
- The list to sort- Since:
- 4.4.0
-
reverseSortOrdered
Sort the given list.- Type Parameters:
T
- The type- Parameters:
list
- The list to sort- Since:
- 4.4.0
-
reverseSort
Sort the given list.You should probably not use this method. Prefer calling
list.sort(OrderUtil.REVERSE_COMPARATOR_ZERO)
instead, which offers more intuitive behavior for beans that don't expose an ordering.- Parameters:
list
- The list to sort
-
reverseSort
Sort the given array in reverse order.- Parameters:
array
- The array to sort
-
sort
Sort the given array.You should probably not use this method. Prefer calling
Arrays.sort(objects, OrderUtil.COMPARATOR_ZERO)
instead, which offers more intuitive behavior for beans that don't expose an ordering.- Parameters:
objects
- The array to sort
-
sort
Sort the given array.You should probably not use this method. Prefer calling
Arrays.sort(objects, OrderUtil.COMPARATOR_ZERO)
instead, which offers more intuitive behavior for beans that don't expose an ordering.- Parameters:
objects
- The array to sort
-
getOrder
Get the order for the given bean instance orAnnotationMetadata
object.You should probably not use this method. Prefer calling
getOrderWithDefaultPrecedence(Object, int)
with 0 instead, which offers more intuitive behavior for beans that don't expose an ordering.- Parameters:
o
- The object- Returns:
Ordered.getOrder()
when object is instance of Ordered, or the order of theAnnotationMetadata
, orOrdered.LOWEST_PRECEDENCE
if the parameter is neither of those.
-
getOrderWithDefaultPrecedence
Get the order for the given bean instance if it implementsOrdered
, or for the givenAnnotationMetadata
object.- Parameters:
o
- The objectdefaultPrecedence
- What to return if the object is neither an ordered bean nor an annotation metadata object.- Returns:
Ordered.getOrder()
when object is instance of Ordered, or the order of theAnnotationMetadata
, ordefaultPrecedence
if the parameter is neither of those.
-
getOrder
Get the order of the given object. Objects implementingOrdered
have precedence over annotation metadata withOrder
.- Parameters:
annotationMetadata
- The annotation metadatao
- The object- Returns:
- The order of the object. If no order is found,
Ordered.LOWEST_PRECEDENCE
is returned.
-
getOrder
Get the order for the given annotation metadata.- Parameters:
annotationMetadata
- The metadata- Returns:
- The order or zero if there is no
Order
annotation. - Since:
- 3.0.0
-
getOrder
Deprecated, for removal: This API element is subject to removal in a future version.Inline methodGet the order for the given Ordered object.- Parameters:
o
- The ordered object- Returns:
- the order
-