Class InMemoryEntityResolver

java.lang.Object
com.tnsai.context.entity.impl.InMemoryEntityResolver
All Implemented Interfaces:
com.tnsai.context.entity.EntityResolver

public class InMemoryEntityResolver extends Object implements com.tnsai.context.entity.EntityResolver
In-memory implementation of EntityResolver for development and testing.

This implementation stores entities in memory using thread-safe ConcurrentHashMap structures. It is suitable for development, testing, and scenarios where persistence is not required.

Thread Safety

All operations are thread-safe using ConcurrentHashMap.

Usage Example


 EntityResolver resolver = new InMemoryEntityResolver();

 // Register sources
 resolver.registerSource(EntitySource.builder()
     .id("salesforce")
     .name("Salesforce CRM")
     .type(EntitySource.SourceType.CRM)
     .priority(1)
     .build());

 // Store entity
 Entity customer = Entity.builder()
     .id("cust-123")
     .type(EntityType.CUSTOMER)
     .attribute("name", "Acme Corp", "salesforce", 0.95)
     .build();
 resolver.store(customer);

 // Resolve
 Optional<Entity> resolved = resolver.resolve("cust-123");
 
  • Constructor Details

    • InMemoryEntityResolver

      public InMemoryEntityResolver()
  • Method Details

    • resolve

      public Optional<com.tnsai.context.entity.Entity> resolve(String entityId)
      Specified by:
      resolve in interface com.tnsai.context.entity.EntityResolver
    • resolveByAttributes

      public com.tnsai.context.entity.EntityResolutionResult resolveByAttributes(Map<String,Object> attributes)
      Specified by:
      resolveByAttributes in interface com.tnsai.context.entity.EntityResolver
    • registerSource

      public void registerSource(com.tnsai.context.entity.EntitySource source)
      Specified by:
      registerSource in interface com.tnsai.context.entity.EntityResolver
    • unregisterSource

      public boolean unregisterSource(String sourceId)
      Specified by:
      unregisterSource in interface com.tnsai.context.entity.EntityResolver
    • getSources

      public List<com.tnsai.context.entity.EntitySource> getSources()
      Specified by:
      getSources in interface com.tnsai.context.entity.EntityResolver
    • getSource

      public Optional<com.tnsai.context.entity.EntitySource> getSource(String sourceId)
      Specified by:
      getSource in interface com.tnsai.context.entity.EntityResolver
    • store

      public void store(com.tnsai.context.entity.Entity entity)
      Specified by:
      store in interface com.tnsai.context.entity.EntityResolver
    • store

      public void store(com.tnsai.context.entity.Entity entity, String sourceId)
      Specified by:
      store in interface com.tnsai.context.entity.EntityResolver
    • delete

      public boolean delete(String entityId)
      Specified by:
      delete in interface com.tnsai.context.entity.EntityResolver
    • mergeEntities

      public com.tnsai.context.entity.Entity mergeEntities(List<com.tnsai.context.entity.Entity> candidates, com.tnsai.context.entity.ConflictResolution strategy)
      Specified by:
      mergeEntities in interface com.tnsai.context.entity.EntityResolver
    • findPotentialDuplicates

      public List<com.tnsai.context.entity.Entity> findPotentialDuplicates(com.tnsai.context.entity.Entity entity, double similarityThreshold)
      Specified by:
      findPotentialDuplicates in interface com.tnsai.context.entity.EntityResolver
    • listByType

      public List<com.tnsai.context.entity.Entity> listByType(com.tnsai.context.entity.EntityType type)
      Specified by:
      listByType in interface com.tnsai.context.entity.EntityResolver
    • listBySource

      public List<com.tnsai.context.entity.Entity> listBySource(String sourceId)
      Specified by:
      listBySource in interface com.tnsai.context.entity.EntityResolver
    • searchByAttribute

      public List<com.tnsai.context.entity.Entity> searchByAttribute(String attributeName, Object attributeValue)
      Specified by:
      searchByAttribute in interface com.tnsai.context.entity.EntityResolver
    • getStatistics

      public com.tnsai.context.entity.EntityResolver.ResolverStatistics getStatistics()
      Specified by:
      getStatistics in interface com.tnsai.context.entity.EntityResolver
    • clear

      public void clear()
      Clears all entities and sources. Useful for testing.