Package com.guinetik.hexafun.hexa
Class InMemoryHexaRepo<T>
java.lang.Object
com.guinetik.hexafun.hexa.InMemoryHexaRepo<T>
- Type Parameters:
T- The entity type this repository manages
- All Implemented Interfaces:
HexaRepo<T>
Generic in-memory implementation of the HexaRepo interface.
Uses a HashMap to store entities with string IDs.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new InMemoryHexaRepo with default behavior.InMemoryHexaRepo(Function<T, String> idExtractor) Creates a new InMemoryHexaRepo with default UUID generation.Creates a new InMemoryHexaRepo with custom ID extraction and generation. -
Method Summary
Modifier and TypeMethodDescriptionclear()Removes all entities from the repository.count()Counts the total number of entities in the repository.deleteAllById(List<String> ids) Deletes multiple entities by their IDs in a batch operation.deleteById(String id) Deletes an entity by its unique identifier.findAll()Retrieves all entities from the repository.findAll(int offset, int limit) Retrieves a paginated list of entities.findBy(DirectoryStream.Filter<T> filter) Retrieves entities that match the given filter criteria.Finds an entity by its unique identifier.Saves a single entity to the repository.Saves multiple entities to the repository in a batch operation.Updates an existing entity identified by its ID.
-
Constructor Details
-
InMemoryHexaRepo
Creates a new InMemoryHexaRepo with custom ID extraction and generation.- Parameters:
idExtractor- Function to extract ID from an entityidGenerator- Function to generate a new ID for an entity that doesn't have one
-
InMemoryHexaRepo
Creates a new InMemoryHexaRepo with default UUID generation. Note: This constructor assumes the entity has an ID field named "id" and is accessible via reflection or a setter.- Parameters:
idExtractor- Function to extract ID from an entity
-
InMemoryHexaRepo
public InMemoryHexaRepo()Creates a new InMemoryHexaRepo with default behavior. The idExtractor returns the ID from storage based on the entity. The idGenerator simply returns the entity as is.
-
-
Method Details
-
save
Description copied from interface:HexaRepoSaves a single entity to the repository. -
saveAll
Description copied from interface:HexaRepoSaves multiple entities to the repository in a batch operation. -
findById
Description copied from interface:HexaRepoFinds an entity by its unique identifier. -
findAll
Description copied from interface:HexaRepoRetrieves all entities from the repository. -
findBy
Description copied from interface:HexaRepoRetrieves entities that match the given filter criteria. -
findAll
Description copied from interface:HexaRepoRetrieves a paginated list of entities. -
count
Description copied from interface:HexaRepoCounts the total number of entities in the repository. -
update
Description copied from interface:HexaRepoUpdates an existing entity identified by its ID. -
deleteById
Description copied from interface:HexaRepoDeletes an entity by its unique identifier.- Specified by:
deleteByIdin interfaceHexaRepo<T>- Parameters:
id- The unique identifier of the entity to delete- Returns:
- A Result containing a Boolean indicating success
-
deleteAllById
Description copied from interface:HexaRepoDeletes multiple entities by their IDs in a batch operation.- Specified by:
deleteAllByIdin interfaceHexaRepo<T>- Parameters:
ids- The list of entity IDs to delete- Returns:
- A Result indicating the operation outcome
-
clear
Description copied from interface:HexaRepoRemoves all entities from the repository.
-