Class IterableLabeledRegistry<T extends fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo, C extends Iterable<T>>
- Type Parameters:
T- the type of labeled values contained in the containersC- the type of container, which must beIterable<T>
LabeledRegistry.
This class extends BasicRegistry, storing containers under string keys,
while also providing flat access to individual labeled values if an elementRegistry
is provided at construction time.
-
Field Summary
Fields inherited from class BasicRegistry
UNDEFINED -
Constructor Summary
ConstructorsConstructorDescriptionIterableLabeledRegistry(String containerPrefix, LabeledRegistry<T> valuesRegistry) Constructs anIterableLabeledRegistrywith the given container key prefix and an optional labeled registry for individual elements. -
Method Summary
Modifier and TypeMethodDescriptiongetContainedKeys(String key) Returns the identifiers of all values contained in the container stored under the given key.protected StringPerforms the actual insertion of the key-value pair into the map.Convenience method that inserts the given value using an auto-generated key.Inserts a value into the registry under the given key, or generates a key if none is provided.voidputAll(BasicRegistry<? extends C> other) Registers all containers and their values from anotherBasicRegistry.voidRegisters all containers and their values from the given map.protected voidvalidateParams(String key, C container) Validates that the key-value pair can be safely inserted into the map.Methods inherited from class BasicRegistry
clear, containsKey, containsValue, entrySet, generateKey, get, isEmpty, keySet, remove, rollback, size, values
-
Constructor Details
-
IterableLabeledRegistry
Constructs anIterableLabeledRegistrywith the given container key prefix and an optional labeled registry for individual elements.- Parameters:
containerPrefix- the prefix to use for auto-generated container keysvaluesRegistry- the registry to use for indexing individual labeled values; may benullto disable element-level access
-
-
Method Details
-
put
public String put(C container) throws NullPointerException, IllegalArgumentException, IllegalStateException Description copied from class:BasicRegistryConvenience method that inserts the given value using an auto-generated key.This is a shorthand for calling
BasicRegistry.put(String, Object)withUNDEFINEDas the key, triggering automatic key generation.- Overrides:
putin classBasicRegistry<C extends Iterable<T>>- Parameters:
container- the value to insert; must not benull- Returns:
- the generated key used for insertion
- Throws:
NullPointerException- if the value isnullIllegalStateException- if a unique key could not be generated or validation failsIllegalArgumentException- See Also:
-
validateParams
Description copied from class:BasicRegistryValidates that the key-value pair can be safely inserted into the map.By default, this method checks that if the key already exists, it must be associated with the same object instance (reference equality).
Subclasses can override this method to implement custom validation logic.
- Overrides:
validateParamsin classBasicRegistry<C extends Iterable<T>>- Parameters:
key- the key to validatecontainer- the value to validate- Throws:
IllegalStateException- if the key already exists and is mapped to a different value
-
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<C extends Iterable<T>>- Parameters:
key- the key to insertcontainer- 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, C container) throws NullPointerException, IllegalArgumentException, IllegalStateException Description copied from class:BasicRegistryInserts a value into the registry under the given key, or generates a key if none is provided.If the specified key is
UNDEFINED, a unique key will be generated using aNamesGenerator. Otherwise, the provided key is used. In both cases, the method ensures the key is not already associated with a different value.Unlike
Map.put(Object, Object), this method returns the actual key used, not the value. This is intentional to allow retrieval of auto-generated keys.This method delegates to four other methods to fulfill its responsibilities:
BasicRegistry.generateKey(String, Object): Resolves the final key to useBasicRegistry.validateParams(String, Object): Ensures the key-value pair can be safely addedBasicRegistry.insert(String, Object): Actually inserts the entry into the mapBasicRegistry.rollback(String, Object, RuntimeException): Handles insertion failure (optional override)
- Overrides:
putin classBasicRegistry<C extends Iterable<T>>- Parameters:
key- the desired key to associate with the value. IfUNDEFINED, a new key is auto-generated.container- the non-null value to insert into the registry- Returns:
- the key used to store the value (either provided or generated)
- Throws:
NullPointerException- if either key or value isnullIllegalStateException- if:- the key already exists and is associated with a different value
- a unique key could not be generated within the allowed attempts
IllegalArgumentException
-
putAll
public void putAll(Map<? extends String, ? extends C> other) throws NullPointerException, IllegalArgumentException, IllegalStateException Registers all containers and their values from the given map. All entries are validated before insertion.- Overrides:
putAllin classBasicRegistry<C extends Iterable<T>>- Parameters:
other- the map of key-container pairs to insert- Throws:
NullPointerException- if the map, any key, or any value isnullIllegalArgumentException- if any value violates label constraintsIllegalStateException- if any key already exists
-
putAll
public void putAll(BasicRegistry<? extends C> other) throws NullPointerException, IllegalStateException, IllegalArgumentException Registers all containers and their values from anotherBasicRegistry.- Overrides:
putAllin classBasicRegistry<C extends Iterable<T>>- Parameters:
other- another registry containing containers of labeled values- Throws:
NullPointerException- if the registry or any of its entries isnullIllegalArgumentException- if any value violates label constraintsIllegalStateException- if any key already exists
-
getContainedKeys
-