public void simulateTimeChange ( long offsetToAddInMillis ) { ImmutableMap . Builder < Long , Event > eventMapBuilder = ImmutableMap . builder ( ) ; for ( Event event : eventsByTimeStamp . values ( ) ) { long newTimestamp = event . getTimeStamp ( ) + offsetToAddInMillis ; eventMapBuilder . put ( newTimestamp , EventBuilder . fromEvent ( event ) . setTimeStamp ( newTimestamp ) . build ( ) ) ; } eventsByTimeStamp . putAll ( eventMapBuilder . build ( ) ) ; }
Simulates the operations done by the framework when there is a time change . If the time is changed the timestamps of all existing usage events will be shifted by the same offset as the time change in order to make sure they remain stable relative to the new time .