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 Double
, Float
and Int
in scala extends AnyVal
, and does not implement `java.lang.Number'
DoubleQuantity
class is inaccessible
DoubleQuantity
is private in module settings?
Quantity<Temperature>
or 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/
keilw on master
197: Incorrect multiplication a… (compare)
keilw on master
198: FloatQuantity.decimalValue… (compare)
keilw on master
308: Factor isEquivalentTo from… (compare)