2626/** Provides common utility methods to provide most often needed answers from a workflow */
2727public final class WorkflowUtils {
2828 private static final int DEFAULT_STARTING_STATE_POSITION = 0 ;
29+
2930 /**
3031 * Gets State matching Start state.If start is not present returns first state otherwise returns
3132 * null
@@ -70,16 +71,16 @@ public static List<State> getStates(Workflow workflow, DefaultState.Type stateTy
7071 * @return {@code List<io.serverlessworkflow.api.events.EventDefinition>}. Returns {@code NULL}
7172 * when workflow is null or when workflow does not contain events
7273 */
73- public static List <EventDefinition > getConsumedEvents (Workflow workflow ) {
74- return getEvents (workflow , EventDefinition .Kind .CONSUMED );
74+ public static List <EventDefinition > getDefinedConsumedEvents (Workflow workflow ) {
75+ return getDefinedEvents (workflow , EventDefinition .Kind .CONSUMED );
7576 }
7677
7778 /**
7879 * @return {@code List<io.serverlessworkflow.api.events.EventDefinition>}. Returns {@code NULL}
7980 * when workflow is null or when workflow does not contain events
8081 */
81- public static List <EventDefinition > getProducedEvents (Workflow workflow ) {
82- return getEvents (workflow , EventDefinition .Kind .PRODUCED );
82+ public static List <EventDefinition > getDefinedProducedEvents (Workflow workflow ) {
83+ return getDefinedEvents (workflow , EventDefinition .Kind .PRODUCED );
8384 }
8485
8586 /**
@@ -89,7 +90,8 @@ public static List<EventDefinition> getProducedEvents(Workflow workflow) {
8990 * @return {@code List<io.serverlessworkflow.api.events.EventDefinition>}. Returns {@code NULL}
9091 * when workflow is null or when workflow does not contain events
9192 */
92- public static List <EventDefinition > getEvents (Workflow workflow , EventDefinition .Kind eventKind ) {
93+ public static List <EventDefinition > getDefinedEvents (
94+ Workflow workflow , EventDefinition .Kind eventKind ) {
9395 if (workflow == null || workflow .getEvents () == null ) {
9496 return null ;
9597 }
@@ -102,4 +104,20 @@ public static List<EventDefinition> getEvents(Workflow workflow, EventDefinition
102104 .filter (eventDef -> eventDef .getKind () == eventKind )
103105 .collect (Collectors .toList ());
104106 }
107+
108+ /** @return {@code int} Returns count of defined event count matching eventKind */
109+ public static int getDefinedEventsCount (Workflow workflow , EventDefinition .Kind eventKind ) {
110+ List <EventDefinition > definedEvents = getDefinedEvents (workflow , eventKind );
111+ return definedEvents == null ? 0 : definedEvents .size ();
112+ }
113+
114+ /** @return {@code int} Returns count of Defined Consumed Event Count */
115+ public static int getDefinedConsumedEventsCount (Workflow workflow ) {
116+ return getDefinedEventsCount (workflow , EventDefinition .Kind .CONSUMED );
117+ }
118+
119+ /** @return {@code int} Returns count of Defined Produced Event Count */
120+ public static int getDefinedProducedEventsCount (Workflow workflow ) {
121+ return getDefinedEventsCount (workflow , EventDefinition .Kind .PRODUCED );
122+ }
105123}
0 commit comments