Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » UOMo » 'valueOf' function appears to not be part of the Unit class
'valueOf' function appears to not be part of the Unit class [message #1476835] Mon, 17 November 2014 11:44 Go to next message
Andrew Broadbent is currently offline Andrew BroadbentFriend
Messages: 3
Registered: November 2014
Junior Member
Hi Werner,

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 unit-api-0.6.1).

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 document:

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?

Thanks,
-Andrew
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 Go to previous message
Werner Keil is currently offline Werner KeilFriend
Messages: 1085
Registered: July 2009
Senior Member
Hi Andrew,

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.

Regards,
Werner

"Andrew Broadbent" schrieb im Newsbeitrag
news:m4cn26$v9f$1@xxxxxxxxe.org...

Hi Werner,

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
unit-api-0.6.1).

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
document:

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?

Thanks,
-Andrew
Previous Topic:Can I used Uomo from a regular java project?
Next Topic:Which version of UOMo to use with Eclipse Luna
Goto Forum:
  


Current Time: Wed Sep 26 04:31:48 GMT 2018

Powered by FUDForum. Page generated in 0.01590 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top