diff --git a/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/library/unit/CustomUnits.java b/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/library/unit/CustomUnits.java new file mode 100644 index 000000000..21349cd4a --- /dev/null +++ b/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/library/unit/CustomUnits.java @@ -0,0 +1,29 @@ +/** + * Copyright (c) 2014,2019 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.core.library.unit; + +import tec.uom.se.AbstractSystemOfUnits; + +/** + * Base class for all custom unit classes added in openHAB. + * + * @author Hilbrand Bouwkamp - initial contribution + */ +class CustomUnits extends AbstractSystemOfUnits { + + @Override + public String getName() { + return getClass().getSimpleName(); + } + +} 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 d59acb4ce..87e445d7e 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 @@ -23,7 +23,6 @@ import javax.measure.spi.SystemOfUnits; import org.eclipse.jdt.annotation.NonNullByDefault; -import tec.uom.se.AbstractSystemOfUnits; import tec.uom.se.format.SimpleUnitFormat; import tec.uom.se.function.AddConverter; import tec.uom.se.function.MultiplyConverter; @@ -39,7 +38,7 @@ import tec.uom.se.unit.Units; * */ @NonNullByDefault -public final class ImperialUnits extends AbstractSystemOfUnits { +public final class ImperialUnits extends CustomUnits { private static final ImperialUnits INSTANCE = new ImperialUnits(); @@ -99,11 +98,6 @@ public final class ImperialUnits extends AbstractSystemOfUnits { // avoid external instantiation } - @Override - public String getName() { - return ImperialUnits.class.getSimpleName(); - } - /** * Returns the unique instance of this class. * 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 3dbfdd20a..9eb7eba75 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 @@ -24,7 +24,6 @@ import javax.measure.spi.SystemOfUnits; import org.eclipse.jdt.annotation.NonNullByDefault; -import tec.uom.se.AbstractSystemOfUnits; import tec.uom.se.format.SimpleUnitFormat; import tec.uom.se.unit.Units; @@ -36,7 +35,7 @@ import tec.uom.se.unit.Units; * */ @NonNullByDefault -public final class SIUnits extends AbstractSystemOfUnits { +public final class SIUnits extends CustomUnits { private static final SIUnits INSTANCE = new SIUnits(); @@ -49,13 +48,13 @@ public final class SIUnits extends AbstractSystemOfUnits { public static final Unit CUBIC_METRE = addUnit(Units.CUBIC_METRE); public static final Unit PASCAL = addUnit(Units.PASCAL); - private SIUnits() { - // avoid external instantiation + static { + // Override the default unit symbol ℃ to better support TTS and UIs: + SimpleUnitFormat.getInstance().label(CELSIUS, "°C"); } - @Override - public String getName() { - return this.getClass().getSimpleName(); + private SIUnits() { + // avoid external instantiation } /** @@ -77,9 +76,4 @@ public final class SIUnits extends AbstractSystemOfUnits { INSTANCE.units.add(unit); return unit; } - - static { - // Override the default unit symbol ℃ to better support TTS and UIs: - SimpleUnitFormat.getInstance().label(CELSIUS, "°C"); - } } 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 159c8dea2..4e7677eb3 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 @@ -53,7 +53,6 @@ import org.eclipse.smarthome.core.library.dimension.Density; import org.eclipse.smarthome.core.library.dimension.Intensity; import org.eclipse.smarthome.core.library.dimension.VolumetricFlowRate; -import tec.uom.se.AbstractSystemOfUnits; import tec.uom.se.AbstractUnit; import tec.uom.se.format.SimpleUnitFormat; import tec.uom.se.function.ExpConverter; @@ -75,7 +74,7 @@ import tec.uom.se.unit.Units; * */ @NonNullByDefault -public final class SmartHomeUnits extends AbstractSystemOfUnits { +public final class SmartHomeUnits extends CustomUnits { private static final SmartHomeUnits INSTANCE = new SmartHomeUnits(); @@ -198,11 +197,6 @@ public final class SmartHomeUnits extends AbstractSystemOfUnits { // avoid external instantiation } - @Override - public String getName() { - return SmartHomeUnits.class.getSimpleName(); - } - /** * Returns the unique instance of this class. *