From 8c4fb060ed9686e22e34336e2be554709ec53304 Mon Sep 17 00:00:00 2001 From: Christoph Weitkamp Date: Wed, 13 Nov 2019 18:35:17 +0100 Subject: [PATCH] Minor clean-ups in 'SmartHomeUnits', 'SIUnits' and 'ImperialUnits' (#1208) * Minor clean-us in SmartHomeUnits * Clean-up in 'SIUnits' and 'ImperialUnits' Signed-off-by: Christoph Weitkamp --- .../core/library/unit/ImperialUnits.java | 29 +++++-------- .../smarthome/core/library/unit/SIUnits.java | 2 +- .../core/library/unit/SmartHomeUnits.java | 42 +++++++++---------- 3 files changed, 33 insertions(+), 40 deletions(-) diff --git a/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/library/unit/ImperialUnits.java b/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/library/unit/ImperialUnits.java index e62dce631..f11f3eceb 100644 --- a/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/library/unit/ImperialUnits.java +++ b/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/library/unit/ImperialUnits.java @@ -41,38 +41,32 @@ public final class ImperialUnits extends CustomUnits { private static final ImperialUnits INSTANCE = new ImperialUnits(); - /** Additionally defined units to be used in ESH **/ - + /** Additionally defined units to be used in openHAB **/ public static final Unit INCH_OF_MERCURY = addUnit(new TransformedUnit<>("inHg", Units.PASCAL, new RationalConverter(BigInteger.valueOf(3386388), BigInteger.valueOf(1000)))); public static final Unit FAHRENHEIT = addUnit(new TransformedUnit<>("°F", Units.KELVIN, new RationalConverter(BigInteger.valueOf(5), BigInteger.valueOf(9)).concatenate(new AddConverter(459.67)))); - public static final Unit MILES_PER_HOUR = addUnit( - new TransformedUnit<>("mph", Units.KILOMETRE_PER_HOUR, new RationalConverter(1609344l, 1000000l))); + public static final Unit MILES_PER_HOUR = addUnit(new TransformedUnit<>("mph", Units.KILOMETRE_PER_HOUR, + new RationalConverter(BigInteger.valueOf(1609344), BigInteger.valueOf(1000000)))); /** Length **/ - public static final Unit INCH = addUnit( - new TransformedUnit<>("in", Units.METRE, new RationalConverter(254l, 10000l))); + public static final Unit INCH = addUnit(new TransformedUnit<>("in", Units.METRE, + new RationalConverter(BigInteger.valueOf(254), BigInteger.valueOf(10000)))); - public static final Unit FOOT = addUnit( - new TransformedUnit<>("ft", ImperialUnits.INCH, new MultiplyConverter(12.0))); + public static final Unit FOOT = addUnit(new TransformedUnit<>("ft", INCH, new MultiplyConverter(12.0))); - public static final Unit YARD = addUnit( - new TransformedUnit<>("yd", ImperialUnits.FOOT, new MultiplyConverter(3.0))); + public static final Unit YARD = addUnit(new TransformedUnit<>("yd", FOOT, new MultiplyConverter(3.0))); - public static final Unit CHAIN = addUnit( - new TransformedUnit<>("ch", ImperialUnits.YARD, new MultiplyConverter(22.0))); + public static final Unit CHAIN = addUnit(new TransformedUnit<>("ch", YARD, new MultiplyConverter(22.0))); public static final Unit FURLONG = addUnit( - new TransformedUnit<>("fur", ImperialUnits.CHAIN, new MultiplyConverter(10.0))); + new TransformedUnit<>("fur", CHAIN, new MultiplyConverter(10.0))); - public static final Unit MILE = addUnit( - new TransformedUnit<>("mi", ImperialUnits.FURLONG, new MultiplyConverter(8.0))); + public static final Unit MILE = addUnit(new TransformedUnit<>("mi", FURLONG, new MultiplyConverter(8.0))); - public static final Unit LEAGUE = addUnit( - new TransformedUnit<>("lea", ImperialUnits.MILE, new MultiplyConverter(3.0))); + public static final Unit LEAGUE = addUnit(new TransformedUnit<>("lea", MILE, new MultiplyConverter(3.0))); public static final Unit SQUARE_FOOT = addUnit(new ProductUnit<>(FOOT.multiply(FOOT))); public static final Unit CUBIC_FOOT = addUnit(new ProductUnit<>(SQUARE_FOOT.multiply(FOOT))); @@ -116,5 +110,4 @@ public final class ImperialUnits extends CustomUnits { INSTANCE.units.add(unit); return unit; } - } diff --git a/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/library/unit/SIUnits.java b/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/library/unit/SIUnits.java index b0fcff71f..c4cb989cc 100644 --- a/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/library/unit/SIUnits.java +++ b/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/library/unit/SIUnits.java @@ -28,7 +28,7 @@ import tec.uom.se.format.SimpleUnitFormat; import tec.uom.se.unit.Units; /** - * Delegate SI units to {@link Units} to hide this dependency from the rest of ESH. + * Delegate SI units to {@link Units} to hide this dependency from the rest of openHAB. * See members of {@link Units} for a detailed description. * * @author Henning Treu - Initial contribution diff --git a/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/library/unit/SmartHomeUnits.java b/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/library/unit/SmartHomeUnits.java index befca6674..6e7071ad7 100644 --- a/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/library/unit/SmartHomeUnits.java +++ b/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/library/unit/SmartHomeUnits.java @@ -83,14 +83,14 @@ public final class SmartHomeUnits extends CustomUnits { // Alphabetical ordered by Unit. public static final Unit METRE_PER_SQUARE_SECOND = addUnit(Units.METRE_PER_SQUARE_SECOND); - public static final Unit STANDARD_GRAVITY = addUnit( - SmartHomeUnits.METRE_PER_SQUARE_SECOND.multiply((9.80665))); + public static final Unit STANDARD_GRAVITY = addUnit(METRE_PER_SQUARE_SECOND.multiply(9.80665)); public static final Unit MOLE = addUnit(Units.MOLE); - public static final Unit DEUTSCHE_HAERTE = addUnit(new TransformedUnit("°dH", - (Unit) MetricPrefix.MILLI(Units.MOLE).divide(Units.LITRE), - RationalConverter.of(5.6, 1))); + @SuppressWarnings("unchecked") + public static final Unit DEUTSCHE_HAERTE = addUnit( + new TransformedUnit<>("°dH", (Unit) MetricPrefix.MILLI(Units.MOLE).divide(Units.LITRE), + RationalConverter.of(5.6, 1))); public static final Unit DEGREE_ANGLE = addUnit(new TransformedUnit<>(Units.RADIAN, - new PiMultiplierConverter().concatenate(new RationalConverter(1, 180)))); + new PiMultiplierConverter().concatenate(new RationalConverter(BigInteger.ONE, BigInteger.valueOf(180))))); public static final Unit RADIAN = addUnit(Units.RADIAN); public static final Unit DOBSON_UNIT = addUnit( new ProductUnit(MetricPrefix.MILLI(Units.MOLE).multiply(0.4462).divide(Units.METRE.pow(2)))); @@ -98,13 +98,13 @@ public final class SmartHomeUnits extends CustomUnits { public static final Unit KILOGRAM_PER_CUBICMETRE = addUnit( new ProductUnit(Units.KILOGRAM.divide(Units.METRE.pow(3)))); public static final Unit MICROGRAM_PER_CUBICMETRE = addUnit(new TransformedUnit<>(KILOGRAM_PER_CUBICMETRE, - new RationalConverter(BigInteger.valueOf(1), BigInteger.valueOf(1000000000)))); + new RationalConverter(BigInteger.ONE, BigInteger.valueOf(1000000000)))); public static final Unit ONE = addUnit(AbstractUnit.ONE); public static final Unit PERCENT = addUnit(Units.PERCENT); public static final Unit PARTS_PER_MILLION = addUnit( - new TransformedUnit<>(ONE, new RationalConverter(1, 1000000))); - public static final Unit DECIBEL = addUnit( - ONE.transform(new LogConverter(10).inverse().concatenate(RationalConverter.of(1d, 10d)))); + new TransformedUnit<>(ONE, new RationalConverter(BigInteger.ONE, BigInteger.valueOf(1000000)))); + public static final Unit DECIBEL = addUnit(ONE.transform( + new LogConverter(10).inverse().concatenate(new RationalConverter(BigInteger.ONE, BigInteger.TEN)))); public static final Unit AMPERE = addUnit(Units.AMPERE); public static final Unit FARAD = addUnit(Units.FARAD); public static final Unit COULOMB = addUnit(Units.COULOMB); @@ -113,8 +113,8 @@ public final class SmartHomeUnits extends CustomUnits { public static final Unit VOLT = addUnit(Units.VOLT); public static final Unit OHM = addUnit(Units.OHM); public static final Unit JOULE = addUnit(Units.JOULE); - public static final Unit WATT_SECOND = addUnit(new ProductUnit(Units.WATT.multiply(Units.SECOND))); - public static final Unit WATT_HOUR = addUnit(new ProductUnit(Units.WATT.multiply(Units.HOUR))); + public static final Unit WATT_SECOND = addUnit(new ProductUnit<>(Units.WATT.multiply(Units.SECOND))); + public static final Unit WATT_HOUR = addUnit(new ProductUnit<>(Units.WATT.multiply(Units.HOUR))); public static final Unit KILOWATT_HOUR = addUnit(MetricPrefix.KILO(WATT_HOUR)); public static final Unit MEGAWATT_HOUR = addUnit(MetricPrefix.MEGA(WATT_HOUR)); public static final Unit KILOVAR = addUnit(MetricPrefix.KILO(new BaseUnit("var"))); @@ -125,27 +125,27 @@ public final class SmartHomeUnits extends CustomUnits { public static final Unit IRRADIANCE = addUnit( new AlternateUnit(Units.WATT.divide(Units.SQUARE_METRE), "W/m2")); public static final Unit MICROWATT_PER_SQUARE_CENTIMETRE = addUnit( - new TransformedUnit<>(IRRADIANCE, new RationalConverter(BigInteger.valueOf(100), BigInteger.valueOf(1)))); + new TransformedUnit<>(IRRADIANCE, new RationalConverter(BigInteger.valueOf(100), BigInteger.ONE))); public static final Unit LUX = addUnit(Units.LUX); public static final Unit LUMEN = addUnit(Units.LUMEN); public static final Unit CANDELA = addUnit(Units.CANDELA); public static final Unit WEBER = addUnit(Units.WEBER); public static final Unit TESLA = addUnit(Units.TESLA); public static final Unit WATT = addUnit(Units.WATT); - public static final Unit DECIBEL_MILLIWATTS = new TransformedUnit<>("dBm", - MetricPrefix.MILLI(SmartHomeUnits.WATT), new ExpConverter(10.0).concatenate(new MultiplyConverter(0.1))); + public static final Unit DECIBEL_MILLIWATTS = new TransformedUnit<>("dBm", MetricPrefix.MILLI(WATT), + new ExpConverter(10.0).concatenate(new MultiplyConverter(0.1))); public static final Unit MILLIMETRE_OF_MERCURY = addUnit(new TransformedUnit<>("mmHg", Units.PASCAL, new RationalConverter(BigInteger.valueOf(133322368), BigInteger.valueOf(1000000)))); public static final Unit BAR = addUnit(new TransformedUnit<>("bar", Units.PASCAL, - new RationalConverter(BigInteger.valueOf(100000), BigInteger.valueOf(1)))); + new RationalConverter(BigInteger.valueOf(100000), BigInteger.ONE))); public static final Unit MILLIBAR = addUnit(MetricPrefix.MILLI(BAR)); public static final Unit BECQUEREL = addUnit(Units.BECQUEREL); public static final Unit GRAY = addUnit(Units.GRAY); public static final Unit SIEVERT = addUnit(Units.SIEVERT); - public static final Unit MILLIMETRE_PER_HOUR = addUnit( - new TransformedUnit<>("mm/h", Units.KILOMETRE_PER_HOUR, new RationalConverter(1l, 1000000l))); - public static final Unit INCHES_PER_HOUR = addUnit( - new TransformedUnit<>("in/h", ImperialUnits.MILES_PER_HOUR, new RationalConverter(1l, 63360l))); + public static final Unit MILLIMETRE_PER_HOUR = addUnit(new TransformedUnit<>("mm/h", + Units.KILOMETRE_PER_HOUR, new RationalConverter(BigInteger.ONE, BigInteger.valueOf(1000000)))); + public static final Unit INCHES_PER_HOUR = addUnit(new TransformedUnit<>("in/h", + ImperialUnits.MILES_PER_HOUR, new RationalConverter(BigInteger.ONE, BigInteger.valueOf(63360)))); public static final Unit METRE_PER_SECOND = addUnit(Units.METRE_PER_SECOND); public static final Unit KNOT = addUnit(new TransformedUnit<>("kn", Units.KILOMETRE_PER_HOUR, new RationalConverter(BigInteger.valueOf(1852), BigInteger.valueOf(1000)))); @@ -168,7 +168,7 @@ public final class SmartHomeUnits extends CustomUnits { new ProductUnit(Units.CUBIC_METRE.divide(Units.HOUR))); public static final Unit CUBICMETRE_PER_DAY = addUnit( new ProductUnit(Units.CUBIC_METRE.divide(Units.DAY))); - public static final Unit BIT = addUnit(new AlternateUnit(ONE, "bit")); + public static final Unit BIT = addUnit(new AlternateUnit<>(ONE, "bit")); public static final Unit MEGABIT = addUnit(MetricPrefix.MEGA(BIT)); public static final Unit KILOBIT = addUnit(MetricPrefix.KILO(BIT)); public static final Unit GIGABIT = addUnit(MetricPrefix.GIGA(BIT));