26
26
/** Provides common utility methods to provide most often needed answers from a workflow */
27
27
public final class WorkflowUtils {
28
28
private static final int DEFAULT_STARTING_STATE_POSITION = 0 ;
29
+
29
30
/**
30
31
* Gets State matching Start state.If start is not present returns first state otherwise returns
31
32
* null
@@ -70,16 +71,16 @@ public static List<State> getStates(Workflow workflow, DefaultState.Type stateTy
70
71
* @return {@code List<io.serverlessworkflow.api.events.EventDefinition>}. Returns {@code NULL}
71
72
* when workflow is null or when workflow does not contain events
72
73
*/
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 );
75
76
}
76
77
77
78
/**
78
79
* @return {@code List<io.serverlessworkflow.api.events.EventDefinition>}. Returns {@code NULL}
79
80
* when workflow is null or when workflow does not contain events
80
81
*/
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 );
83
84
}
84
85
85
86
/**
@@ -89,7 +90,8 @@ public static List<EventDefinition> getProducedEvents(Workflow workflow) {
89
90
* @return {@code List<io.serverlessworkflow.api.events.EventDefinition>}. Returns {@code NULL}
90
91
* when workflow is null or when workflow does not contain events
91
92
*/
92
- public static List <EventDefinition > getEvents (Workflow workflow , EventDefinition .Kind eventKind ) {
93
+ public static List <EventDefinition > getDefinedEvents (
94
+ Workflow workflow , EventDefinition .Kind eventKind ) {
93
95
if (workflow == null || workflow .getEvents () == null ) {
94
96
return null ;
95
97
}
@@ -102,4 +104,20 @@ public static List<EventDefinition> getEvents(Workflow workflow, EventDefinition
102
104
.filter (eventDef -> eventDef .getKind () == eventKind )
103
105
.collect (Collectors .toList ());
104
106
}
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
+ }
105
123
}
0 commit comments