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.
    • 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
    • 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

      public static int getOrder(Ordered o)
      Get the order for the given Ordered object.
      Parameters:
      o - The ordered object
      Returns:
      the order