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);
 
  • Field Details

    • DEFAULT_CONFIDENCE

      public static final double DEFAULT_CONFIDENCE
      Default confidence for attributes without explicit confidence.
      See Also:
  • Constructor Details

  • Method Details

    • of

      public static EntityAttribute of(String name, Object value, String sourceId)
      Creates an attribute with default confidence (1.0) and current timestamp.
      Parameters:
      name - attribute name
      value - attribute value
      sourceId - 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 name
      value - attribute value
      sourceId - source system identifier
      confidence - 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 name
      value - attribute value
      sourceId - source system identifier
      confidence - confidence score
      observedAt - 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 value
      newSourceId - source of the new value
      newConfidence - confidence of the new value
      changeReason - reason for the change
      Returns:
      new EntityAttribute with updated value and history
    • withConfidence

      public EntityAttribute withConfidence(double newConfidence)
      Creates a new attribute with updated confidence.
      Parameters:
      newConfidence - new confidence score
      Returns:
      new EntityAttribute with updated confidence
    • conflictsWith

      public boolean conflictsWith(EntityAttribute other)
      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

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • value

      public Object value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component
    • sourceId

      public String sourceId()
      Returns the value of the sourceId record component.
      Returns:
      the value of the sourceId record component
    • confidence

      public double confidence()
      Returns the value of the confidence record component.
      Returns:
      the value of the confidence record component
    • observedAt

      public Instant observedAt()
      Returns the value of the observedAt record component.
      Returns:
      the value of the observedAt record component
    • history

      Returns the value of the history record component.
      Returns:
      the value of the history record component