Skip to main content

[jsr363-experts] Unit commensurability (again) - please I would like answers

  • From: Martin Desruisseaux < >
  • To: " " < >
  • Subject: [jsr363-experts] Unit commensurability (again) - please I would like answers
  • Date: Wed, 17 Dec 2014 13:59:59 +0900
  • Organization: Geomatys

The specification said:

    Two units /u1/ and /u2/ are compatible if and only if
    u1.getDimension().equals(u2.getDimension()).

*First question:**
*What is the expected result of the following code? Shall c be the
identity converter or shall the code throw an IncommensurableException?
If I interpret the specification literally, we would get an identity
converter (no exception thrown). Is it what we want?

    Unit<Energy> energy = SI.JOULE;
    Unit<Torque> torque = SI.NEWTON.multiply(SI.METRE).asType(Torque.class);
    UnitConverter c = energy.getConverterToAny(torque);

*Second question:**
*What is the expected result of the following code? Should the operation
succeed or throw a ClassCastException?

    Quantity<Energy> energy = factory.create(1, SI.JOULE);
    Quantity<Torque> torque = energy.asType(Torque.class);

My opinion is that above Quantity.asType(class) should throw an
exception even if the units are commensurable. Do we agree on that?

Martin



[jsr363-experts] Unit commensurability (again) - please I would like answers

Martin Desruisseaux 12/17/2014

[jsr363-experts] Re: Unit commensurability (again) - please I would like answers

Werner Keil 12/17/2014
 
 
Close
loading
Please Confirm
Close