test_class.declarator: itemStateConverter
test_class.modifier: private
test_class.original_string: private ItemStateConverterImpl itemStateConverter;
test_class.type: ItemStateConverterImpl
test_class.var_name: itemStateConverter
test_class.file: bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/ItemStateConverterImplTest.java
test_class.identifier: ItemStateConverterImplTest
test_case.body: @Test
      public void testNullState() {
          State undef = itemStateConverter.convertToAcceptedState(null, null);
  
          assertThat(undef, is(UnDefType.NULL));
      }
test_case.class_method_signature: ItemStateConverterImplTest.testNullState()
test_case.full_signature: @Test public void testNullState()
test_case.identifier: testNullState
test_case.invocations: convertToAcceptedState assertThat is
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testNullState()
focal_class.declarator: logger = LoggerFactory.getLogger(ItemStateConverterImpl.class)
focal_class.modifier: private final
focal_class.original_string: private final Logger logger = LoggerFactory.getLogger(ItemStateConverterImpl.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: unitProvider
focal_class.modifier: private final
focal_class.original_string: private final UnitProvider unitProvider;
focal_class.type: UnitProvider
focal_class.var_name: unitProvider
focal_class.file: bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/ItemStateConverterImpl.java
focal_class.identifier: ItemStateConverterImpl
focal_class.interfaces: implements ItemStateConverter
focal_class.class_method_signature: ItemStateConverterImpl.ItemStateConverterImpl(final @Reference UnitProvider unitProvider)
focal_class.full_signature: @Activate public  ItemStateConverterImpl(final @Reference UnitProvider unitProvider)
focal_class.identifier: ItemStateConverterImpl
focal_class.modifiers: @Activate public
focal_class.parameters: (final @Reference UnitProvider unitProvider)
focal_class.signature:  ItemStateConverterImpl(final @Reference UnitProvider unitProvider)
focal_class.class_method_signature: ItemStateConverterImpl.convertToAcceptedState(@Nullable State state, @Nullable Item item)
focal_class.full_signature: @Override public State convertToAcceptedState(@Nullable State state, @Nullable Item item)
focal_class.identifier: convertToAcceptedState
focal_class.modifiers: @Override public
focal_class.parameters: (@Nullable State state, @Nullable Item item)
focal_class.return: State
focal_class.signature: State convertToAcceptedState(@Nullable State state, @Nullable Item item)
focal_class.class_method_signature: ItemStateConverterImpl.convertOrUndef(QuantityType<?> quantityState, Unit<?> targetUnit)
focal_class.full_signature: private State convertOrUndef(QuantityType<?> quantityState, Unit<?> targetUnit)
focal_class.identifier: convertOrUndef
focal_class.modifiers: private
focal_class.parameters: (QuantityType<?> quantityState, Unit<?> targetUnit)
focal_class.return: State
focal_class.signature: State convertOrUndef(QuantityType<?> quantityState, Unit<?> targetUnit)
focal_class.class_method_signature: ItemStateConverterImpl.parseItemUnit(NumberItem numberItem)
focal_class.full_signature: private @Nullable Unit<?> parseItemUnit(NumberItem numberItem)
focal_class.identifier: parseItemUnit
focal_class.modifiers: private @Nullable
focal_class.parameters: (NumberItem numberItem)
focal_class.return: Unit<?>
focal_class.signature: Unit<?> parseItemUnit(NumberItem numberItem)
focal_class.class_method_signature: ItemStateConverterImpl.isAccepted(Item item, State state)
focal_class.full_signature: private boolean isAccepted(Item item, State state)
focal_class.identifier: isAccepted
focal_class.modifiers: private
focal_class.parameters: (Item item, State state)
focal_class.return: boolean
focal_class.signature: boolean isAccepted(Item item, State state)
focal_method.body: @Override
      public State convertToAcceptedState(@Nullable State state, @Nullable Item item) {
          if (state == null) {
              logger.error("A conversion of null was requested:",
                      new IllegalArgumentException("State must not be null."));
              return UnDefType.NULL;
          }
  
          if (item != null && !isAccepted(item, state)) {
              for (Class<? extends State> acceptedType : item.getAcceptedDataTypes()) {
                  State convertedState = state.as(acceptedType);
                  if (convertedState != null) {
                      logger.debug("Converting {} '{}' to {} '{}' for item '{}'", state.getClass().getSimpleName(), state,
                              convertedState.getClass().getSimpleName(), convertedState, item.getName());
                      return convertedState;
                  }
              }
          }
  
          if (item instanceof NumberItem && state instanceof QuantityType) {
              NumberItem numberItem = (NumberItem) item;
              if (numberItem.getDimension() != null) {
                  QuantityType<?> quantityState = (QuantityType<?>) state;
  
                  // in case the item does define a unit it takes precedence over all other conversions:
                  Unit<?> itemUnit = parseItemUnit(numberItem);
                  if (itemUnit != null) {
                      if (!itemUnit.equals(quantityState.getUnit())) {
                          return convertOrUndef(quantityState, itemUnit);
                      }
  
                      return quantityState;
                  }
  
                  Class<? extends Quantity<?>> dimension = numberItem.getDimension();
                  @SuppressWarnings({ "unchecked", "rawtypes" })
                  // explicit cast to Class<? extends Quantity> as JDK compiler complains
                  Unit<? extends Quantity<?>> conversionUnit = unitProvider
                          .getUnit((Class<? extends Quantity>) dimension);
                  if (conversionUnit != null
                          && UnitUtils.isDifferentMeasurementSystem(conversionUnit, quantityState.getUnit())) {
                      return convertOrUndef(quantityState, conversionUnit);
                  }
  
                  return state;
              } else {
                  State convertedState = state.as(DecimalType.class);
                  if (convertedState != null) {
                      // convertedState is always returned because the state is an instance
                      // of QuantityType which never returns null for as(DecimalType.class)
                      return convertedState;
                  }
              }
          }
  
          return state;
      }
focal_method.class_method_signature: ItemStateConverterImpl.convertToAcceptedState(@Nullable State state, @Nullable Item item)
focal_method.full_signature: @Override public State convertToAcceptedState(@Nullable State state, @Nullable Item item)
focal_method.identifier: convertToAcceptedState
focal_method.invocations: error isAccepted getAcceptedDataTypes as debug getSimpleName getClass getSimpleName getClass getName getDimension parseItemUnit equals getUnit convertOrUndef getDimension getUnit isDifferentMeasurementSystem getUnit convertOrUndef as
focal_method.modifiers: @Override public
focal_method.parameters: (@Nullable State state, @Nullable Item item)
focal_method.return: State
focal_method.signature: State convertToAcceptedState(@Nullable State state, @Nullable Item item)