Package org.apache.sis.measure
Class UnitServices
java.lang.Object
javax.measure.spi.ServiceProvider
org.apache.sis.measure.UnitServices
- All Implemented Interfaces:
javax.measure.spi.SystemOfUnitsService
,javax.measure.spi.UnitFormatService
public class UnitServices
extends javax.measure.spi.ServiceProvider
implements javax.measure.spi.SystemOfUnitsService, javax.measure.spi.UnitFormatService
The central point from which all unit services (parsing, formatting, listing, etc) can be obtained.
Apache SIS does not use this class (SIS rather uses
Units
predefined constants and UnitFormat
directly since they are designed specifically for SIS needs).
This class is provided for allowing other applications to discover Apache SIS implementation of JSR-363
without direct dependency. A UnitServices
instance can be obtained by call to ServiceProvider.current()
.- Since:
- 0.8
- Version:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final UnitRegistry[]
All system of units known to this provider. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a list of available format names.Collection
<javax.measure.spi.SystemOfUnits> Returns the list of all available systems of units.<Q extends javax.measure.Quantity<Q>>
javax.measure.spi.QuantityFactory<Q> getQuantityFactory
(Class<Q> type) Return a factory for the givenQuantity
type.javax.measure.spi.SystemOfUnits
Returns the default system of units used by Apache SIS.javax.measure.spi.SystemOfUnits
getSystemOfUnits
(String name) Returns the system of units having the specified name, ornull
if none.javax.measure.spi.SystemOfUnitsService
Returns the service to obtain aSystemOfUnits
instances.javax.measure.format.UnitFormat
Returns an unit format instance for human-readable unit symbols in the default locale.javax.measure.format.UnitFormat
getUnitFormat
(String name) Returns the unit format for the given name.javax.measure.spi.UnitFormatService
Returns the service to obtain aUnitFormat
instances.Methods inherited from class javax.measure.spi.ServiceProvider
available, current, getPriority, setCurrent
-
Field Details
-
systems
All system of units known to this provider. The last element in the array is the default system with all units known to SIS.
-
-
Constructor Details
-
UnitServices
public UnitServices()Creates a new service provider.UnitServices
should not be instantiated directly unless the caller wants specifically the Apache SIS implementation. For obtaining the default implementation, useServiceProvider.current()
instead.
-
-
Method Details
-
getSystemOfUnits
public javax.measure.spi.SystemOfUnits getSystemOfUnits()Returns the default system of units used by Apache SIS. This include the International System of Units (SI) together with some imperial units and other units. This system includes at least all the constants defined in theUnits
class.- Specified by:
getSystemOfUnits
in interfacejavax.measure.spi.SystemOfUnitsService
- Returns:
- the system of units used by Apache SIS.
-
getSystemOfUnits
Returns the system of units having the specified name, ornull
if none. The argument can be any name in the following table:Available system of units Name Examples SI m, km, m³, s, m∕s, K, °C, hPa, rad, µrad SI + accepted s, min, h, m∕s, km∕h, °, ′, ″, ha Imperial in, ft, mi (statute mile) SI + other m, m∕s, km∕h, ft, mi, M (nautical mile) - Specified by:
getSystemOfUnits
in interfacejavax.measure.spi.SystemOfUnitsService
- Parameters:
name
- the name of the desired system of units.- Returns:
- the system of units for the given name, or
null
if none.
-
getAvailableSystemsOfUnits
Returns the list of all available systems of units.- Specified by:
getAvailableSystemsOfUnits
in interfacejavax.measure.spi.SystemOfUnitsService
- Returns:
- list of available systems of units.
-
getSystemOfUnitsService
public javax.measure.spi.SystemOfUnitsService getSystemOfUnitsService()Returns the service to obtain aSystemOfUnits
instances. The default implementation returnsthis
since thisUnitServices
class implements directly all relevant interfaces. The methods related to system of units are:- Specified by:
getSystemOfUnitsService
in classjavax.measure.spi.ServiceProvider
- Returns:
- the service to obtain a
SystemOfUnits
, ornull
if none.
-
getUnitFormat
public javax.measure.format.UnitFormat getUnitFormat()Returns an unit format instance for human-readable unit symbols in the default locale. The format style isUnitFormat.Style.SYMBOL
. This style requires support for Unicode characters; for example square metres are formatted as “m²”, not “m2”.- Specified by:
getUnitFormat
in interfacejavax.measure.spi.UnitFormatService
- Returns:
- a
UnitFormat
instance for unit symbols.
-
getUnitFormat
Returns the unit format for the given name. The argument can be the name of any value in theUnitFormat.Style
enumeration. The argument can be any name in the following table:Available unit format name Name Examples SYMBOL km, m³, m∕s, N⋅m, K, °C, hPa, rad, µrad UCUM km, m3, m/s, N.m NAME kilometre, cubic metre, metres per second "NAME"
format is locale-sensitive. The format locale can be modified by a call toUnitFormat.setLocale(Locale)
on the returned object.- Specified by:
getUnitFormat
in interfacejavax.measure.spi.UnitFormatService
- Parameters:
name
- the name of the desired format.- Returns:
- the corresponding unit format, or
null
if none.
-
getAvailableFormatNames
Returns a list of available format names. The default implementation returns the names of all values in theUnitFormat.Style
enumeration.- Specified by:
getAvailableFormatNames
in interfacejavax.measure.spi.UnitFormatService
- Returns:
- list of available formats.
-
getUnitFormatService
public javax.measure.spi.UnitFormatService getUnitFormatService()Returns the service to obtain aUnitFormat
instances. The default implementation returnsthis
since thisUnitServices
class implements directly all relevant interfaces. The methods related to unit formats are:- Specified by:
getUnitFormatService
in classjavax.measure.spi.ServiceProvider
- Returns:
- the service to obtain a
UnitFormat
, ornull
if none.
-
getQuantityFactory
public <Q extends javax.measure.Quantity<Q>> javax.measure.spi.QuantityFactory<Q> getQuantityFactory(Class<Q> type) Return a factory for the givenQuantity
type. In the particular case of Apache SIS implementation,Quantities.create(double, Unit)
provides a more direct way to instantiate quantities.- Specified by:
getQuantityFactory
in classjavax.measure.spi.ServiceProvider
- Type Parameters:
Q
- compile-time value of thetype
argument.- Parameters:
type
- type of the desired the quantity.- Returns:
- the service to obtain
Quantity
instances. - See Also:
-