Class LabeledRegistry<T extends fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo>
- Type Parameters:
T- the type of labeled objects stored in this registry
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.
-
Field Summary
Fields inherited from class BasicRegistry
UNDEFINED -
Constructor Summary
ConstructorsConstructorDescriptionLabeledRegistry(String prefix) Creates a labeled registry using the given key prefix. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsValue(T value) Checks whether the registry contains the given labeled value.protected StringgenerateKey(String key, T value) Generates the final key to use for storing the given value.protected StringPerforms the actual insertion of the key-value pair into the map.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.Inserts the given labeled value into the registry.removeValue(T value) Removes the given labeled value from the registry using its label.Methods inherited from class BasicRegistry
clear, containsKey, entrySet, get, isEmpty, keySet, putAll, putAll, remove, rollback, size, validateParams, values
-
Constructor Details
-
LabeledRegistry
Creates a labeled registry using the given key prefix.- Parameters:
prefix- the prefix used for generated keys
-
-
Method Details
-
put
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 viasetLabel(), before inserting it.If the value already has a label, it will be used directly as the key.
- Overrides:
putin classBasicRegistry<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 isnullIllegalStateException- if the key already exists in the registry- See Also:
-
generateKey
Description copied from class:BasicRegistryGenerates 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 theNamesGenerator, 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_RETRYattempts, an exception is thrown.- Overrides:
generateKeyin classBasicRegistry<T extends fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo>- Parameters:
key- the initial key, possiblyUNDEFINEDvalue- 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
Description copied from class:BasicRegistryPerforms 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:
insertin classBasicRegistry<T extends fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo>- Parameters:
key- the key to insertvalue- the value to associate with the key- Returns:
- the key used for insertion
- Throws:
RegistryInsertionException- if the insertion fails unexpectedly
-
put
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:
putin classBasicRegistry<T extends fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo>- Parameters:
key- the key to associate with the valuevalue- the labeled value to insert- Returns:
- the key used to register the value
- Throws:
NullPointerException- if the key or value isnullIllegalStateException- if the key already exists in the registry, or if it does not match the value’s existing label
-
containsValue
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:
containsValuein classBasicRegistry<T extends fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo>- Parameters:
value- the labeled value to check- Returns:
trueif a value with the same label exists in the registry;falseotherwise- Throws:
NullPointerException- if the value isnull
-
removeValue
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
nullif no such key existed - Throws:
NullPointerException- if the value isnull
-