From a49c27529996e53ac851e340a6e0532ebd92c469 Mon Sep 17 00:00:00 2001 From: Simon Schneider <10846939+raynigon@users.noreply.github.com> Date: Sun, 13 Sep 2020 17:03:30 +0200 Subject: [PATCH] Implement more custom Units --- .../core/service/UnitResolverService.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/unit-api-core/src/main/java/com/raynigon/unit_api/core/service/UnitResolverService.java b/unit-api-core/src/main/java/com/raynigon/unit_api/core/service/UnitResolverService.java index d390cc42..004fcee3 100644 --- a/unit-api-core/src/main/java/com/raynigon/unit_api/core/service/UnitResolverService.java +++ b/unit-api-core/src/main/java/com/raynigon/unit_api/core/service/UnitResolverService.java @@ -2,12 +2,15 @@ import tech.units.indriya.AbstractSystemOfUnits; import tech.units.indriya.function.AbstractConverter; +import tech.units.indriya.function.MultiplyConverter; +import tech.units.indriya.function.RationalConverter; import tech.units.indriya.unit.TransformedUnit; import tech.units.indriya.unit.Units; import javax.measure.MetricPrefix; import javax.measure.Quantity; import javax.measure.Unit; +import javax.measure.quantity.ElectricCharge; import javax.measure.quantity.Energy; import java.util.ArrayList; import java.util.Map; @@ -27,6 +30,7 @@ public UnitResolverService() { createScaledUnits("m", "k", "c", "m"); createScaledUnits("Wh", "k", "m"); + createScaledUnits("s", "m", "\u00b5", "n"); } public > void addUnit(U unit) { @@ -64,6 +68,20 @@ private void createCustomUnits() { (Unit) Units.WATT.multiply(Units.HOUR), AbstractConverter.IDENTITY); addUnit(wattHour); + + Unit ampereSecond = new TransformedUnit( + "As", + "Ampere-second", + Units.COULOMB, + AbstractConverter.IDENTITY); + addUnit(ampereSecond); + + Unit ampereHour = new TransformedUnit( + "Ah", + "Ampere-hour", + (Unit) Units.COULOMB.multiply(Units.HOUR), + AbstractConverter.IDENTITY); + addUnit(ampereHour); } private void replaceDefaultUnits() {