Record Class SnapshotDiff

java.lang.Object
java.lang.Record
com.tnsai.context.snapshot.SnapshotDiff

public record SnapshotDiff(String beforeSnapshotId, String afterSnapshotId, Duration timeElapsed, List<Belief> addedBeliefs, List<Belief> removedBeliefs, List<Desire> addedDesires, List<Desire> removedDesires, List<Intention> addedIntentions, List<Intention> removedIntentions, List<Entity> addedEntities, List<Entity> removedEntities, Map<String,SnapshotDiff.VariableChange> variableChanges, SnapshotDiff.DiffSummary summary) extends Record
Represents the difference between two context snapshots.

SnapshotDiff enables understanding what changed between two points in time, which is essential for:

  • Understanding decision impact
  • Debugging unexpected behavior
  • Auditing state changes

Usage Example


 ContextSnapshot before = contextManager.createSnapshot(SnapshotTrigger.PRE_DECISION);
 // ... decision execution ...
 ContextSnapshot after = contextManager.createSnapshot(SnapshotTrigger.POST_DECISION);

 SnapshotDiff diff = before.diff(after);
 System.out.println("Added beliefs: " + diff.addedBeliefs().size());
 System.out.println("Removed entities: " + diff.removedEntities().size());
 System.out.println("Time elapsed: " + diff.timeElapsed());
 
  • Constructor Details

  • Method Details

    • compute

      public static SnapshotDiff compute(ContextSnapshot before, ContextSnapshot after)
      Computes the difference between two snapshots.
      Parameters:
      before - the earlier snapshot
      after - the later snapshot
      Returns:
      SnapshotDiff describing the changes
    • hasChanges

      public boolean hasChanges()
      Returns true if there are any changes.
    • beliefsChanged

      public boolean beliefsChanged()
      Returns true if beliefs changed.
    • intentionsChanged

      public boolean intentionsChanged()
      Returns true if intentions changed.
    • entitiesChanged

      public boolean entitiesChanged()
      Returns true if entities changed.
    • getTotalChanges

      public int getTotalChanges()
      Gets the total number of changes.
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • beforeSnapshotId

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

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

      public Duration timeElapsed()
      Returns the value of the timeElapsed record component.
      Returns:
      the value of the timeElapsed record component
    • addedBeliefs

      public List<Belief> addedBeliefs()
      Returns the value of the addedBeliefs record component.
      Returns:
      the value of the addedBeliefs record component
    • removedBeliefs

      public List<Belief> removedBeliefs()
      Returns the value of the removedBeliefs record component.
      Returns:
      the value of the removedBeliefs record component
    • addedDesires

      public List<Desire> addedDesires()
      Returns the value of the addedDesires record component.
      Returns:
      the value of the addedDesires record component
    • removedDesires

      public List<Desire> removedDesires()
      Returns the value of the removedDesires record component.
      Returns:
      the value of the removedDesires record component
    • addedIntentions

      public List<Intention> addedIntentions()
      Returns the value of the addedIntentions record component.
      Returns:
      the value of the addedIntentions record component
    • removedIntentions

      public List<Intention> removedIntentions()
      Returns the value of the removedIntentions record component.
      Returns:
      the value of the removedIntentions record component
    • addedEntities

      public List<Entity> addedEntities()
      Returns the value of the addedEntities record component.
      Returns:
      the value of the addedEntities record component
    • removedEntities

      public List<Entity> removedEntities()
      Returns the value of the removedEntities record component.
      Returns:
      the value of the removedEntities record component
    • variableChanges

      public Map<String,SnapshotDiff.VariableChange> variableChanges()
      Returns the value of the variableChanges record component.
      Returns:
      the value of the variableChanges record component
    • summary

      public SnapshotDiff.DiffSummary summary()
      Returns the value of the summary record component.
      Returns:
      the value of the summary record component