Package com.guinetik.hexafun
Class HexaApp
java.lang.Object
com.guinetik.hexafun.HexaApp
- Direct Known Subclasses:
HexaAppImpl
Core container for a Hexagonal Architecture application.
Manages use cases, ports, and adapters.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<From,To> To adapt(AdapterKey<From, To> key, From input) Adapt a value using a type-safe adapter key.static HexaAppcreate()Create a new empty HexaApp.booleanhasAdapter(AdapterKey<?, ?> key) Check if an adapter is registered for the given key.booleanCheck if a port is registered for the given type.<I,O> O invoke(UseCaseKey<I, O> key, I input) Invoke a use case using a type-safe key.<I,O> O invokeByName(String name, I input) Invoke a use case by name (for internal/testing use).<T> TRetrieve a port by its type.<T> HexaAppRegister a port (output adapter) by its type.Get all registered adapter names.Get all registered port types.Get the names of all registered use cases.voidrun()Optional startup logic.<I,O> UseCaseTest<I, O> test(UseCaseKey<I, O> key) Start testing a use case using a type-safe key.<From,To> HexaApp withAdapter(AdapterKey<From, To> key, Function<From, To> adapter) Register an adapter with a type-safe key.<From,To> HexaApp withAdapter(String name, Function<From, To> adapter) Register an adapter by name (used internally by builder).<I,O> HexaApp withUseCase(UseCaseKey<I, O> key, UseCase<I, O> useCase) Add a use case using a type-safe key.<I,O> HexaApp withUseCase(String name, UseCase<I, O> useCase) Add a use case to this HexaApp (used internally by builder).
-
Field Details
-
useCases
-
ports
-
adapters
-
-
Constructor Details
-
HexaApp
public HexaApp()
-
-
Method Details
-
create
Create a new empty HexaApp.- Returns:
- A new empty HexaApp
-
withUseCase
Add a use case to this HexaApp (used internally by builder). -
withUseCase
Add a use case using a type-safe key.Example:
app.withUseCase(CREATE_TASK, new CreateTaskHandler(app));- Type Parameters:
I- Input typeO- Output type- Parameters:
key- The type-safe use case keyuseCase- The use case implementation- Returns:
- This HexaApp for chaining
-
port
Register a port (output adapter) by its type. Provides type-safe dependency injection for output ports.Example:
app.port(TaskRepository.class, new InMemoryTaskRepository());- Type Parameters:
T- The port type- Parameters:
type- The interface/class type to registerimpl- The implementation instance- Returns:
- This HexaApp for chaining
-
port
Retrieve a port by its type.Example:
TaskRepository repo = app.port(TaskRepository.class);- Type Parameters:
T- The port type- Parameters:
type- The interface/class type to retrieve- Returns:
- The registered implementation
- Throws:
IllegalArgumentException- if no port is registered for the given type
-
hasPort
Check if a port is registered for the given type.- Parameters:
type- The interface/class type to check- Returns:
- true if a port is registered, false otherwise
-
registeredPorts
Get all registered port types.- Returns:
- A set of registered port types
-
withAdapter
Register an adapter with a type-safe key. Adapters transform data from one type to another.Example:
app.withAdapter(TO_INVENTORY, req -> new InventoryCheck(req.itemId()));- Type Parameters:
From- The source typeTo- The target type- Parameters:
key- The type-safe adapter keyadapter- The adapter function- Returns:
- This HexaApp for chaining
-
withAdapter
Register an adapter by name (used internally by builder).- Type Parameters:
From- The source typeTo- The target type- Parameters:
name- The adapter nameadapter- The adapter function- Returns:
- This HexaApp for chaining
-
adapt
Adapt a value using a type-safe adapter key. Transforms the input from one type to another.Example:
InventoryCheck check = app.adapt(TO_INVENTORY, orderRequest);- Type Parameters:
From- The source typeTo- The target type- Parameters:
key- The type-safe adapter keyinput- The value to adapt- Returns:
- The adapted value
- Throws:
IllegalArgumentException- if no adapter is registered with the given key
-
hasAdapter
Check if an adapter is registered for the given key.- Parameters:
key- The adapter key to check- Returns:
- true if an adapter is registered, false otherwise
-
registeredAdapters
Get all registered adapter names.- Returns:
- A set of registered adapter names
-
invoke
Invoke a use case using a type-safe key. Provides compile-time type checking for input and output types.- Type Parameters:
I- The input type of the use caseO- The output type of the use case- Parameters:
key- The type-safe key for the use caseinput- The input to the use case- Returns:
- The result of the use case
- Throws:
IllegalArgumentException- if no use case is registered with the given key
-
registeredUseCases
Get the names of all registered use cases.- Returns:
- A set of registered use case names
-
invokeByName
Invoke a use case by name (for internal/testing use). Prefer usinginvoke(UseCaseKey, Object)for type safety.- Type Parameters:
I- The input typeO- The output type- Parameters:
name- The name of the use caseinput- The input to the use case- Returns:
- The result of the use case
- Throws:
IllegalArgumentException- if no use case is registered with the given name
-
test
Start testing a use case using a type-safe key.- Type Parameters:
I- Input type of the use caseO- Output type of the use case- Parameters:
key- The type-safe key for the use case- Returns:
- A new UseCaseTest instance
-
run
public void run()Optional startup logic.
-