Package com.tnsai.context.entity
Class Entity
java.lang.Object
com.tnsai.context.entity.Entity
Represents a unified entity resolved from multiple sources.
Entities aggregate information from different systems (CRM, Slack, Email) into a single coherent view, tracking the provenance of each attribute. This enables the Context Graph to maintain a complete picture of real-world entities across organizational boundaries.
Design Principles
- Immutable core state for thread-safety
- Provenance tracking for every attribute
- Conflict detection and resolution support
- Merge capability for entity deduplication
Usage Example
Entity customer = Entity.builder()
.id("customer-123")
.type(EntityType.CUSTOMER)
.attribute("name", "Acme Corp", "salesforce", 0.95)
.attribute("email", "contact@acme.com", "email-system", 0.99)
.source(salesforceSource)
.build();
// Check for conflicts
if (customer.hasConflict("email")) {
List<EntityAttribute> emails = customer.getConflictingValues("email");
}
// Merge with another entity
Entity merged = customer.merge(otherCustomer, ConflictResolution.HIGHEST_CONFIDENCE);
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic Entity.Builderbuilder()Creates a new builder.booleanGets all attributes that have conflicts.getAttribute(String name) Gets an attribute by name.Gets all attribute names.getAttributeValue(String name) Gets an attribute value by name.<T> Optional<T> getAttributeValue(String name, Class<T> type) Gets an attribute value as a specific type.getConflictingValues(String attributeName) Gets all conflicting values for an attribute.getId()getSpec()getType()booleanReturns true if this entity has any conflicts.booleanhasConflict(String attributeName) Returns true if this entity has conflicting values for an attribute.inthashCode()merge(Entity other, ConflictResolution strategy) Merges this entity with another, using the specified conflict resolution strategy.static Entityof(String id, EntityType type) Creates a simple entity with ID and type.toString()withAttribute(EntityAttribute attribute) Creates a new entity with an updated attribute.withoutAttribute(String attributeName) Creates a new entity with an attribute removed.
-
Method Details
-
builder
Creates a new builder. -
of
Creates a simple entity with ID and type. -
getId
-
getType
-
getCreatedAt
-
getLastUpdatedAt
-
getSpec
-
getSources
-
getAttributeNames
Gets all attribute names. -
getAttribute
Gets an attribute by name.- Parameters:
name- attribute name- Returns:
- Optional containing the attribute if present
-
getAttributeValue
Gets an attribute value by name.- Parameters:
name- attribute name- Returns:
- Optional containing the value if present
-
getAttributeValue
Gets an attribute value as a specific type.- Parameters:
name- attribute nametype- expected type- Returns:
- Optional containing the typed value if present and castable
-
hasConflict
Returns true if this entity has conflicting values for an attribute.- Parameters:
attributeName- attribute to check- Returns:
- true if there are conflicts
-
hasAnyConflicts
public boolean hasAnyConflicts()Returns true if this entity has any conflicts. -
getConflictingValues
Gets all conflicting values for an attribute.- Parameters:
attributeName- attribute to get conflicts for- Returns:
- list of conflicting attributes, empty if no conflicts
-
getAllConflicts
Gets all attributes that have conflicts. -
merge
Merges this entity with another, using the specified conflict resolution strategy.- Parameters:
other- entity to merge withstrategy- conflict resolution strategy- Returns:
- new merged entity
-
withAttribute
Creates a new entity with an updated attribute.- Parameters:
attribute- new or updated attribute- Returns:
- new Entity with the attribute updated
-
withoutAttribute
Creates a new entity with an attribute removed.- Parameters:
attributeName- attribute to remove- Returns:
- new Entity without the attribute
-
equals
-
hashCode
public int hashCode() -
toString
-