Class DefaultServiceProvider

  • All Implemented Interfaces:
    java.lang.Comparable<javax.measure.spi.ServiceProvider>

    public class DefaultServiceProvider
    extends javax.measure.spi.ServiceProvider
    implements java.lang.Comparable<javax.measure.spi.ServiceProvider>
    This class extends the ServiceProvider class and hereby uses the JDK ServiceLoader to load the required services.
    Since:
    1.0
    Version:
    1.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.Class,​javax.measure.spi.QuantityFactory> QUANTITY_FACTORIES  
      private static java.util.Comparator<java.lang.Object> SERVICE_COMPARATOR  
      private java.util.Map<java.lang.Class,​java.util.List<java.lang.Object>> servicesLoaded
      List of services loaded, per class.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static int compareServices​(java.lang.Object o1, java.lang.Object o2)  
      int compareTo​(javax.measure.spi.ServiceProvider o)  
      int getPriority()
      Returns a priority value of 10.
      <Q extends javax.measure.Quantity<Q>>
      javax.measure.spi.QuantityFactory<Q>
      getQuantityFactory​(java.lang.Class<Q> quantity)
      Return a factory for this quantity
      protected <T> T getService​(java.lang.Class<T> serviceType)  
      protected <T> java.util.List<T> getServices​(java.lang.Class<T> serviceType)
      Loads and registers services.
      javax.measure.spi.SystemOfUnitsService getSystemOfUnitsService()  
      javax.measure.spi.UnitFormatService getUnitFormatService()  
      private <T> java.util.List<T> loadServices​(java.lang.Class<T> serviceType)
      Loads and registers services.
      • Methods inherited from class javax.measure.spi.ServiceProvider

        available, current, setCurrent
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • servicesLoaded

        private final java.util.Map<java.lang.Class,​java.util.List<java.lang.Object>> servicesLoaded
        List of services loaded, per class.
      • SERVICE_COMPARATOR

        private static final java.util.Comparator<java.lang.Object> SERVICE_COMPARATOR
      • QUANTITY_FACTORIES

        private final java.util.Map<java.lang.Class,​javax.measure.spi.QuantityFactory> QUANTITY_FACTORIES
    • Constructor Detail

      • DefaultServiceProvider

        public DefaultServiceProvider()
    • Method Detail

      • getPriority

        public int getPriority()
        Returns a priority value of 10.
        Overrides:
        getPriority in class javax.measure.spi.ServiceProvider
        Returns:
        10, overriding the default provider.
      • getServices

        protected <T> java.util.List<T> getServices​(java.lang.Class<T> serviceType)
        Loads and registers services.
        Type Parameters:
        T - the concrete type.
        Parameters:
        serviceType - The service type.
        Returns:
        the items found, never null.
      • getService

        protected <T> T getService​(java.lang.Class<T> serviceType)
      • compareServices

        static int compareServices​(java.lang.Object o1,
                                   java.lang.Object o2)
      • loadServices

        private <T> java.util.List<T> loadServices​(java.lang.Class<T> serviceType)
        Loads and registers services.
        Type Parameters:
        T - the concrete type.
        Parameters:
        serviceType - The service type.
        Returns:
        the items found, never null.
      • compareTo

        public int compareTo​(javax.measure.spi.ServiceProvider o)
        Specified by:
        compareTo in interface java.lang.Comparable<javax.measure.spi.ServiceProvider>
      • getSystemOfUnitsService

        public javax.measure.spi.SystemOfUnitsService getSystemOfUnitsService()
        Specified by:
        getSystemOfUnitsService in class javax.measure.spi.ServiceProvider
      • getUnitFormatService

        public javax.measure.spi.UnitFormatService getUnitFormatService()
        Specified by:
        getUnitFormatService in class javax.measure.spi.ServiceProvider
      • getQuantityFactory

        public final <Q extends javax.measure.Quantity<Q>> javax.measure.spi.QuantityFactory<Q> getQuantityFactory​(java.lang.Class<Q> quantity)
        Return a factory for this quantity
        Specified by:
        getQuantityFactory in class javax.measure.spi.ServiceProvider
        Parameters:
        quantity - the quantity type
        Returns:
        the QuantityFactory
        Throws:
        java.lang.NullPointerException