Conversion of composite units

9 views
Skip to first unread message

fuffact

unread,
Feb 13, 2024, 2:58:02 AM2/13/24
to Units Users
Hi All,

I am new to the Java Units API, would like to understand if it can fit my use case.

I am using units-in-java for years, built also a powerful converter with it. Units-in-java is port of GNU Units, which I find an amazing software. Unfortunately units-in-java seems  unmaintained/abandoned, so I am searching a replacement for it.

The Java Units API looks well structured and solid, I would love to use it, but inspecting the sample code I find it quite hard to implement the conversion of "composite" units. While it is relatively easy to convert simple units like mass, volume, converting composite units like "kg/h" or "Pa * s" seems to require a non negligible amount of work. With GNU Units type of approach, it is one line of code.

My question is how should I handle the conversion of composite units?

Sorry if the agument is too broad, I need just a general answer to orient myself.

Regards
Carlo

Werner Keil

unread,
Feb 7, 2025, 3:13:16 PMFeb 7
to Units Users
Hi,

Thanks for starting this conversation. Sorry it took almost a year to reply.
units-in-java seems pretty dead, because the page was last updated, when we started JSR 363 over 10 years ago.
The page of GNU Units was updated last year, but I don't think the library itself was recently.

In the Java Units API (JSR 385 now as of version 2) there are two types of "composite" units in both implementations:
  • Indriya (the Reference Implementation)
  • Seshat (a less extensible, but somewhat more lightweight implementation)
You cannot mix the implementations, but you should be able to exchange them, as long as your code only uses the API.

Not sure, if you really mean "kg/h" (kilogram per hour) or "km/h" (kilometre per hour), but both works the same way with our API.
Either 
KILO(METRE).divide(HOUR)
Or
KILOGRAM.divide(HOUR)

Same for 
PASCAL.KILOGRAM.divide(HOUR)

There are various demos how to use the API and also a uom-guide. Especially the latter could use some help.
You are welcome to contribute to both, if you can.

Regards,
Werner
Reply all
Reply to author
Forward
0 new messages