Class RuleSupportRuleRegistryDelegate

java.lang.Object
org.openhab.core.automation.module.script.rulesupport.shared.RuleSupportRuleRegistryDelegate
All Implemented Interfaces:
RuleRegistry, Registry<Rule,String>

@NonNullByDefault public class RuleSupportRuleRegistryDelegate extends Object implements RuleRegistry
The RuleSupportRuleRegistryDelegate is wrapping a RuleRegistry to provide a comfortable way to add rules to the RuleManager without worrying about the need to remove rules again. Nonetheless, using the addPermanent method it is still possible to add rules permanently.
Author:
Simon Merschjohann - Initial contribution
  • Constructor Details

  • Method Details

    • addRegistryChangeListener

      public void addRegistryChangeListener(RegistryChangeListener<Rule> listener)
      Description copied from interface: Registry
      Adds a RegistryChangeListener to the registry.
      Specified by:
      addRegistryChangeListener in interface Registry<Rule,String>
      Parameters:
      listener - registry change listener
    • getAll

      public Collection<Rule> getAll()
      Description copied from interface: Registry
      Returns a collection of all elements in the registry.
      Specified by:
      getAll in interface Registry<Rule,String>
      Returns:
      collection of all elements in the registry
    • stream

      public Stream<Rule> stream()
      Description copied from interface: Registry
      Returns a stream of all elements in the registry.
      Specified by:
      stream in interface Registry<Rule,String>
      Returns:
      stream of all elements in the registry
    • get

      public @Nullable Rule get(String key)
      Description copied from interface: Registry
      This method retrieves a single element from the registry.
      Specified by:
      get in interface Registry<Rule,String>
      Parameters:
      key - key of the element
      Returns:
      element or null if no element was found
    • removeRegistryChangeListener

      public void removeRegistryChangeListener(RegistryChangeListener<Rule> listener)
      Description copied from interface: Registry
      Removes a RegistryChangeListener from the registry.
      Specified by:
      removeRegistryChangeListener in interface Registry<Rule,String>
      Parameters:
      listener - registry change listener
    • add

      public Rule add(Rule element)
      Description copied from interface: RuleRegistry
      This method is used to register a Rule into the RuleRegistry. First the Rule become RuleStatus.UNINITIALIZED. Then verification procedure will be done and the Rule become RuleStatus.IDLE. If the verification fails, the Rule will stay RuleStatus.UNINITIALIZED.
      Specified by:
      add in interface Registry<Rule,String>
      Specified by:
      add in interface RuleRegistry
      Parameters:
      element - a Rule instance which have to be added into the RuleRegistry.
      Returns:
      a copy of the added Rule
    • addPermanent

      public void addPermanent(Rule element)
      add a rule permanently to the RuleManager
      Parameters:
      element - the rule
    • update

      public @Nullable Rule update(Rule element)
      Description copied from interface: Registry
      Updates the given element at the according ManagedProvider.
      Specified by:
      update in interface Registry<Rule,String>
      Parameters:
      element - element to be updated (must not be null)
      Returns:
      returns the old element or null if no element with the same key exists
    • remove

      public @Nullable Rule remove(String key)
      Description copied from interface: Registry
      Removes the given element from the according ManagedProvider.
      Specified by:
      remove in interface Registry<Rule,String>
      Parameters:
      key - key of the element (must not be null)
      Returns:
      element that was removed, or null if no element with the given key exists
    • getByTag

      public Collection<Rule> getByTag(@Nullable String tag)
      Description copied from interface: RuleRegistry
      Gets a collection of Rules which shares same tag.
      Specified by:
      getByTag in interface RuleRegistry
      Parameters:
      tag - specifies a tag that will filter the rules.
      Returns:
      collection of Rules having specified tag.
    • removeAllAddedByScript

      public void removeAllAddedByScript()
      called when the script is unloaded or reloaded
    • getByTags

      public Collection<Rule> getByTags(String... tags)
      Description copied from interface: RuleRegistry
      Gets a collection of Rules which has specified tags.
      Specified by:
      getByTags in interface RuleRegistry
      Parameters:
      tags - specifies tags that will filter the rules.
      Returns:
      collection of Rules having specified tags.
    • regenerateFromTemplate

      public void regenerateFromTemplate(String ruleUID)
      Description copied from interface: RuleRegistry
      This method triggers a new generation of the rule from its template by reverting the rule to its "rule stub" state only containing the template configuration.
      Specified by:
      regenerateFromTemplate in interface RuleRegistry
      Parameters:
      ruleUID - the UID of the Rule.