Package com.tnsai.context.snapshot
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());
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumType of change.static final recordSummary of changes between snapshots.static final recordRepresents a change to a variable. -
Constructor Summary
ConstructorsConstructorDescriptionSnapshotDiff(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) Compact constructor with validation. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theaddedBeliefsrecord component.Returns the value of theaddedDesiresrecord component.Returns the value of theaddedEntitiesrecord component.Returns the value of theaddedIntentionsrecord component.Returns the value of theafterSnapshotIdrecord component.Returns the value of thebeforeSnapshotIdrecord component.booleanReturns true if beliefs changed.static SnapshotDiffcompute(ContextSnapshot before, ContextSnapshot after) Computes the difference between two snapshots.booleanReturns true if entities changed.final booleanIndicates whether some other object is "equal to" this one.intGets the total number of changes.booleanReturns true if there are any changes.final inthashCode()Returns a hash code value for this object.booleanReturns true if intentions changed.Returns the value of theremovedBeliefsrecord component.Returns the value of theremovedDesiresrecord component.Returns the value of theremovedEntitiesrecord component.Returns the value of theremovedIntentionsrecord component.summary()Returns the value of thesummaryrecord component.Returns the value of thetimeElapsedrecord component.final StringtoString()Returns a string representation of this record class.Returns the value of thevariableChangesrecord component.
-
Constructor Details
-
SnapshotDiff
public 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) Compact constructor with validation.
-
-
Method Details
-
compute
Computes the difference between two snapshots.- Parameters:
before- the earlier snapshotafter- 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
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. All components in this record class are compared withObjects::equals(Object,Object). -
beforeSnapshotId
Returns the value of thebeforeSnapshotIdrecord component.- Returns:
- the value of the
beforeSnapshotIdrecord component
-
afterSnapshotId
Returns the value of theafterSnapshotIdrecord component.- Returns:
- the value of the
afterSnapshotIdrecord component
-
timeElapsed
Returns the value of thetimeElapsedrecord component.- Returns:
- the value of the
timeElapsedrecord component
-
addedBeliefs
Returns the value of theaddedBeliefsrecord component.- Returns:
- the value of the
addedBeliefsrecord component
-
removedBeliefs
Returns the value of theremovedBeliefsrecord component.- Returns:
- the value of the
removedBeliefsrecord component
-
addedDesires
Returns the value of theaddedDesiresrecord component.- Returns:
- the value of the
addedDesiresrecord component
-
removedDesires
Returns the value of theremovedDesiresrecord component.- Returns:
- the value of the
removedDesiresrecord component
-
addedIntentions
Returns the value of theaddedIntentionsrecord component.- Returns:
- the value of the
addedIntentionsrecord component
-
removedIntentions
Returns the value of theremovedIntentionsrecord component.- Returns:
- the value of the
removedIntentionsrecord component
-
addedEntities
Returns the value of theaddedEntitiesrecord component.- Returns:
- the value of the
addedEntitiesrecord component
-
removedEntities
Returns the value of theremovedEntitiesrecord component.- Returns:
- the value of the
removedEntitiesrecord component
-
variableChanges
Returns the value of thevariableChangesrecord component.- Returns:
- the value of the
variableChangesrecord component
-
summary
Returns the value of thesummaryrecord component.- Returns:
- the value of the
summaryrecord component
-