Package com.tnsai.context.entity
Record Class EntityAttribute
java.lang.Object
java.lang.Record
com.tnsai.context.entity.EntityAttribute
public record EntityAttribute(String name, Object value, String sourceId, double confidence, Instant observedAt, List<EntityAttribute.AttributeHistory> history)
extends Record
An entity attribute with provenance tracking.
Each attribute knows where it came from, when it was observed, and how confident we are in its value. This enables auditability and conflict resolution when merging entities from multiple sources.
Usage Example
EntityAttribute email = EntityAttribute.of("email", "john@example.com", "salesforce");
EntityAttribute verified = EntityAttribute.withConfidence("email", "john@example.com", "auth-system", 0.99);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordHistorical record of attribute changes. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleDefault confidence for attributes without explicit confidence. -
Constructor Summary
ConstructorsConstructorDescriptionEntityAttribute(String name, Object value, String sourceId, double confidence, Instant observedAt, List<EntityAttribute.AttributeHistory> history) Compact constructor with validation. -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the value of theconfidencerecord component.booleanconflictsWith(EntityAttribute other) Returns true if this attribute conflicts with another (same name, different value).final booleanIndicates whether some other object is "equal to" this one.static EntityAttributeCreates an attribute with full specification.final inthashCode()Returns a hash code value for this object.history()Returns the value of thehistoryrecord component.booleanReturns true if this attribute has high confidence (>= 0.9).booleanReturns true if this attribute has low confidence (invalid input: '<' 0.7).name()Returns the value of thenamerecord component.Returns the value of theobservedAtrecord component.static EntityAttributeCreates an attribute with default confidence (1.0) and current timestamp.sourceId()Returns the value of thesourceIdrecord component.final StringtoString()Returns a string representation of this record class.updateValue(Object newValue, String newSourceId, double newConfidence, String changeReason) Creates a new attribute with updated value and adds current value to history.value()Returns the value of thevaluerecord component.withConfidence(double newConfidence) Creates a new attribute with updated confidence.static EntityAttributewithConfidence(String name, Object value, String sourceId, double confidence) Creates an attribute with specified confidence.
-
Field Details
-
DEFAULT_CONFIDENCE
public static final double DEFAULT_CONFIDENCEDefault confidence for attributes without explicit confidence.- See Also:
-
-
Constructor Details
-
Method Details
-
of
Creates an attribute with default confidence (1.0) and current timestamp.- Parameters:
name- attribute namevalue- attribute valuesourceId- source system identifier- Returns:
- new EntityAttribute
-
withConfidence
public static EntityAttribute withConfidence(String name, Object value, String sourceId, double confidence) Creates an attribute with specified confidence.- Parameters:
name- attribute namevalue- attribute valuesourceId- source system identifierconfidence- confidence score (0.0-1.0)- Returns:
- new EntityAttribute
-
full
public static EntityAttribute full(String name, Object value, String sourceId, double confidence, Instant observedAt) Creates an attribute with full specification.- Parameters:
name- attribute namevalue- attribute valuesourceId- source system identifierconfidence- confidence scoreobservedAt- when the value was observed- Returns:
- new EntityAttribute
-
isHighConfidence
public boolean isHighConfidence()Returns true if this attribute has high confidence (>= 0.9). -
isLowConfidence
public boolean isLowConfidence()Returns true if this attribute has low confidence (invalid input: '<' 0.7). -
updateValue
public EntityAttribute updateValue(Object newValue, String newSourceId, double newConfidence, String changeReason) Creates a new attribute with updated value and adds current value to history.- Parameters:
newValue- the new valuenewSourceId- source of the new valuenewConfidence- confidence of the new valuechangeReason- reason for the change- Returns:
- new EntityAttribute with updated value and history
-
withConfidence
Creates a new attribute with updated confidence.- Parameters:
newConfidence- new confidence score- Returns:
- new EntityAttribute with updated confidence
-
conflictsWith
Returns true if this attribute conflicts with another (same name, different value).- Parameters:
other- another attribute to compare- Returns:
- true if there is a conflict
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
name
Returns the value of thenamerecord component.- Returns:
- the value of the
namerecord component
-
value
Returns the value of thevaluerecord component.- Returns:
- the value of the
valuerecord component
-
sourceId
Returns the value of thesourceIdrecord component.- Returns:
- the value of the
sourceIdrecord component
-
confidence
public double confidence()Returns the value of theconfidencerecord component.- Returns:
- the value of the
confidencerecord component
-
observedAt
Returns the value of theobservedAtrecord component.- Returns:
- the value of the
observedAtrecord component
-
history
Returns the value of thehistoryrecord component.- Returns:
- the value of the
historyrecord component
-