private SubscriptionEvent [ ] findPrevNext ( final List < SubscriptionEvent > events , final UUID targetEntitlementId , final SubscriptionEvent insertionEvent ) { // Find prev/next event for the same entitlement final SubscriptionEvent [ ] result = new DefaultSubscriptionEvent [ 2 ] ; if ( insertionEvent == null ) { result [ 0 ] = null ; result [ 1 ] = ! events . isEmpty ( ) ? events . get ( 0 ) : null ; return result ; } final Iterator < SubscriptionEvent > it = events . iterator ( ) ; DefaultSubscriptionEvent prev = null ; DefaultSubscriptionEvent next = null ; boolean foundCur = false ; while ( it . hasNext ( ) ) { final DefaultSubscriptionEvent tmp = ( DefaultSubscriptionEvent ) it . next ( ) ; if ( tmp . getEntitlementId ( ) . equals ( targetEntitlementId ) ) { if ( ! foundCur ) { prev = tmp ; } else { next = tmp ; break ; } } // Check both the id and the event type because of multiplexing if ( tmp . getId ( ) . equals ( insertionEvent . getId ( ) ) && tmp . getSubscriptionEventType ( ) . equals ( insertionEvent . getSubscriptionEventType ( ) ) ) { foundCur = true ; } } result [ 0 ] = prev ; result [ 1 ] = next ; return result ; }
Extract prev and next events in the stream events for that particular target subscription from the insertionEvent