|Re: 'valueOf' function appears to not be part of the Unit class [message #1519485 is a reply to message #1476835]
||Sat, 20 December 2014 18:01
| Werner Keil
Registered: July 2009
Thanks for your message and observation.
This is a bit of a legacy from JSR 275 (which is currently used by other
Eclipse projects, especially uDig under the GeoTools umbrella) and when we
restructured the API into a more abstract layer, Unit became an interface
and (unless you risk being compatible only with Java SE 8;-) cannot define
such a static factory method.
You'll find them either on abstract base classes like AbstractUnit or
concrete sub-classes in UOMo.
Note, in the near future (as soon as the Early Draft, see
https://java.net/projects/unitsofmeasurement/downloads is made available by
jcp.org and a CQ processed by Eclipse Legal) UOMo shall be upgraded to JSR
363, the Units of Measurement Standard accepted by the Java Community
Process earlier this year. A few patterns you see in the Reference
Implementation will be adopted accordingly. E.g. valueOf() gets a short-cut
named of() in most cases, parsing from a string normally called parse(),
etc. Since the API is backward compatible till at least Java SE 6 (similar
to a vast majority of Eclipse projects) there won't be a Unit.of() method
there either, but UOMo should get some.
Existing methods like public static Unit<?> valueOf(CharSequence
charSequence) in AbstractUnit (as mentioned, that's where UOMo has it, we'll
fix JavaDoc thanks to your note;-) will remain for backward-compatibility,
but we'll likely add a similar method called parse() to align with JSR 363
RI. UOMo having a bigger payload via ICU4J was considered as RI briefly, but
aiming at standalone JVMs and especially smaller Embedded (IoT) ones we
decided to create a smaller independent RI. While UOMo will make use of Java
SE and ICU4J and OSGi to implement JSR 363, too.
"Andrew Broadbent" schrieb im Newsbeitrag
I've just started using the uomo api, thanks for your work on it. In a
previous post I talked about packaging up the library into a single jar
file; I've now done this via having a project include all the required libs
and using fatjar to create a single .jar (for reference I used
Now when I come to use it, the compiler can find all the required types, I
can even run the code in the tutorial (so I don't suspect it's a packaging
issue), when I try to parse a unit string using the code in the reference
Unit<Length> m = Unit.valueOf("m").asType(Length.class);
'valueOf' doesn't appear to be a function of Unit. Has this function moved?
I've tries looking through the classes I thought it would be on, but I
cannot seem to find it. Has the API for parsing unit strings changed?
Powered by FUDForum
. Page generated in 0.01590 seconds