test_class.file: bundles/org.openhab.core/src/test/java/org/openhab/core/types/util/UnitUtilsTest.java
test_class.identifier: UnitUtilsTest
test_case.body: @Test
      public void shouldParseUnitFromPattern() {
          assertThat(UnitUtils.parseUnit("%.2f °F"), is(ImperialUnits.FAHRENHEIT));
          assertThat(UnitUtils.parseUnit("%.2f °C"), is(SIUnits.CELSIUS));
          assertThat(UnitUtils.parseUnit("myLabel km"), is(KILO(SIUnits.METRE)));
          assertThat(UnitUtils.parseUnit("%.2f %%"), is(SmartHomeUnits.PERCENT));
          assertThat(UnitUtils.parseUnit("myLabel %unit%"), is(nullValue()));
          assertThat(UnitUtils.parseUnit("%.2f kvarh"), is(SmartHomeUnits.KILOVAR_HOUR));
      }
test_case.class_method_signature: UnitUtilsTest.shouldParseUnitFromPattern()
test_case.full_signature: @Test public void shouldParseUnitFromPattern()
test_case.identifier: shouldParseUnitFromPattern
test_case.invocations: assertThat parseUnit s( assertThat parseUnit s( assertThat parseUnit is KILO assertThat parseUnit is assertThat parseUnit is nullValue assertThat parseUnit is
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void shouldParseUnitFromPattern()
focal_class.declarator: LOGGER = LoggerFactory.getLogger(UnitUtils.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOGGER = LoggerFactory.getLogger(UnitUtils.class);
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.declarator: UNIT_PLACEHOLDER = "%unit%"
focal_class.modifier: public static final
focal_class.original_string: public static final String UNIT_PLACEHOLDER = "%unit%";
focal_class.type: String
focal_class.var_name: UNIT_PLACEHOLDER
focal_class.declarator: UNIT_PERCENT_FORMAT_STRING = "%%"
focal_class.modifier: public static final
focal_class.original_string: public static final String UNIT_PERCENT_FORMAT_STRING = "%%";
focal_class.type: String
focal_class.var_name: UNIT_PERCENT_FORMAT_STRING
focal_class.declarator: JAVAX_MEASURE_QUANTITY_PREFIX = "javax.measure.quantity."
focal_class.modifier: private static final
focal_class.original_string: private static final String JAVAX_MEASURE_QUANTITY_PREFIX = "javax.measure.quantity.";
focal_class.type: String
focal_class.var_name: JAVAX_MEASURE_QUANTITY_PREFIX
focal_class.declarator: FRAMEWORK_DIMENSION_PREFIX = "org.openhab.core.library.dimension."
focal_class.modifier: private static final
focal_class.original_string: private static final String FRAMEWORK_DIMENSION_PREFIX = "org.openhab.core.library.dimension.";
focal_class.type: String
focal_class.var_name: FRAMEWORK_DIMENSION_PREFIX
focal_class.declarator: ALL_SYSTEM_OF_UNITS = Arrays.asList(SIUnits.class,
              ImperialUnits.class, SmartHomeUnits.class, Units.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Collection<Class<? extends SystemOfUnits>> ALL_SYSTEM_OF_UNITS = Arrays.asList(SIUnits.class,
              ImperialUnits.class, SmartHomeUnits.class, Units.class);
focal_class.type: Collection<Class<? extends SystemOfUnits>>
focal_class.var_name: ALL_SYSTEM_OF_UNITS
focal_class.file: bundles/org.openhab.core/src/main/java/org/openhab/core/types/util/UnitUtils.java
focal_class.identifier: UnitUtils
focal_class.class_method_signature: UnitUtils.parseDimension(String dimension)
focal_class.full_signature: public static @Nullable Class<? extends Quantity<?>> parseDimension(String dimension)
focal_class.identifier: parseDimension
focal_class.modifiers: public static @Nullable
focal_class.parameters: (String dimension)
focal_class.return: Class<? extends Quantity<?>>
focal_class.signature: Class<? extends Quantity<?>> parseDimension(String dimension)
focal_class.class_method_signature: UnitUtils.getDimensionName(Unit<?> unit)
focal_class.full_signature: public static @Nullable String getDimensionName(Unit<?> unit)
focal_class.identifier: getDimensionName
focal_class.modifiers: public static @Nullable
focal_class.parameters: (Unit<?> unit)
focal_class.return: String
focal_class.signature: String getDimensionName(Unit<?> unit)
focal_class.class_method_signature: UnitUtils.parseUnit(@Nullable String pattern)
focal_class.full_signature: public static @Nullable Unit<?> parseUnit(@Nullable String pattern)
focal_class.identifier: parseUnit
focal_class.modifiers: public static @Nullable
focal_class.parameters: (@Nullable String pattern)
focal_class.return: Unit<?>
focal_class.signature: Unit<?> parseUnit(@Nullable String pattern)
focal_class.class_method_signature: UnitUtils.isDifferentMeasurementSystem(Unit<? extends Quantity<?>> thisUnit, Unit<?> thatUnit)
focal_class.full_signature: public static boolean isDifferentMeasurementSystem(Unit<? extends Quantity<?>> thisUnit, Unit<?> thatUnit)
focal_class.identifier: isDifferentMeasurementSystem
focal_class.modifiers: public static
focal_class.parameters: (Unit<? extends Quantity<?>> thisUnit, Unit<?> thatUnit)
focal_class.return: boolean
focal_class.signature: boolean isDifferentMeasurementSystem(Unit<? extends Quantity<?>> thisUnit, Unit<?> thatUnit)
focal_class.class_method_signature: UnitUtils.isMetricConversion(UnitConverter converter)
focal_class.full_signature: private static boolean isMetricConversion(UnitConverter converter)
focal_class.identifier: isMetricConversion
focal_class.modifiers: private static
focal_class.parameters: (UnitConverter converter)
focal_class.return: boolean
focal_class.signature: boolean isMetricConversion(UnitConverter converter)
focal_class.class_method_signature: UnitUtils.dimensionClass(String prefix, String name)
focal_class.full_signature: @SuppressWarnings("unchecked") private static Class<? extends Quantity<?>> dimensionClass(String prefix, String name)
focal_class.identifier: dimensionClass
focal_class.modifiers: @SuppressWarnings("unchecked") private static
focal_class.parameters: (String prefix, String name)
focal_class.return: Class<? extends Quantity<?>>
focal_class.signature: Class<? extends Quantity<?>> dimensionClass(String prefix, String name)
focal_method.body: public static @Nullable Unit<?> parseUnit(@Nullable String pattern) {
          if (pattern == null || pattern.isBlank()) {
              return null;
          }
  
          String unitSymbol = pattern;
          int lastBlankIndex = pattern.lastIndexOf(" ");
          if (lastBlankIndex >= 0) {
              unitSymbol = pattern.substring(lastBlankIndex).trim();
          }
  
          if (!UNIT_PLACEHOLDER.equals(unitSymbol)) {
              if (UNIT_PERCENT_FORMAT_STRING.equals(unitSymbol)) {
                  return SmartHomeUnits.PERCENT;
              }
              try {
                  Quantity<?> quantity = Quantities.getQuantity("1 " + unitSymbol);
                  return quantity.getUnit();
              } catch (IllegalArgumentException e) {
                  // we expect this exception in case the extracted string does not match any known unit
                  LOGGER.debug("Unknown unit from pattern: {}", unitSymbol);
              }
          }
  
          return null;
      }
focal_method.class_method_signature: UnitUtils.parseUnit(@Nullable String pattern)
focal_method.full_signature: public static @Nullable Unit<?> parseUnit(@Nullable String pattern)
focal_method.identifier: parseUnit
focal_method.invocations: isBlank lastIndexOf trim substring equals equals getQuantity getUnit debug
focal_method.modifiers: public static @Nullable
focal_method.parameters: (@Nullable String pattern)
focal_method.return: Unit<?>
focal_method.signature: Unit<?> parseUnit(@Nullable String pattern)