- java.lang.Object
-
- io.helidon.common.serviceloader.Priorities
-
public final class Priorities extends Object
Priority utilities.
-
-
Method Summary
All Methods Static Methods Concrete Methods 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 ofPrioritized
, and/or optionally annotated withPriority
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.
-
-
-
Method Detail
-
find
public static int find(Class<?> aClass, int defaultPriority)
Find priority from class annotation, or return default if none found.- Parameters:
aClass
- class to analyzeddefaultPriority
- default priority of this class- Returns:
- priority from
Priority
or the default provided
-
find
public static int find(Object anObject, int defaultPriority)
Find priority for an instance. First checks if instance isPrioritized
. If so, uses the value from it. Then checks forPriority
annotation. If none of the above is found, returns the default priority.- Parameters:
anObject
- object to find priority fordefaultPriority
- 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 sortdefaultPriority
- default priority for elements that do not have it
- If element implements
-
priorityComparator
public static <S> Comparator<S> priorityComparator(int defaultPriority)
Returns a comparator for two objects, the classes for which are implementations ofPrioritized
, and/or optionally annotated withPriority
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 thePriority
annotation- Returns:
- comparator
-
-