Class OrderUtil

java.lang.Object
io.micronaut.core.order.OrderUtil

public class OrderUtil extends Object
Apply the Ordered interface to lists or arrays.
Since:
1.0
Author:
Graeme Rocher
  • Field Details

    • COMPARATOR

      public static final Comparator<Object> COMPARATOR
      Provide a comparator for collections.
    • ORDERED_COMPARATOR

      public static final Comparator<Ordered> ORDERED_COMPARATOR
      The comparator of elements implementing Ordered.
    • REVERSE_ORDERED_COMPARATOR

      public static final Comparator<Ordered> REVERSE_ORDERED_COMPARATOR
      The reverse comparator of elements implementing Ordered.
    • REVERSE_COMPARATOR

      public static final Comparator<Object> REVERSE_COMPARATOR
      Provide a comparator, in reversed order, for collections.
  • Constructor Details

    • OrderUtil

      public OrderUtil()
  • Method Details

    • sort

      public static void sort(List<?> list)
      Sort the given list.
      Parameters:
      list - The list to sort
    • sort

      public static <T> Stream<T> sort(Stream<T> list)
      Sort the given list.
      Type Parameters:
      T - The stream generic type
      Parameters:
      list - The list to sort
      Returns:
      The sorted stream
    • sortOrdered

      public static <T extends Ordered> Stream<T> sortOrdered(Stream<T> list)
      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

      public static <T extends Ordered> List<T> sortOrderedCollection(Collection<T> list)
      Sort the given list.
      Type Parameters:
      T - The type
      Parameters:
      list - The list to sort
      Returns:
      The sorted collection
      Since:
      4.4.0
    • sortOrdered

      public static <T extends Ordered> void sortOrdered(List<T> list)
      Sort the given list.
      Type Parameters:
      T - The type
      Parameters:
      list - The list to sort
      Since:
      4.4.0
    • reverseSortOrdered

      public static <T extends Ordered> void reverseSortOrdered(List<T> list)
      Sort the given list.
      Type Parameters:
      T - The type
      Parameters:
      list - The list to sort
      Since:
      4.4.0
    • reverseSort

      public static void reverseSort(List<?> list)
      Sort the given list.
      Parameters:
      list - The list to sort
    • reverseSort

      public static void reverseSort(Object[] array)
      Sort the given array in reverse order.
      Parameters:
      array - The array to sort
    • sort

      public static void sort(Ordered... objects)
      Sort the given array.
      Parameters:
      objects - The array to sort
    • sort

      public static void sort(Object[] objects)
      Sort the given array.
      Parameters:
      objects - The array to sort
    • getOrder

      public static int getOrder(Object o)
      Get the order for the given object.
      Parameters:
      o - The object
      Returns:
      Ordered.getOrder() when object is instance of Ordered otherwise Ordered.LOWEST_PRECEDENCE
    • getOrder

      public static int getOrder(AnnotationMetadata annotationMetadata, Object o)
      Get the order of the given object. Objects implementing Ordered have precedence over annotation metadata with Order.
      Parameters:
      annotationMetadata - The annotation metadata
      o - The object
      Returns:
      The order of the object. If no order is found, Ordered.LOWEST_PRECEDENCE is returned.
    • getOrder

      public static int getOrder(@NonNull @NonNull AnnotationMetadata annotationMetadata)
      Get the order for the given annotation metadata.
      Parameters:
      annotationMetadata - The metadata
      Returns:
      The order
      Since:
      3.0.0
    • getOrder

      @Deprecated(since="4.4.0", forRemoval=true) public static int getOrder(Ordered o)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Inline method
      Get the order for the given Ordered object.
      Parameters:
      o - The ordered object
      Returns:
      the order