Class TypeBasedLocator

java.lang.Object
arez.component.TypeBasedLocator
All Implemented Interfaces:
Locator

@OmitType(unless="arez.enable_references") public final class TypeBasedLocator extends Object implements Locator
An Locator implementation where you can register a function-per type to be resolved.
  • Constructor Details

  • Method Details

    • registerLookup

      public <T> void registerLookup(@Nonnull Class<T> type, @Nonnull Function<Object,T> findByIdFunction)
      Register a function that will find entities of specified type by id. This must not be invoked if another function has already been registered for type.
      Type Parameters:
      T - the type of the entity.
      Parameters:
      type - the type of the entity.
      findByIdFunction - the function that looks up the entity by id.
    • findById

      @Nullable public <T> T findById(@Nonnull Class<T> type, @Nonnull Object id)
      Description copied from interface: Locator
      Lookup the entity with the specified type and the specified id, returning null if not present.
      Specified by:
      findById in interface Locator
      Type Parameters:
      T - the entity type.
      Parameters:
      type - the type of the entity.
      id - the id of the entity.
      Returns:
      the entity or null if no such entity.