Use Advanced Search to search the entire archive.
[jsr363-experts] Re: Issue in creating TransformedUnit
- From: Werner Keil <
>
- To: Anakar Parida <
>
- Cc: "
" <
>
- Subject: [jsr363-experts] Re: Issue in creating TransformedUnit
- Date: Mon, 16 Feb 2015 14:30:05 +0100
Anakar,
Sorry to respond a little later here. We already discussed a few aspects in
GChat, but I wanted to share it with the EG alias, too.
The issues you faced are reasonably well known. Mostly related to a
discrepancy between getSymbol() for certain units, especially
TransformedUnit and the way these units are defined by catalogues like UCUM
https://github.com/unitsofmeasurement/uom-se/issues/54
Thus if you load such unit from a UCUM data source like the
ucum-essence.xml file, one gets correct data including the symbol if the
file is parsed and mapped to API types correctly. See the UCUM bundle in
Eclipse UOMo using the prior Unit-API (0.6) both against strongly-typed SI
or US unit systems or UCUM via a "more weakly-typed" representation. Where
only core types like Unit are used, but not the "quantity" package. The way
JScience 5 and inspired by it our initial RI/SE port represent UCUM also as
a unit system is derived from strongly-typed units defined in SI, thus the
base units are also the same as there. Meaning "GRAM" (seen by UCUM as the
base unit for mass) is derived from "KILOGRAM" therefore the
TransformedUnit behaved differently in our implementation. TransformedUnit
would take the symbol of its parent/base unit which is "kg" not "g".
To overcome that dilemma and also meet the criteria of Unit JavaDoc (
http://www.unitsofmeasurement.org/jsr-363/apidocs/javax/measure/Unit.html#getSymbol())
a TransformedUnit currently doesn't carry a symbol. What you see if you
instantiate one is the literal formatted operation since there is no
symbol.
We either have to solve this in the SE port (in a way that is compatible
with the API and where they define the same elements also RI!) for these
classes or offer additional ways of labeling, also see this new issue
https://github.com/unitsofmeasurement/uom-se/issues/60.
Thanks for your offer to help, we highly appreciate other JUGs and their
members to adopt JSR 363 and related projects.
Werner
On Fri, Feb 13, 2015 at 9:25 PM, Anakar Parida
<
>
wrote:
>
>
Hi Werner,
>
>
I am trying to build uom-astronomy. I am stuck while creating unit. There
>
are few questions
>
>
1. How can I create a TransformedUnit which on printing will display the
>
value along with unit I have given while creating. For example
>
>
*public static final TransformedUnit<Length> ASTRONOMICAL_UNIT*
>
* = new TransformedUnit<Length>("AU", SI.METRE, new
>
MultiplyConverter(149597871000.0));*
>
>
Now I create a quantity for the above unit. For example
>
>
*Quantity<Length> peri =
>
QuantityFactoryProvider.getQuantityFactory(Length.class).create(0.9832687
>
<%280.9832687>, AstronomicalSystemOfUnits.ASTRONOMICAL_UNIT);*
>
>
If I print peri it gives me output as *0.9832687 <0.9832687>
>
m·149597871000* but my desired output is *0.9832687 <0.9832687> AU*.
>
>
2. If the above desired output cannot be obtained by TransformedUnit then
>
which type of unit and how should I code to achieve the same? (Note - I
>
need a converter too that converts AU to METRE. So that if I do
>
*peri.getUnit().getConverterTo(SIPrefix.KILO(SI.METRE))* then it can
>
convert to the specific desired type).
>
>
Thanks in advance. Please help me to reach to a solution for the above
>
problem
>
>
Regards
>
Anakar Parida
>
>
>
[jsr363-experts] Re: Issue in creating TransformedUnit
|
Werner Keil |
02/16/2015 |