unitsofmeasurement/uom-systems

Guidelines and/or a system for subclassing/expanding an existing System of Units

fref opened this issue · 1 comments

fref commented

If I want to work with/add new units, then serialize values made of a combination of those units and the standard units, what should be be the standard way of doing this?

A cursory glance at UCUM/SI gives the impression that if I want to add new units, I have to create a new AbstractSystemOfUnits child, then redefine or reinject in it all the units of another system manually. No extension mechansim seems to exist.

It would be nice to have some sort of hierarchical structure, similar to the classloader mechanism, to allow one to work with the child system of units, passing the request upwards when a given unit is not found directly in the "managed" units of the child (e.g. when deserializing values)

keilw commented

You get that via ServiceProvider SPI. The SystemsOfUnitsService provides one or more SystemsOfUnits implementations.
It all uses the service loader mechanism.

There is no fallback to another system, you might have to go through various available service providers.
Feel free to create a an example for such mechanisms in uom-demos/console/systems, e.g. UCUM because that uses other systems, but the UCUM system is meant to be complete and consistent anyway, so such a fallback would not make as much sense there. Maybe for US or Imperial and SI, etc. I close this here, because it is not subject to the systems themselves, please create either that demo as a basis if you can, or also a feature request for the SPI in a future version. Could be related to unit-api#90