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 testGetDimensionName() {
          assertThat(UnitUtils.getDimensionName(SIUnits.CELSIUS), is(Temperature.class.getSimpleName()));
          assertThat(UnitUtils.getDimensionName(SmartHomeUnits.KILOWATT_HOUR), is(Energy.class.getSimpleName()));
          assertThat(UnitUtils.getDimensionName(SmartHomeUnits.WATT), is(Power.class.getSimpleName()));
          assertThat(UnitUtils.getDimensionName(MetricPrefix.MEGA(SmartHomeUnits.KILOWATT_HOUR)),
                  is(Energy.class.getSimpleName()));
  
          Unit<?> unit = UnitUtils.parseUnit("°F");
          assertNotNull(unit);
          if (unit != null) {
              assertThat(UnitUtils.getDimensionName(unit), is(Temperature.class.getSimpleName()));
          }
          unit = UnitUtils.parseUnit("m");
          assertNotNull(unit);
          if (unit != null) {
              assertThat(UnitUtils.getDimensionName(unit), is(Length.class.getSimpleName()));
          }
      }
test_case.class_method_signature: UnitUtilsTest.testGetDimensionName()
test_case.full_signature: @Test public void testGetDimensionName()
test_case.identifier: testGetDimensionName
test_case.invocations: assertThat getDimensionName is getSimpleName assertThat getDimensionName is getSimpleName assertThat getDimensionName is getSimpleName assertThat getDimensionName MEGA is getSimpleName parseUnit assertNotNull assertThat getDimensionName is getSimpleName parseUnit assertNotNull assertThat getDimensionName is getSimpleName
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testGetDimensionName()
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 String getDimensionName(Unit<?> unit) {
          for (Class<? extends SystemOfUnits> system : ALL_SYSTEM_OF_UNITS) {
              for (Field field : system.getDeclaredFields()) {
                  if (field.getType().isAssignableFrom(Unit.class) && Modifier.isStatic(field.getModifiers())) {
                      Type genericType = field.getGenericType();
                      if (genericType instanceof ParameterizedType) {
                          String dimension = ((Class<?>) ((ParameterizedType) genericType).getActualTypeArguments()[0])
                                  .getSimpleName();
                          Unit<?> systemUnit;
                          try {
                              systemUnit = (Unit<?>) field.get(null);
                              if (systemUnit == null) {
                                  LOGGER.warn("Unit field points to a null value: {}", field);
                              } else if (systemUnit.isCompatible(unit)) {
                                  return dimension;
                              }
                          } catch (IllegalArgumentException | IllegalAccessException e) {
                              LOGGER.error("The unit field '{}' seems to be not accessible", field, e);
                          }
                      } else {
                          LOGGER.warn("There is a unit field defined which has no generic type parametrization: {}",
                                  field);
                      }
                  }
              }
          }
          return null;
      }
focal_method.class_method_signature: UnitUtils.getDimensionName(Unit<?> unit)
focal_method.full_signature: public static @Nullable String getDimensionName(Unit<?> unit)
focal_method.identifier: getDimensionName
focal_method.invocations: getDeclaredFields isAssignableFrom getType isStatic getModifiers getGenericType getSimpleName getActualTypeArguments get warn isCompatible error warn
focal_method.modifiers: public static @Nullable
focal_method.parameters: (Unit<?> unit)
focal_method.return: String
focal_method.signature: String getDimensionName(Unit<?> unit)