Package com.tnsai.fsm
Record Class Event
java.lang.Object
java.lang.Record
com.tnsai.fsm.Event
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondata()Returns the value of thedatarecord component.final booleanIndicates whether some other object is "equal to" this one.<T> TGets data by key.<T> TgetDataOrDefault(String key, T defaultValue) Gets data with default.getName()Gets the event name (alias for name()).booleanChecks if data exists.final inthashCode()Returns a hash code value for this object.name()Returns the value of thenamerecord component.static EventCreates an event with the given name.static EventCreates an event with data.toString()Returns a string representation of this record class.Creates a new event with additional data.
-
Constructor Details
-
Event
Creates an event with the given name.- Parameters:
name- event name
-
-
Method Details
-
of
Creates an event with the given name.- Parameters:
name- the event name- Returns:
- new event
-
of
Creates an event with data.- Parameters:
name- the event namedata- the event data- Returns:
- new event
-
withData
Creates a new event with additional data.- Parameters:
key- the data keyvalue- the data value- Returns:
- new event with the data
-
getData
Gets data by key.- Type Parameters:
T- the value type- Parameters:
key- the key- Returns:
- value or null
-
getDataOrDefault
Gets data with default.- Type Parameters:
T- the value type- Parameters:
key- the keydefaultValue- default value if not found- Returns:
- value or default
-
hasData
Checks if data exists.- Parameters:
key- the key- Returns:
- true if exists
-
getName
Gets the event name (alias for name()).- Returns:
- event name
-
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). -
name
Returns the value of thenamerecord component.- Returns:
- the value of the
namerecord component
-
data
Returns the value of thedatarecord component.- Returns:
- the value of the
datarecord component
-