java.lang.Object
io.helidon.common.serviceloader.Priorities

public final class Priorities extends Object
Priority utilities.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    find(Class<?> aClass, int defaultPriority)
    Find priority from class annotation, or return default if none found.
    static int
    find(Object anObject, int defaultPriority)
    Find priority for an instance.
    static <S> Comparator<S>
    priorityComparator(int defaultPriority)
    Returns a comparator for two objects, the classes for which are implementations of Prioritized, and/or optionally annotated with Priority and which applies a specified default priority if either or both classes lack the annotation.
    static void
    sort(List<?> list, int defaultPriority)
    Sort the list based on priorities.
    static void
    sort(List<? extends Prioritized> list)
    Sort the prioritized list based on priorities.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • find

      public static int find(Class<?> aClass, int defaultPriority)
      Find priority from class annotation, or return default if none found.
      Parameters:
      aClass - class to analyzed
      defaultPriority - default priority of this class
      Returns:
      priority from Priorityor the default provided
    • find

      public static int find(Object anObject, int defaultPriority)
      Find priority for an instance. First checks if instance is Prioritized. If so, uses the value from it. Then checks for Priority annotation. If none of the above is found, returns the default priority.
      Parameters:
      anObject - object to find priority for
      defaultPriority - default priority to use
      Returns:
      priority of the object or default provided
    • sort

      public static void sort(List<? extends Prioritized> list)
      Sort the prioritized list based on priorities.
      Parameters:
      list - list to sort
    • sort

      public static void sort(List<?> list, int defaultPriority)
      Sort the list based on priorities.
      • If element implements Prioritized, uses its priority.
      • If element is a class and has annotation Priority, uses its priority
      • If element is any object and its class has annotation Priority, uses its priority
      Parameters:
      list - list to sort
      defaultPriority - default priority for elements that do not have it
    • priorityComparator

      public static <S> Comparator<S> priorityComparator(int defaultPriority)
      Returns a comparator for two objects, the classes for which are implementations of Prioritized, and/or optionally annotated with Priority and which applies a specified default priority if either or both classes lack the annotation.
      Type Parameters:
      S - type of object being compared
      Parameters:
      defaultPriority - used if the classes for either or both objects lack the Priority annotation
      Returns:
      comparator