Package org.openhab.core.types.util
Class UnitUtils
java.lang.Object
org.openhab.core.types.util.UnitUtils
A utility for parsing dimensions to interface classes of
Quantity
and parsing units from format strings.- Author:
- Henning Treu - Initial contribution
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable String
getDimensionName
(javax.measure.Unit<?> unit) The name of the dimension as stated in the ChannelType configuration.static boolean
isDifferentMeasurementSystem
(javax.measure.Unit<? extends javax.measure.Quantity<?>> thisUnit, javax.measure.Unit<?> thatUnit) static @Nullable Class
<? extends javax.measure.Quantity<?>> parseDimension
(@Nullable String dimension) Parses a String denoting a dimension (e.g.static @Nullable javax.measure.Unit
<?> A utility method to parse a unit symbol either directly or from a given pattern (like stateDescription or widget label).
-
Field Details
-
UNIT_PLACEHOLDER
- See Also:
-
UNIT_PERCENT_FORMAT_STRING
- See Also:
-
-
Constructor Details
-
UnitUtils
public UnitUtils()
-
-
Method Details
-
parseDimension
public static @Nullable Class<? extends javax.measure.Quantity<?>> parseDimension(@Nullable String dimension) Parses a String denoting a dimension (e.g. Length, Temperature, Mass,..) into aClass
instance of an interface fromQuantity
. The interfaces reside injavax.measure.quantity
and framework specific interfaces inorg.openhab.core.library.dimension
.- Parameters:
dimension
- the simple name of an interface from the packagejavax.measure.quantity
ororg.openhab.core.library.dimension
.- Returns:
- the
Class
instance of the interface ornull
if the given dimension is blank. - Throws:
IllegalArgumentException
- in case no class instance could be parsed from the given dimension.
-
getDimensionName
The name of the dimension as stated in the ChannelType configuration. e.g.Unit: 'm' -> "Length"
Unit: 'kWh' -> "Energy"
If the
Unit
can not be found in any of the available Measurement systems, it returnsnull
- Parameters:
unit
- TheUnit
to get the Dimension's name from.- Returns:
- The Dimension string or null if the unit can not be found in any of the SystemOfUnits.
-
parseUnit
A utility method to parse a unit symbol either directly or from a given pattern (like stateDescription or widget label). In the latter case, the unit is expected to be the last part of the pattern separated by " " (e.g. "%.2f °C" for °C).- Parameters:
pattern
- the string to extract the unit symbol from- Returns:
- the unit symbol extracted from the string or
null
if no unit could be parsed
-
isDifferentMeasurementSystem
public static boolean isDifferentMeasurementSystem(javax.measure.Unit<? extends javax.measure.Quantity<?>> thisUnit, javax.measure.Unit<?> thatUnit)
-