netbits.registries.registry.Registry¶
- class netbits.registries.registry.Registry[source]¶
Bases:
Generic[T]A generic registry to store and retrieve items by their identifiers.
Methods
__init__()Initialize an empty registry.
get(identifier)Retrieve an item from the registry by its identifier.
get_id(value)Retrieve the identifier of an item in the registry.
register(identifier, value)Register an item with its identifier in the registry.
- get(identifier: Identifier) T | None[source]¶
Retrieve an item from the registry by its identifier.
- Parameters:
identifier (Identifier) – The identifier of the item to retrieve.
- Returns:
The item associated with the identifier, or None if not found.
- Return type:
T | None
- get_id(value: T) Identifier | None[source]¶
Retrieve the identifier of an item in the registry.
- Parameters:
value (T) – The item whose identifier is to be retrieved.
- Returns:
The identifier associated with the item, or None if not found.
- Return type:
Identifier | None
- register(identifier: Identifier, value: T)[source]¶
Register an item with its identifier in the registry.
- Parameters:
identifier (Identifier) – The identifier for the item.
value (T) – The item to be registered.
- Raises:
ValueError – If the identifier is not an instance of the Identifier class.