Package org.apache.sis.measure
Class UnitServices
- Object
-
- ServiceProvider
-
- UnitServices
-
- All Implemented Interfaces:
SystemOfUnitsService,UnitFormatService
public class UnitServices extends ServiceProvider implements SystemOfUnitsService, 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 usesUnitspre-defined constants andUnitFormatdirectly 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. AUnitServicesinstance can be obtained by call toServiceProvider.current().- Since:
- 0.8
Defined in the
sis-utilitymodule
-
-
Constructor Summary
Constructors Constructor Description UnitServices()Creates a new service provider.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<String>getAvailableFormatNames()Returns a list of available format names.Collection<SystemOfUnits>getAvailableSystemsOfUnits()Returns the list of all available systems of units.<Q extends Quantity<Q>>
QuantityFactory<Q>getQuantityFactory(Class<Q> type)Return a factory for the givenQuantitytype.SystemOfUnitsgetSystemOfUnits()Returns the default system of units used by Apache SIS.SystemOfUnitsgetSystemOfUnits(String name)Returns the system of units having the specified name, ornullif none.SystemOfUnitsServicegetSystemOfUnitsService()Returns the service to obtain aSystemOfUnitsinstances.UnitFormatgetUnitFormat()Returns an unit format instance for human-readable unit symbols in the default locale.UnitFormatgetUnitFormat(String name)Returns the unit format for the given name.UnitFormatServicegetUnitFormatService()Returns the service to obtain aUnitFormatinstances.-
Methods inherited from class ServiceProvider
available, current, getPriority, setCurrent
-
-
-
-
Constructor Detail
-
UnitServices
public UnitServices()
Creates a new service provider.UnitServicesshould not be instantiated directly unless the caller wants specifically the Apache SIS implementation. For obtaining the default implementation, useServiceProvider.current()instead.
-
-
Method Detail
-
getSystemOfUnits
public 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 theUnitsclass.- Specified by:
getSystemOfUnitsin interfaceSystemOfUnitsService- Returns:
- the system of units used by Apache SIS.
-
getSystemOfUnits
public SystemOfUnits getSystemOfUnits(String name)
Returns the system of units having the specified name, ornullif none. The argument can be any name in the following table:
The search for name is case-insensitive and ignore whitespaces.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:
getSystemOfUnitsin interfaceSystemOfUnitsService- Parameters:
name- the name of the desired system of units.- Returns:
- the system of units for the given name, or
nullif none.
-
getAvailableSystemsOfUnits
public Collection<SystemOfUnits> getAvailableSystemsOfUnits()
Returns the list of all available systems of units.- Specified by:
getAvailableSystemsOfUnitsin interfaceSystemOfUnitsService- Returns:
- list of available systems of units.
-
getSystemOfUnitsService
public SystemOfUnitsService getSystemOfUnitsService()
Returns the service to obtain aSystemOfUnitsinstances. The default implementation returnsthissince thisUnitServicesclass implements directly all relevant interfaces. The methods related to system of units are:- Specified by:
getSystemOfUnitsServicein classServiceProvider- Returns:
- the service to obtain a
SystemOfUnits, ornullif none.
-
getUnitFormat
public 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:
getUnitFormatin interfaceUnitFormatService- Returns:
- a
UnitFormatinstance for unit symbols.
-
getUnitFormat
public UnitFormat getUnitFormat(String name)
Returns the unit format for the given name. The argument can be the name of any value in theUnitFormat.Styleenumeration. The argument can be any name in the following table:
TheAvailable 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:
getUnitFormatin interfaceUnitFormatService- Parameters:
name- the name of the desired format.- Returns:
- the corresponding unit format, or
nullif none.
-
getAvailableFormatNames
public Set<String> getAvailableFormatNames()
Returns a list of available format names. The default implementation returns the names of all values in theUnitFormat.Styleenumeration.- Specified by:
getAvailableFormatNamesin interfaceUnitFormatService- Returns:
- list of available formats.
-
getUnitFormatService
public UnitFormatService getUnitFormatService()
Returns the service to obtain aUnitFormatinstances. The default implementation returnsthissince thisUnitServicesclass implements directly all relevant interfaces. The methods related to unit formats are:- Specified by:
getUnitFormatServicein classServiceProvider- Returns:
- the service to obtain a
UnitFormat, ornullif none.
-
getQuantityFactory
public <Q extends Quantity<Q>> QuantityFactory<Q> getQuantityFactory(Class<Q> type)
Return a factory for the givenQuantitytype. In the particular case of Apache SIS implementation,Quantities.create(double, Unit)provides a more direct way to instantiate quantities.- Specified by:
getQuantityFactoryin classServiceProvider- Type Parameters:
Q- compile-time value of thetypeargument.- Parameters:
type- type of the desired the quantity.- Returns:
- the service to obtain
Quantityinstances, ornullif none. - See Also:
Quantities.create(double, Unit)
-
-