Skip to content

Commit

Permalink
Added new parent class for units to fix import problems. (#618)
Browse files Browse the repository at this point in the history
The change with unit classes parent (#617) causes it to report missing imports of tec.uom.se when using static import. Before the change this was not a problem because the parent class was SmartHomeUnits. This change adds a new parent class for all units.

Signed-off-by: Hilbrand Bouwkamp <[email protected]>
  • Loading branch information
Hilbrand authored and wborn committed Mar 2, 2019
1 parent 4517f39 commit caa9b71
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

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;
Expand All @@ -39,7 +38,7 @@
*
*/
@NonNullByDefault
public final class ImperialUnits extends AbstractSystemOfUnits {
public final class ImperialUnits extends CustomUnits {

private static final ImperialUnits INSTANCE = new ImperialUnits();

Expand Down Expand Up @@ -99,11 +98,6 @@ private ImperialUnits() {
// avoid external instantiation
}

@Override
public String getName() {
return ImperialUnits.class.getSimpleName();
}

/**
* Returns the unique instance of this class.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import org.eclipse.jdt.annotation.NonNullByDefault;

import tec.uom.se.AbstractSystemOfUnits;
import tec.uom.se.format.SimpleUnitFormat;
import tec.uom.se.unit.Units;

Expand All @@ -36,7 +35,7 @@
*
*/
@NonNullByDefault
public final class SIUnits extends AbstractSystemOfUnits {
public final class SIUnits extends CustomUnits {

private static final SIUnits INSTANCE = new SIUnits();

Expand All @@ -49,13 +48,13 @@ public final class SIUnits extends AbstractSystemOfUnits {
public static final Unit<Volume> CUBIC_METRE = addUnit(Units.CUBIC_METRE);
public static final Unit<Pressure> 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
}

/**
Expand All @@ -77,9 +76,4 @@ private static <U extends Unit<?>> U addUnit(U unit) {
INSTANCE.units.add(unit);
return unit;
}

static {
// Override the default unit symbol ℃ to better support TTS and UIs:
SimpleUnitFormat.getInstance().label(CELSIUS, "°C");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
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;
Expand All @@ -75,7 +74,7 @@
*
*/
@NonNullByDefault
public final class SmartHomeUnits extends AbstractSystemOfUnits {
public final class SmartHomeUnits extends CustomUnits {

private static final SmartHomeUnits INSTANCE = new SmartHomeUnits();

Expand Down Expand Up @@ -198,11 +197,6 @@ private SmartHomeUnits() {
// avoid external instantiation
}

@Override
public String getName() {
return SmartHomeUnits.class.getSimpleName();
}

/**
* Returns the unique instance of this class.
*
Expand Down

0 comments on commit caa9b71

Please sign in to comment.