@@ -24,6 +24,8 @@ public class Sequence<T> {
2424
2525 private int index = 0 ;
2626 private long ticks = 0 ;
27+ private int initialObserveSize = 0 ;
28+ private int initialScheduleSize = 0 ;
2729 private long lastExecutionTime = System .currentTimeMillis ();
2830 private State state = State .INACTIVE ;
2931
@@ -36,6 +38,9 @@ public Sequence(final SequenceContext sequenceContext,
3638
3739 this .scheduleActions .putAll (scheduleActions );
3840 this .observerActions .putAll (observerActions );
41+
42+ this .initialObserveSize = this .observerActions .size ();
43+ this .initialScheduleSize = this .scheduleActions .size ();
3944 }
4045
4146 /**
@@ -50,6 +55,7 @@ public boolean applyObserve(final T event, final SequenceContext sequenceContext
5055 final Iterator <ObserverAction <T >> iterator = this .observerActions .keySet ().iterator ();
5156
5257 if (this .state .equals (State .INACTIVE )) this .state = State .ACTIVE ;
58+ if (this .initialObserveSize < 1 ) return false ;
5359
5460 if (iterator .hasNext ()) {
5561 final ObserverAction <T > action = iterator .next ();
@@ -102,6 +108,7 @@ public boolean applySchedule(final SequenceContext sequenceContext) {
102108 final Iterator <ScheduleAction > iterator = this .scheduleActions .keySet ().iterator ();
103109
104110 if (this .state .equals (State .INACTIVE )) this .state = State .ACTIVE ;
111+ if (this .initialScheduleSize < 1 ) return false ;
105112
106113 this .ticks ++;
107114
@@ -152,7 +159,7 @@ public boolean succeed(final Action action, final SequenceContext sequenceContex
152159
153160 this .lastExecutionTime = System .currentTimeMillis ();
154161
155- if (this .index >= this .observerActions . size () + this .scheduleActions . size () ) this .state = State .FINISHED ;
162+ if (this .index >= this .initialObserveSize + this .initialScheduleSize ) this .state = State .FINISHED ;
156163
157164 return true ;
158165 }
0 commit comments