Package javax.measure.spi
Class ServiceProvider.Selector
java.lang.Object
javax.measure.spi.ServiceProvider.Selector
- All Implemented Interfaces:
Comparator<ServiceProvider>,Predicate<ServiceProvider>
- Enclosing class:
ServiceProvider
private static final class ServiceProvider.Selector
extends Object
implements Predicate<ServiceProvider>, Comparator<ServiceProvider>
A filter and a comparator for processing the stream of service providers.
The two tasks (filtering and sorting) are implemented by the same class,
but the filter task shall be used only if the name to search is non-null.
The comparator is used in all cases, for sorting providers with higher priority first.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final MethodThevalue()method in the "javax.inject.Named" annotation, ornullif that class is not on the classpath.private final MethodThevalue()method in the "javax.annotation.Priority" annotation, ornullif that class is not on the classpath.private final MethodThevalue()method in the "jakarta.inject.Named" annotation, ornullif that class is not on the classpath.private final MethodThevalue()method in the "jakarta.annotation.Priority" annotation, ornullif that class is not on the classpath.private final StringThe name of the provider to search, ornullif no filtering by name is applied. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcompare(ServiceProvider p1, ServiceProvider p2) Compares the given service providers for order based on their priority.private static ObjectInvokes thevalue()method on the annotation of the given class.private static MethodgetValueMethod(String classname) Returns thevalue()method in the given annotation class.private intpriority(ServiceProvider provider) Returns the priority of the given service provider.private Stream<ServiceProvider> stream()Gets allServiceProviders sorted by priority and optionally filtered by the name in this selector.booleantest(ServiceProvider provider) Returnstrueif the given service provider has the name we are looking for.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
toSearch
The name of the provider to search, ornullif no filtering by name is applied. -
nameGetter
Thevalue()method in the "jakarta.inject.Named" annotation, ornullif that class is not on the classpath. -
priorityGetter
Thevalue()method in the "jakarta.annotation.Priority" annotation, ornullif that class is not on the classpath. -
legacyNameGetter
Thevalue()method in the "javax.inject.Named" annotation, ornullif that class is not on the classpath. -
legacyPriorityGetter
Thevalue()method in the "javax.annotation.Priority" annotation, ornullif that class is not on the classpath.
-
-
Constructor Details
-
Selector
Selector(String name) Creates a new filter and comparator for a stream of service providers.- Parameters:
name- name of the desired service provider, ornullif no filtering by name is applied.
-
-
Method Details
-
getValueMethod
Returns thevalue()method in the given annotation class.- Parameters:
classname- name of the class from which to get thevalue()method.- Returns:
- the
value()method, ornullif the annotation class was not found. - Throws:
NoSuchMethodException
-
getValue
Invokes thevalue()method on the annotation of the given class. The annotation on which to invoke the method is given byMethod.getDeclaringClass().- Parameters:
provider- class of the provider on which to invoke annotationvalue().getter- the preferredvalue()method to invoke, ornull.fallback- an alternativevalue()method to invoke, ornull.- Returns:
- the value, or
nullif none.
-
test
Returnstrueif the given service provider has the name we are looking for. This method shall be invoked only if a non-null name has been specified to the constructor. This method looks for the "jakarta.inject.Named" and "javax.inject.Named" annotations in that order, and if none are found fallbacks onObject.toString().- Specified by:
testin interfacePredicate<ServiceProvider>
-
priority
Returns the priority of the given service provider. This method looks for the "jakarta.annotation.Priority" and "javax.annotation.Priority" annotations in that order, and if none are found falls back onServiceProvider.getPriority(). -
compare
Compares the given service providers for order based on their priority. The priority of each provider is determined as documented byServiceProvider.getPriority().- Specified by:
comparein interfaceComparator<ServiceProvider>
-
stream
Gets allServiceProviders sorted by priority and optionally filtered by the name in this selector. The list of service providers is not cached because it depends on the context class loader, which itself depends on which thread is invoking this method.
-