From 4e72aeeaff87e865d9dc85b2cbc4d40bfab71d97 Mon Sep 17 00:00:00 2001 From: Werner Keil Date: Sun, 29 Sep 2024 16:39:17 +0200 Subject: [PATCH] 424: Scaling / multiplication is unable to apply factors to temperatures Task-Url: https://github.com/unitsofmeasurement/indriya/issues/424 --- .../impl/seshat/TemperatureConverterDemo.java | 28 +++++++++++++++++++ .../demo/java17/TemperatureConverterDemo.java | 27 ++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 console/impl/seshat/src/main/java/tech/uom/demo/impl/seshat/TemperatureConverterDemo.java create mode 100644 console/java17/src/main/java/tech/uom/demo/java17/TemperatureConverterDemo.java diff --git a/console/impl/seshat/src/main/java/tech/uom/demo/impl/seshat/TemperatureConverterDemo.java b/console/impl/seshat/src/main/java/tech/uom/demo/impl/seshat/TemperatureConverterDemo.java new file mode 100644 index 00000000..b9a0bb12 --- /dev/null +++ b/console/impl/seshat/src/main/java/tech/uom/demo/impl/seshat/TemperatureConverterDemo.java @@ -0,0 +1,28 @@ +package tech.uom.demo.impl.seshat; + +import javax.measure.IncommensurableException; +import javax.measure.UnconvertibleException; +import javax.measure.UnitConverter; + +import tech.uom.seshat.UnitServices; + +public class TemperatureConverterDemo { + + public static void main(String[] args) { + var format = UnitServices.current().getFormatService().getUnitFormat(); + + var source = format.parse("°C/10"); + var dest = format.parse("°C"); + UnitConverter converter = null; + try { + converter = source.getConverterToAny(dest); + } catch (UnconvertibleException | IncommensurableException e) { + e.printStackTrace(); + } + if (converter != null) { + var converted = converter.convert(10); + System.out.println(converted); + } + } + +} diff --git a/console/java17/src/main/java/tech/uom/demo/java17/TemperatureConverterDemo.java b/console/java17/src/main/java/tech/uom/demo/java17/TemperatureConverterDemo.java new file mode 100644 index 00000000..0e1ebc54 --- /dev/null +++ b/console/java17/src/main/java/tech/uom/demo/java17/TemperatureConverterDemo.java @@ -0,0 +1,27 @@ +package tech.uom.demo.java17; + +import javax.measure.IncommensurableException; +import javax.measure.UnconvertibleException; +import javax.measure.UnitConverter; +import javax.measure.spi.ServiceProvider; + +public class TemperatureConverterDemo { + + public static void main(String[] args) { + var format = ServiceProvider.current().getFormatService().getUnitFormat(); + + var source = format.parse("°C/10"); + var dest = format.parse("°C"); + UnitConverter converter = null; + try { + converter = source.getConverterToAny(dest); + } catch (UnconvertibleException | IncommensurableException e) { + e.printStackTrace(); + } + if (converter != null) { + var converted = converter.convert(10); + System.out.println(converted); + } + } + +}