keilw on master
# WARNING: head commit changed … (compare)
keilw on master
210: preserve ProductUnit dimen… Merge pull request #211 from an… (compare)
Hello everyone, I'd like to derive a new unit representation based on an existing one. However, it does not seem to work as expected. Could you please have a look at the following code snippet and guide me to the right directions? Thanks.
Unit<Energy> WATTHOUR = new TransformedUnit<Energy>("Wh", Units.JOULE, new RationalConverter(3600, 1));
ComparableQuantity<Power> power = Quantities.getQuantity(1000, MetricPrefix.MILLI(Units.WATT));
ComparableQuantity<Time> time = Quantities.getQuantity(15, Units.MINUTE);
ComparableQuantity<Energy> energy = power.multiply(time).asType(Energy.class);
System.out.println(energy); //Ouput 15000.00 J/s·min -> correct
System.out.println(energy.to(Units.JOULE)); //Output 900.00 J -> correct
System.out.println(energy.to(WATTHOUR)); //Output 0.25 m·N -> Expected: 0.25 Wh
System.out.println(energy.to(MetricPrefix.KILO(Units.JOULE))); //Output 0.90 m·N -> Wrong, expected something like 0.90 kJ or 0.90 kNm
System.out.println(energy.to(MetricPrefix.KILO(WATTHOUR))); //Output 0.00025 m·N -> Wrong, expected 0.00025 kWh
Quantities.getQuantity()will not work at scala, because
Intin scala extends
AnyVal, and does not implement `java.lang.Number'
DoubleQuantityclass is inaccessible
DoubleQuantityis private in module settings?
Quantity<Pressure>. If you're using UoM for the first time I would start out trying it in Java or Kotlin first where it is all idiomatic and tested before trying it in Scala. The JSR 363 spec describes it pretty well in detail, not sure if there is one for JSR 385 yet. Here is the JSR 363 one http://download.oracle.com/otndocs/jcp/units-1_0-final-eval-spec/