diff --git a/console/java17/src/main/java/tech/uom/demo/java17/format/TemperatureQuantityConverterDemo.java b/console/java17/src/main/java/tech/uom/demo/java17/format/TemperatureQuantityConverterDemo.java index d93ff7d8..895248a9 100644 --- a/console/java17/src/main/java/tech/uom/demo/java17/format/TemperatureQuantityConverterDemo.java +++ b/console/java17/src/main/java/tech/uom/demo/java17/format/TemperatureQuantityConverterDemo.java @@ -1,28 +1,42 @@ package tech.uom.demo.java17.format; -import static javax.measure.Quantity.Scale.ABSOLUTE; +import static javax.measure.Quantity.Scale.*; import static tech.units.indriya.unit.Units.CELSIUS; +import java.text.NumberFormat; + import javax.measure.Quantity; import javax.measure.Unit; import javax.measure.quantity.Temperature; -import tech.units.indriya.quantity.Quantities; -import tech.units.indriya.format.EBNFUnitFormat; +import tech.units.indriya.format.NumberDelimiterQuantityFormat; import tech.units.indriya.format.SimpleUnitFormat; +import tech.units.indriya.quantity.Quantities; public class TemperatureQuantityConverterDemo { public static void main(String[] args) { //Unit cByTen = CELSIUS.divide(10); - //var format = EBNFUnitFormat.getInstance(); var format = SimpleUnitFormat.getInstance(); Unit cByTen = format.parse("°C/10").asType(Temperature.class); Quantity absT = Quantities.getQuantity(0d, CELSIUS, ABSOLUTE); Quantity absT2 = Quantities.getQuantity(0d, CELSIUS, ABSOLUTE); - Quantity absT3 = Quantities.getQuantity(0d, cByTen, ABSOLUTE); - Quantity sum = absT.add(absT2); - System.out.println(sum); - System.out.println(absT3); - System.out.println(sum.to(cByTen)); + Quantity relT = Quantities.getQuantity(0d, CELSIUS, RELATIVE); + Quantity relT2 = Quantities.getQuantity(0d, CELSIUS, RELATIVE); + Quantity sumAbs = absT.add(absT2); + Quantity sumRel = relT.add(relT2); + System.out.println(sumAbs); + System.out.println(sumRel); + System.out.printf("Abs: %s%s", sumAbs.to(cByTen), System.lineSeparator()); + System.out.printf("Rel: %s%s", sumRel.to(cByTen), System.lineSeparator()); + + var qformat = NumberDelimiterQuantityFormat.getInstance(NumberFormat.getInstance(), format); + var source = format.parse("K/10"); + var intermediary = format.parse("K"); + + var qs = Quantities.getQuantity(10, source, ABSOLUTE); + System.out.println(qformat.format(qs)); + var qs3 = Quantities.getQuantity(1, intermediary, ABSOLUTE); + var qs4 = qs.multiply(qs3); + System.out.println(qformat.format(qs4)); } } diff --git a/console/java17/src/main/java/tech/uom/demo/java17/format/TemperatureUnitConverterDemo.java b/console/java17/src/main/java/tech/uom/demo/java17/format/TemperatureUnitConverterDemo.java index 0bf0579a..f8054264 100644 --- a/console/java17/src/main/java/tech/uom/demo/java17/format/TemperatureUnitConverterDemo.java +++ b/console/java17/src/main/java/tech/uom/demo/java17/format/TemperatureUnitConverterDemo.java @@ -2,56 +2,36 @@ import static javax.measure.Quantity.Scale.*; -import java.text.NumberFormat; - import javax.measure.IncommensurableException; -import javax.measure.UnconvertibleException; import javax.measure.UnitConverter; -import javax.measure.spi.ServiceProvider; import tech.units.indriya.AbstractUnit; import tech.units.indriya.format.EBNFUnitFormat; -import tech.units.indriya.format.NumberDelimiterQuantityFormat; -import tech.units.indriya.quantity.Quantities; public class TemperatureUnitConverterDemo { public static void main(String[] args) { //var format = ServiceProvider.current().getFormatService().getUnitFormat(); var format = EBNFUnitFormat.getInstance(); - var format2 = NumberDelimiterQuantityFormat.getInstance(NumberFormat.getInstance(), format); var source = format.parse("K/10"); - var intermediary = format.parse("K"); + var dest = format.parse("K"); var source2 = format.parse("°C/10"); - var dest = format.parse("°C"); + var dest2 = format.parse("°C"); UnitConverter converter = null; UnitConverter converter2 = null; - UnitConverter converter3 = null; try { - converter = source.getConverterToAny(intermediary); - converter2 = dest.getConverterToAny(intermediary); - converter3 = ((AbstractUnit)source2).getConverterToAny(dest, RELATIVE); - } catch (UnconvertibleException | IncommensurableException e) { + converter = source.getConverterToAny(dest); + converter2 = ((AbstractUnit)source2).getConverterToAny(dest2, RELATIVE); + } catch (IncommensurableException e) { e.printStackTrace(); } if (converter != null) { - var toK = converter2.convert(1); - var converted = converter.convert(toK); + var converted = converter.convert(10); System.out.println(converted); } - if (converter3 != null) { - var converted = converter3.convert(10); - System.out.println(converted); - } - - var qs = Quantities.getQuantity(10, source, ABSOLUTE); - System.out.println(format2.format(qs)); - //var qs2 = Quantities.getQuantity(10, source2, Scale.ABSOLUTE); - //System.out.println(format2.format(qs2)); - var qs3 = Quantities.getQuantity(1, intermediary, ABSOLUTE); - var qs4 = qs.multiply(qs3); - System.out.println(format2.format(qs4)); - //var qs5 = qs.to(dest); + if (converter2 != null) { + var converted2 = converter2.convert(10); + System.out.println(converted2); + } } - } diff --git a/lang/valhalla/pom.xml b/lang/valhalla/pom.xml index c929c7f4..dc370ed9 100644 --- a/lang/valhalla/pom.xml +++ b/lang/valhalla/pom.xml @@ -11,7 +11,7 @@ valhalla Project Valhalla Demos - 14 + 23 @@ -19,28 +19,32 @@ org.apache.maven.plugins maven-compiler-plugin + + ${java.version} + true org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M3 ${java.bin}/java.exe + --enable-preview org.codehaus.mojo exec-maven-plugin - 1.3.2 + 1.6.0 @@ -49,11 +53,16 @@ - ${java.bin}/java.exe + tech.uom.demo.valhalla.ValhallaDemo + + --enable-preview + --enable-preview + @@ -71,12 +80,10 @@ tech.uom.lib uom-lib-common - ${lib.version} tech.units indriya - ${ri.version} diff --git a/lang/valhalla/src/main/java/tech/uom/demo/valhalla/VUnit.java b/lang/valhalla/src/main/java/tech/uom/demo/valhalla/VUnit.java index d9546e12..9d261902 100644 --- a/lang/valhalla/src/main/java/tech/uom/demo/valhalla/VUnit.java +++ b/lang/valhalla/src/main/java/tech/uom/demo/valhalla/VUnit.java @@ -3,8 +3,7 @@ import javax.measure.*; import java.util.Map; -public inline class VUnit> implements Unit? { - +public value class VUnit> implements Unit { private final String x; private final String y; @@ -44,21 +43,6 @@ public Map, Integer> getBaseUnits() { return null; } - @Override - public boolean isCompatible(Unit that) { - return false; - } - - @Override - public > Unit asType(Class type) throws ClassCastException { - return null; - } - - @Override - public UnitConverter getConverterToAny(Unit that) throws IncommensurableException, UnconvertibleException { - return null; - } - @Override public Unit alternate(String symbol) { return null; @@ -84,11 +68,6 @@ public Unit multiply(double multiplier) { return null; } - @Override - public Unit multiply(Unit multiplier) { - return null; - } - @Override public Unit inverse() { return null; @@ -104,10 +83,6 @@ public Unit divide(double divisor) { return null; } - @Override - public Unit divide(Unit divisor) { - return null; - } @Override public Unit root(int n) { @@ -129,14 +104,51 @@ public Unit prefix(Prefix prefix) { return null; } - @Override - public UnitConverter getConverterTo(Unit that) throws UnconvertibleException { - return null; - } - @Override public String toString() { return "VUnit [symbol=" + x + ", name=" + y + "]"; } + @Override + public boolean isEquivalentTo(Unit that) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isCompatible(Unit that) { + // TODO Auto-generated method stub + return false; + } + + @Override + public Unit asType(Class type) throws ClassCastException { + // TODO Auto-generated method stub + return null; + } + + @Override + public UnitConverter getConverterTo(Unit that) throws UnconvertibleException { + // TODO Auto-generated method stub + return null; + } + + @Override + public UnitConverter getConverterToAny(Unit that) throws IncommensurableException, UnconvertibleException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Unit multiply(Unit multiplier) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Unit divide(Unit divisor) { + // TODO Auto-generated method stub + return null; + } + } diff --git a/lang/valhalla/src/main/java/tech/uom/demo/valhalla/ValhallaDemo.java b/lang/valhalla/src/main/java/tech/uom/demo/valhalla/ValhallaDemo.java index df9b6989..5743c2ab 100644 --- a/lang/valhalla/src/main/java/tech/uom/demo/valhalla/ValhallaDemo.java +++ b/lang/valhalla/src/main/java/tech/uom/demo/valhalla/ValhallaDemo.java @@ -1,13 +1,15 @@ package tech.uom.demo.valhalla; +import javax.measure.quantity.Mass; + public class ValhallaDemo { private static final String PATTERN = "%s and %s are %s."; private static final String SAME = "the same"; private static final String NOT_SAME = "not the same"; public static void main(String[] args) { - VUnit m1 = VUnit.of("kg","kilogram"); - VUnit m2 = VUnit.of("kg","kilogram"); + VUnit m1 = VUnit.of("kg","kilogram"); + VUnit m2 = VUnit.of("kg","kilogram"); System.out.println(m1); if (m1 == m2) { System.out.println(String.format(PATTERN, m1, m2, SAME)); diff --git a/lang/valhalla/src/test/java/tech/uom/demo/valhalla/EqualityTest.java b/lang/valhalla/src/test/java/tech/uom/demo/valhalla/EqualityTest.java index 2a77b10d..eedbe1a4 100644 --- a/lang/valhalla/src/test/java/tech/uom/demo/valhalla/EqualityTest.java +++ b/lang/valhalla/src/test/java/tech/uom/demo/valhalla/EqualityTest.java @@ -1,12 +1,17 @@ package tech.uom.demo.valhalla; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; /* * @test - * @summary Test inline classes for equality + * @summary Test value classes for equality */ public class EqualityTest { diff --git a/lang/valhalla/src/test/java/tech/uom/demo/valhalla/InlineReferenceTest.java b/lang/valhalla/src/test/java/tech/uom/demo/valhalla/InlineReferenceTest.java index 59752b13..bed62004 100644 --- a/lang/valhalla/src/test/java/tech/uom/demo/valhalla/InlineReferenceTest.java +++ b/lang/valhalla/src/test/java/tech/uom/demo/valhalla/InlineReferenceTest.java @@ -1,11 +1,9 @@ package tech.uom.demo.valhalla; -import static org.junit.Assert.*; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; -import org.junit.Test; /* * @test @@ -14,17 +12,17 @@ */ public class InlineReferenceTest { - @Test(expected = IllegalArgumentException.class) - public void test1() { - VUnit? p = VUnit.of("k","kilogram"); - WeakReference r = new WeakReference<>(p); - } - - @Test(expected = IllegalArgumentException.class) - public void test2() { - ReferenceQueue q = new ReferenceQueue<>(); - VUnit? p = VUnit.of("k","kilogram"); - WeakReference r = new WeakReference<>(p, q); - } +// @Test(expected = IllegalArgumentException.class) +// public void test1() { +// VUnit? p = VUnit.of("k","kilogram"); +// WeakReference r = new WeakReference<>(p); +// } +// +// @Test(expected = IllegalArgumentException.class) +// public void test2() { +// ReferenceQueue q = new ReferenceQueue<>(); +// VUnit? p = VUnit.of("k","kilogram"); +// WeakReference r = new WeakReference<>(p, q); +// } } diff --git a/lang/valhalla/src/test/java/tech/uom/demo/valhalla/MethodTest.java b/lang/valhalla/src/test/java/tech/uom/demo/valhalla/MethodTest.java index 4cd63d7e..1bbc842b 100644 --- a/lang/valhalla/src/test/java/tech/uom/demo/valhalla/MethodTest.java +++ b/lang/valhalla/src/test/java/tech/uom/demo/valhalla/MethodTest.java @@ -1,12 +1,15 @@ package tech.uom.demo.valhalla; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; /* * @test - * @summary Test inline classes and its methods + * @summary Test value classes and their methods */ public class MethodTest {