Class AdapterKey<From,To>

java.lang.Object
com.guinetik.hexafun.hexa.AdapterKey<From,To>
Type Parameters:
From - The source type to adapt from
To - The target type to adapt to

public final class AdapterKey<From,To> extends Object
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 Details

    • of

      public static <From, To> AdapterKey<From,To> of(String name)
      Create a new type-safe adapter key.
      Type Parameters:
      From - The source type
      To - The target type
      Parameters:
      name - The unique name for this adapter
      Returns:
      A new AdapterKey instance
    • name

      public String name()
      Get the string name of this adapter key.
      Returns:
      The adapter name
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object