test_class.declarator: ITEM_NAME = "itemName"
test_class.modifier: private static final
test_class.original_string: private static final String ITEM_NAME = "itemName";
test_class.type: String
test_class.var_name: ITEM_NAME
test_class.declarator: managedProviderRef
test_class.modifier: @SuppressWarnings("rawtypes")
      private @Mock
test_class.original_string: @SuppressWarnings("rawtypes")
      private @Mock ServiceReference managedProviderRef;
test_class.type: ServiceReference
test_class.var_name: managedProviderRef
test_class.declarator: bundleContext
test_class.modifier: private @Mock
test_class.original_string: private @Mock BundleContext bundleContext;
test_class.type: BundleContext
test_class.var_name: bundleContext
test_class.declarator: managedProvider
test_class.modifier: private @Mock
test_class.original_string: private @Mock ManagedMetadataProvider managedProvider;
test_class.type: ManagedMetadataProvider
test_class.var_name: managedProvider
test_class.declarator: metadataRegistry
test_class.modifier: private @Mock
test_class.original_string: private @Mock MetadataRegistryImpl metadataRegistry;
test_class.type: MetadataRegistryImpl
test_class.var_name: metadataRegistry
test_class.declarator: stateDescriptionFragmentProvider
test_class.modifier: private
test_class.original_string: private MetadataStateDescriptionFragmentProvider stateDescriptionFragmentProvider;
test_class.type: MetadataStateDescriptionFragmentProvider
test_class.var_name: stateDescriptionFragmentProvider
test_class.declarator: providerTracker
test_class.modifier: private
test_class.original_string: private ServiceListener providerTracker;
test_class.type: ServiceListener
test_class.var_name: providerTracker
test_class.file: bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/MetadataStateDescriptionFragmentProviderTest.java
test_class.identifier: MetadataStateDescriptionFragmentProviderTest
test_case.body: @SuppressWarnings("null")
      @Test
      public void testFragment() throws Exception {
          MetadataKey metadataKey = new MetadataKey("stateDescription", ITEM_NAME);
          Map<String, Object> metadataConfig = new HashMap<>();
          metadataConfig.put("pattern", "%.1f %unit%");
          metadataConfig.put("min", 18.5);
          metadataConfig.put("max", "34");
          metadataConfig.put("step", 3);
          metadataConfig.put("readOnly", "true");
          metadataConfig.put("options", "OPTION1,OPTION2 , 3 =Option 3 ");
          Metadata metadata = new Metadata(metadataKey, "N/A", metadataConfig);
          metadataRegistry.added(managedProvider, metadata);
  
          StateDescriptionFragment stateDescriptionFragment = stateDescriptionFragmentProvider
                  .getStateDescriptionFragment(ITEM_NAME, null);
          assertNotNull(stateDescriptionFragment);
          assertEquals("%.1f %unit%", stateDescriptionFragment.getPattern());
          assertEquals(new BigDecimal(18.5), stateDescriptionFragment.getMinimum());
          assertEquals(new BigDecimal(34), stateDescriptionFragment.getMaximum());
          assertEquals(new BigDecimal(3), stateDescriptionFragment.getStep());
          assertEquals(true, stateDescriptionFragment.isReadOnly());
          assertNotNull(stateDescriptionFragment.getOptions());
          Iterator<StateOption> it = stateDescriptionFragment.getOptions().iterator();
          StateOption stateOption = it.next();
          assertEquals("OPTION1", stateOption.getValue());
          assertNull(stateOption.getLabel());
          stateOption = it.next();
          assertEquals("OPTION2", stateOption.getValue());
          assertNull(stateOption.getLabel());
          stateOption = it.next();
          assertEquals("3", stateOption.getValue());
          assertEquals("Option 3", stateOption.getLabel());
      }
test_case.class_method_signature: MetadataStateDescriptionFragmentProviderTest.testFragment()
test_case.full_signature: @SuppressWarnings("null") @Test public void testFragment()
test_case.identifier: testFragment
test_case.invocations: put put put put put put added getStateDescriptionFragment assertNotNull assertEquals getPattern assertEquals getMinimum assertEquals getMaximum assertEquals getStep assertEquals isReadOnly assertNotNull getOptions iterator getOptions next assertEquals getValue assertNull getLabel next assertEquals getValue assertNull getLabel next assertEquals getValue assertEquals getLabel
test_case.modifiers: @SuppressWarnings("null") @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testFragment()
focal_class.declarator: logger = LoggerFactory.getLogger(MetadataStateDescriptionFragmentProvider.class)
focal_class.modifier: private final
focal_class.original_string: private final Logger logger = LoggerFactory.getLogger(MetadataStateDescriptionFragmentProvider.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: STATEDESCRIPTION_METADATA_NAMESPACE = "stateDescription"
focal_class.modifier: public static final
focal_class.original_string: public static final String STATEDESCRIPTION_METADATA_NAMESPACE = "stateDescription";
focal_class.type: String
focal_class.var_name: STATEDESCRIPTION_METADATA_NAMESPACE
focal_class.declarator: metadataRegistry
focal_class.modifier: private final
focal_class.original_string: private final MetadataRegistry metadataRegistry;
focal_class.type: MetadataRegistry
focal_class.var_name: metadataRegistry
focal_class.declarator: rank
focal_class.modifier: private final
focal_class.original_string: private final Integer rank;
focal_class.type: Integer
focal_class.var_name: rank
focal_class.file: bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/MetadataStateDescriptionFragmentProvider.java
focal_class.identifier: MetadataStateDescriptionFragmentProvider
focal_class.interfaces: implements StateDescriptionFragmentProvider
focal_class.class_method_signature: MetadataStateDescriptionFragmentProvider.MetadataStateDescriptionFragmentProvider(final @Reference MetadataRegistry metadataRegistry,
              Map<String, Object> properties)
focal_class.full_signature: @Activate public  MetadataStateDescriptionFragmentProvider(final @Reference MetadataRegistry metadataRegistry,
              Map<String, Object> properties)
focal_class.identifier: MetadataStateDescriptionFragmentProvider
focal_class.modifiers: @Activate public
focal_class.parameters: (final @Reference MetadataRegistry metadataRegistry,
              Map<String, Object> properties)
focal_class.signature:  MetadataStateDescriptionFragmentProvider(final @Reference MetadataRegistry metadataRegistry,
              Map<String, Object> properties)
focal_class.class_method_signature: MetadataStateDescriptionFragmentProvider.getStateDescriptionFragment(String itemName, @Nullable Locale locale)
focal_class.full_signature: @Override public @Nullable StateDescriptionFragment getStateDescriptionFragment(String itemName, @Nullable Locale locale)
focal_class.identifier: getStateDescriptionFragment
focal_class.modifiers: @Override public @Nullable
focal_class.parameters: (String itemName, @Nullable Locale locale)
focal_class.return: StateDescriptionFragment
focal_class.signature: StateDescriptionFragment getStateDescriptionFragment(String itemName, @Nullable Locale locale)
focal_class.class_method_signature: MetadataStateDescriptionFragmentProvider.getBigDecimal(Object value)
focal_class.full_signature: private BigDecimal getBigDecimal(Object value)
focal_class.identifier: getBigDecimal
focal_class.modifiers: private
focal_class.parameters: (Object value)
focal_class.return: BigDecimal
focal_class.signature: BigDecimal getBigDecimal(Object value)
focal_class.class_method_signature: MetadataStateDescriptionFragmentProvider.getBoolean(Object value)
focal_class.full_signature: private Boolean getBoolean(Object value)
focal_class.identifier: getBoolean
focal_class.modifiers: private
focal_class.parameters: (Object value)
focal_class.return: Boolean
focal_class.signature: Boolean getBoolean(Object value)
focal_class.class_method_signature: MetadataStateDescriptionFragmentProvider.getRank()
focal_class.full_signature: @Override public Integer getRank()
focal_class.identifier: getRank
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: Integer
focal_class.signature: Integer getRank()
focal_method.body: @Override
      public @Nullable StateDescriptionFragment getStateDescriptionFragment(String itemName, @Nullable Locale locale) {
          Metadata metadata = metadataRegistry.get(new MetadataKey(STATEDESCRIPTION_METADATA_NAMESPACE, itemName));
  
          if (metadata != null) {
              try {
                  StateDescriptionFragmentBuilder builder = StateDescriptionFragmentBuilder.create();
                  if (metadata.getConfiguration().containsKey("pattern")) {
                      builder.withPattern((String) metadata.getConfiguration().get("pattern"));
                  }
                  if (metadata.getConfiguration().containsKey("min")) {
                      builder.withMinimum(getBigDecimal(metadata.getConfiguration().get("min")));
                  }
                  if (metadata.getConfiguration().containsKey("max")) {
                      builder.withMaximum(getBigDecimal(metadata.getConfiguration().get("max")));
                  }
                  if (metadata.getConfiguration().containsKey("step")) {
                      builder.withStep(getBigDecimal(metadata.getConfiguration().get("step")));
                  }
                  if (metadata.getConfiguration().containsKey("readOnly")) {
                      builder.withReadOnly(getBoolean(metadata.getConfiguration().get("readOnly")));
                  }
                  if (metadata.getConfiguration().containsKey("options")) {
                      List<StateOption> stateOptions = Stream
                              .of(metadata.getConfiguration().get("options").toString().split(",")).map(o -> {
                                  return (o.contains("="))
                                          ? new StateOption(o.split("=")[0].trim(), o.split("=")[1].trim())
                                          : new StateOption(o.trim(), null);
                              }).collect(Collectors.toList());
                      builder.withOptions(stateOptions);
                  }
  
                  return builder.build();
              } catch (Exception e) {
                  logger.warn("Unable to parse the stateDescription from metadata for item {}, ignoring it", itemName);
              }
          }
  
          return null;
      }
focal_method.class_method_signature: MetadataStateDescriptionFragmentProvider.getStateDescriptionFragment(String itemName, @Nullable Locale locale)
focal_method.full_signature: @Override public @Nullable StateDescriptionFragment getStateDescriptionFragment(String itemName, @Nullable Locale locale)
focal_method.identifier: getStateDescriptionFragment
focal_method.invocations: get create containsKey getConfiguration withPattern get getConfiguration containsKey getConfiguration withMinimum getBigDecimal get getConfiguration containsKey getConfiguration withMaximum getBigDecimal get getConfiguration containsKey getConfiguration withStep getBigDecimal get getConfiguration containsKey getConfiguration withReadOnly getBoolean get getConfiguration containsKey getConfiguration collect map of split toString get getConfiguration contains trim split trim split trim toList withOptions build warn
focal_method.modifiers: @Override public @Nullable
focal_method.parameters: (String itemName, @Nullable Locale locale)
focal_method.return: StateDescriptionFragment
focal_method.signature: StateDescriptionFragment getStateDescriptionFragment(String itemName, @Nullable Locale locale)