Package com.guinetik.hexafun.hexa
Class AdapterKey<From,To>
java.lang.Object
com.guinetik.hexafun.hexa.AdapterKey<From,To>
- Type Parameters:
From- The source type to adapt fromTo- The target type to adapt to
Type-safe key for adapter registration and invocation.
Provides compile-time type checking for transformations between types.
Adapters transform data from one type to another, useful for:
- Converting between use case input types
- Mapping domain objects to DTOs
- Transforming external data to internal representations
Usage:
// Define keys as constants
public interface OrderAdapters {
AdapterKey<OrderRequest, InventoryCheck> TO_INVENTORY =
AdapterKey.of("orderToInventory");
AdapterKey<OrderRequest, PaymentRequest> TO_PAYMENT =
AdapterKey.of("orderToPayment");
}
// Register in DSL
HexaFun.dsl()
.withAdapter(TO_INVENTORY, req -> new InventoryCheck(req.itemId()))
.withAdapter(TO_PAYMENT, req -> new PaymentRequest(req.total()))
.useCase(...)
.build();
// Type-safe adaptation
InventoryCheck check = app.adapt(TO_INVENTORY, orderRequest);
-
Method Summary
-
Method Details
-
of
Create a new type-safe adapter key.- Type Parameters:
From- The source typeTo- The target type- Parameters:
name- The unique name for this adapter- Returns:
- A new AdapterKey instance
-
name
Get the string name of this adapter key.- Returns:
- The adapter name
-
equals
-
hashCode
public int hashCode() -
toString
-