Skip to content

Commit

Permalink
Implement more custom Units
Browse files Browse the repository at this point in the history
  • Loading branch information
raynigon committed Sep 13, 2020
1 parent bd8ba2a commit a49c275
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +30,7 @@ public UnitResolverService() {

createScaledUnits("m", "k", "c", "m");
createScaledUnits("Wh", "k", "m");
createScaledUnits("s", "m", "\u00b5", "n");
}

public <U extends Unit<?>> void addUnit(U unit) {
Expand Down Expand Up @@ -64,6 +68,20 @@ private void createCustomUnits() {
(Unit<Energy>) Units.WATT.multiply(Units.HOUR),
AbstractConverter.IDENTITY);
addUnit(wattHour);

Unit<ElectricCharge> ampereSecond = new TransformedUnit<ElectricCharge>(
"As",
"Ampere-second",
Units.COULOMB,
AbstractConverter.IDENTITY);
addUnit(ampereSecond);

Unit<ElectricCharge> ampereHour = new TransformedUnit<ElectricCharge>(
"Ah",
"Ampere-hour",
(Unit<ElectricCharge>) Units.COULOMB.multiply(Units.HOUR),
AbstractConverter.IDENTITY);
addUnit(ampereHour);
}

private void replaceDefaultUnits() {
Expand Down

0 comments on commit a49c275

Please sign in to comment.