Package com.tnsai.fsm

Record Class Event

java.lang.Object
java.lang.Record
com.tnsai.fsm.Event

public record Event(String name, Map<String,Object> data) extends Record
Represents an event that triggers state transitions.

Events can carry payload data that guards and actions can use.

Usage


 // Simple event
 Event submit = Event.of("SUBMIT");

 // Event with payload
 Event review = Event.of("REVIEW_COMPLETE")
     .withData("confidence", 0.95)
     .withData("reviewer", "agent-1");

 // Fire the event
 stateMachine.fire(review);
 
  • Constructor Details

    • Event

      public Event(String name, Map<String,Object> data)
      Creates an event with the given name.
      Parameters:
      name - event name
  • Method Details

    • of

      public static Event of(String name)
      Creates an event with the given name.
      Parameters:
      name - the event name
      Returns:
      new event
    • of

      public static Event of(String name, Map<String,Object> data)
      Creates an event with data.
      Parameters:
      name - the event name
      data - the event data
      Returns:
      new event
    • withData

      public Event withData(String key, Object value)
      Creates a new event with additional data.
      Parameters:
      key - the data key
      value - the data value
      Returns:
      new event with the data
    • getData

      public <T> T getData(String key)
      Gets data by key.
      Type Parameters:
      T - the value type
      Parameters:
      key - the key
      Returns:
      value or null
    • getDataOrDefault

      public <T> T getDataOrDefault(String key, T defaultValue)
      Gets data with default.
      Type Parameters:
      T - the value type
      Parameters:
      key - the key
      defaultValue - default value if not found
      Returns:
      value or default
    • hasData

      public boolean hasData(String key)
      Checks if data exists.
      Parameters:
      key - the key
      Returns:
      true if exists
    • getName

      public String getName()
      Gets the event name (alias for name()).
      Returns:
      event name
    • toString

      public 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.
    • name

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

      public Map<String,Object> data()
      Returns the value of the data record component.
      Returns:
      the value of the data record component