Top Description Fields Constructors Methods
tech.units.indriya.spi

public abstract Class AbstractServiceProvider

extends ServiceProvider
implements Comparable<ServiceProvider>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Known Direct Subclasses
tech.units.indriya.spi.DefaultServiceProvider
Imports
javax.measure.Quantity, javax.measure.spi.FormatService, .QuantityFactory, .ServiceProvider, .SystemOfUnitsService, tech.units.indriya.quantity.DefaultQuantityFactory, java.util.ArrayList, .Collections, .Comparator, .List, .Map, .Objects, .ServiceLoader, java.util.concurrent.ConcurrentHashMap, java.util.logging.Level, java.util.logging.Logger

This class extends the javax.measure.spi.ServiceProvider class and hereby uses the JDK java.util.ServiceLoader to load the required services.
Author
Werner Keil
Since
2.0
Version
2.0

Field Summary

Modifier and TypeField and Description
private final Map<Class<T>, QuantityFactory<Q extends Quantity<Q>>>
private static final Comparator<Object>
private final Map<Class<T>, List<Object>>
servicesLoaded

List of services loaded, per class.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static int
public int
compareTo(ServiceProvider
the object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

public FormatService
getFormatService()

Implements abstract javax.measure.spi.ServiceProvider.getFormatService.

Returns the service to obtain UnitFormat and QuantityFormat or null if none.

public final <Q extends Quantity<Q>> QuantityFactory<Q>

Returns:

the QuantityFactory
getQuantityFactory
(Class<Q>
the quantity type
quantity
)

Implements abstract javax.measure.spi.ServiceProvider.getQuantityFactory.

Return a factory for this quantity

protected <T> T
getService(Class<T> serviceType)

protected <
the concrete type.
T
>
List<T>

Returns:

the items found, never null.
getServices
(final Class<T>
The service type.
serviceType
)

Loads and registers services.

public SystemOfUnitsService
getSystemOfUnitsService()

Implements abstract javax.measure.spi.ServiceProvider.getSystemOfUnitsService.

Returns the service to obtain a SystemOfUnits, or null if none.

private <
the concrete type.
T
>
List<T>

Returns:

the items found, never null.
loadServices
(final Class<T>
The service type.
serviceType
)

Loads and registers services.

public abstract String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from javax.measure.spi.ServiceProvider:
availablecurrentgetPriorityofsetCurrent

Field Detail

QUANTITY_FACTORIESback to summary
private final Map<Class<T>, QuantityFactory<Q extends Quantity<Q>>> QUANTITY_FACTORIES
Annotations
@SuppressWarnings:rawtypes
SERVICE_COMPARATORback to summary
private static final Comparator<Object> SERVICE_COMPARATOR
servicesLoadedback to summary
private final Map<Class<T>, List<Object>> servicesLoaded

List of services loaded, per class.

Annotations
@SuppressWarnings:rawtypes

Constructor Detail

AbstractServiceProviderback to summary
public AbstractServiceProvider()

Method Detail

compareServicesback to summary
private static int compareServices(Object o1, Object o2)
compareToback to summary
public int compareTo(ServiceProvider o)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
o:ServiceProvider

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
getFormatServiceback to summary
public FormatService getFormatService()

Implements abstract javax.measure.spi.ServiceProvider.getFormatService.

Doc from javax.measure.spi.ServiceProvider.getFormatService.

Returns the service to obtain UnitFormat and QuantityFormat or null if none.

Returns:FormatService

the service to obtain a UnitFormat and QuantityFormat, or null.

Annotations
@Override
getQuantityFactoryback to summary
public final <Q extends Quantity<Q>> QuantityFactory<Q> getQuantityFactory(Class<Q> quantity)

Implements abstract javax.measure.spi.ServiceProvider.getQuantityFactory.

Return a factory for this quantity

Parameters
<Q>

Doc from javax.measure.spi.ServiceProvider.getQuantityFactory. the type of the Quantity instances created by the factory

quantity:Class<Q>

the quantity type

Returns:QuantityFactory<Q>

the QuantityFactory

Annotations
@Override
@SuppressWarnings:unchecked
Exceptions
NullPointerException:
if quantity is null
getServiceback to summary
protected <T> T getService(Class<T> serviceType)
getServicesback to summary
protected <T> List<T> getServices(final Class<T> serviceType)

Loads and registers services.

Parameters
<T>
the concrete type.
serviceType:Class<T>

The service type.

Returns:List<T>

the items found, never null.

getSystemOfUnitsServiceback to summary
public SystemOfUnitsService getSystemOfUnitsService()

Implements abstract javax.measure.spi.ServiceProvider.getSystemOfUnitsService.

Doc from javax.measure.spi.ServiceProvider.getSystemOfUnitsService.

Returns the service to obtain a SystemOfUnits, or null if none.

Returns:SystemOfUnitsService

the service to obtain a SystemOfUnits, or null.

Annotations
@Override
loadServicesback to summary
private <T> List<T> loadServices(final Class<T> serviceType)

Loads and registers services.

Parameters
<T>
the concrete type.
serviceType:Class<T>

The service type.

Returns:List<T>

the items found, never null.

toStringback to summary
public abstract String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override