Class AbstractManagedProvider<E extends Identifiable<K>,K,PE>

java.lang.Object
org.openhab.core.common.registry.AbstractProvider<E>
org.openhab.core.common.registry.AbstractManagedProvider<E,K,PE>
Type Parameters:
E - type of the element
K - type of the element key
PE - type of the persistable element
All Implemented Interfaces:
ManagedProvider<E,K>, Provider<E>
Direct Known Subclasses:
DefaultAbstractManagedProvider, ManagedItemProvider, ManagedPersistenceServiceConfigurationProvider, ManagedRuleProvider, ManagedSemanticTagProvider, ManagedThingProvider, ManagedTransformationProvider

@NonNullByDefault public abstract class AbstractManagedProvider<@NonNull E extends Identifiable<@NonNull K>,@NonNull K,@NonNull PE> extends AbstractProvider<E> implements ManagedProvider<E,K>
AbstractManagedProvider is an abstract implementation for the ManagedProvider interface and can be used as base class for ManagedProvider implementations. It uses the StorageService to persist the elements.

It provides the possibility to transform the element into another java class, that can be persisted. This is needed, if the original element class is not directly persistable. If the element type can be persisted directly the DefaultAbstractManagedProvider can be used as base class.

Author:
Dennis Nobel - Initial contribution
  • Field Details

    • logger

      protected final org.slf4j.Logger logger
  • Constructor Details

    • AbstractManagedProvider

      protected AbstractManagedProvider(StorageService storageService)
  • Method Details

    • add

      public void add(@NonNull E element)
      Description copied from interface: ManagedProvider
      Adds an element.
      Specified by:
      add in interface ManagedProvider<E extends Identifiable<K>,K>
      Parameters:
      element - element to be added
    • getAll

      public Collection<E> getAll()
      Description copied from interface: Provider
      Returns a collection of all elements.
      Specified by:
      getAll in interface Provider<E extends Identifiable<K>>
      Returns:
      collection of all elements
    • get

      public @Nullable E get(@NonNull K key)
      Description copied from interface: ManagedProvider
      Returns an element for the given key or null if no element for the given key exists.
      Specified by:
      get in interface ManagedProvider<E extends Identifiable<K>,K>
      Parameters:
      key - key
      Returns:
      returns element or null, if no element for the given key exists
    • remove

      public @Nullable E remove(@NonNull K key)
      Description copied from interface: ManagedProvider
      Removes an element and returns the removed element.
      Specified by:
      remove in interface ManagedProvider<E extends Identifiable<K>,K>
      Parameters:
      key - key of the element that should be removed
      Returns:
      element that was removed, or null if no element with the given key exists
    • update

      public @Nullable E update(@NonNull E element)
      Description copied from interface: ManagedProvider
      Updates an element.
      Specified by:
      update in interface ManagedProvider<E extends Identifiable<K>,K>
      Parameters:
      element - element to be updated
      Returns:
      returns the old element or null if no element with the same key exists
    • getStorageName

      protected abstract String getStorageName()
      Returns the name of storage, that is used to persist the elements.
      Returns:
      name of the storage
    • keyToString

      protected abstract String keyToString(@NonNull K key)
      Transforms the key into a string representation.
      Parameters:
      key - key
      Returns:
      string representation of the key
    • toElement

      protected abstract @Nullable E toElement(String key, @NonNull PE persistableElement)
      Converts the persistable element into the original element.
      Parameters:
      key - key
      persistableElement - persistable element
      Returns:
      original element
    • toPersistableElement

      protected abstract PE toPersistableElement(@NonNull E element)
      Converts the original element into an element that can be persisted.
      Parameters:
      element - original element
      Returns:
      persistable element