Class LabeledRegistry<T extends fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo>

java.lang.Object
fr.inria.rules.integraal.api.external.registries.BasicRegistry<T>
fr.inria.rules.integraal.api.external.registries.LabeledRegistry<T>
Type Parameters:
T - the type of labeled objects stored in this registry

public class LabeledRegistry<T extends fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo> extends BasicRegistry<T>
A specialized BasicRegistry that manages Labeled objects, ensuring each value is consistently labeled with its corresponding registry key.

If a value is inserted without a label, a key will be generated and assigned to the value via setLabel. If a value already has a label, that label will be used as the registry key.

This registry enforces strict consistency between keys and value labels: inserting a value with a mismatched label and key is not allowed and results in an exception.

Note: This is a temporary version used prior to the transition to DLGPE. After that switch, Name and getName() will be used in place of the more ambiguous Label API.

  • Constructor Details

    • LabeledRegistry

      public LabeledRegistry(String prefix)
      Creates a labeled registry using the given key prefix.
      Parameters:
      prefix - the prefix used for generated keys
  • Method Details

    • put

      public String put(T value) throws IllegalStateException, NullPointerException
      Inserts the given labeled value into the registry.

      If the value has no label (i.e., getLabel().equals("")), a key will be auto-generated using the registry's prefix and assigned to the value via setLabel(), before inserting it.

      If the value already has a label, it will be used directly as the key.

      Overrides:
      put in class BasicRegistry<T extends fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo>
      Parameters:
      value - the labeled value to insert
      Returns:
      the key used to register the value
      Throws:
      NullPointerException - if the value is null
      IllegalStateException - if the key already exists in the registry
      See Also:
    • generateKey

      protected String generateKey(String key, T value) throws IllegalStateException
      Description copied from class: BasicRegistry
      Generates the final key to use for storing the given value.

      If the provided key is not equal to UNDEFINED, it is returned unchanged. Otherwise, this method attempts to generate a unique key using the NamesGenerator, appending a timestamp and a configured prefix.

      The method ensures that the generated key does not collide with existing entries in the map. If a unique key cannot be found within MAX_RETRY attempts, an exception is thrown.

      Overrides:
      generateKey in class BasicRegistry<T extends fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo>
      Parameters:
      key - the initial key, possibly UNDEFINED
      value - the value to be stored
      Returns:
      a key guaranteed to be non-null and not already present in the map
      Throws:
      IllegalStateException - if a unique key could not be generated within allowed attempts
    • insert

      protected String insert(String key, T value) throws RegistryInsertionException
      Description copied from class: BasicRegistry
      Performs the actual insertion of the key-value pair into the map.

      This method should not perform validation, but rather assume the key and value have been verified already. The default implementation inserts the pair into the map and returns the key.

      Subclasses may override to perform custom insertion strategies.

      Overrides:
      insert in class BasicRegistry<T extends fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo>
      Parameters:
      key - the key to insert
      value - the value to associate with the key
      Returns:
      the key used for insertion
      Throws:
      RegistryInsertionException - if the insertion fails unexpectedly
    • put

      public String put(String key, T value) throws IllegalStateException, NullPointerException
      Inserts the given labeled value into the registry using the specified key, but only if it does not conflict with the value's internal label.

      If the value has no label, the provided key is assigned to it via setLabel(), and used for registration.

      If the value already has a label that differs from the provided key, an exception is thrown to prevent inconsistent state.

      Overrides:
      put in class BasicRegistry<T extends fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo>
      Parameters:
      key - the key to associate with the value
      value - the labeled value to insert
      Returns:
      the key used to register the value
      Throws:
      NullPointerException - if the key or value is null
      IllegalStateException - if the key already exists in the registry, or if it does not match the value’s existing label
    • containsValue

      public boolean containsValue(T value) throws NullPointerException
      Checks whether the registry contains the given labeled value.

      This method performs the check using the value's label as a key, offering constant-time lookup (O(1)) instead of linear-time iteration (O(n)) based on value equality.

      Overrides:
      containsValue in class BasicRegistry<T extends fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo>
      Parameters:
      value - the labeled value to check
      Returns:
      true if a value with the same label exists in the registry; false otherwise
      Throws:
      NullPointerException - if the value is null
    • removeValue

      public String removeValue(T value)
      Removes the given labeled value from the registry using its label.

      This operation performs a constant-time O(1) lookup using the value’s label as the key, rather than iterating over the entries.

      Parameters:
      value - the labeled value to remove
      Returns:
      the key that was removed, or null if no such key existed
      Throws:
      NullPointerException - if the value is null