question: public static void backAndForth ( HGSearchResult < ? > rs , int windowSize , int iteration ) { boolean advance = true ; for ( int i = 0 ; i < iteration ; i ++ ) { Object x = rs . current ( ) ; int steps = random ( windowSize ) ; steps = forward ( rs , steps ) ; if ( back ( rs , steps ) != steps ) throw new RuntimeException ( "Moved " + steps + " forward, but not backward." ) ; if ( ! x . equals ( rs . current ( ) ) ) throw new RuntimeException ( "Moving " + steps + " steps forward and backward missed current " + x ) ; if ( advance ) { forward ( rs , random ( windowSize ) ) ; if ( ! rs . hasNext ( ) ) { back ( rs , random ( windowSize ) ) ; advance = false ; } } else { back ( rs , random ( windowSize ) ) ; if ( ! rs . hasPrev ( ) ) { forward ( rs , random ( windowSize ) ) ; advance = true ; } } } }
target:  Go back and forth on a result set an 'iteration' number of times. Assume the result set is not empty and it already has a current position. The windowSize parameters controls how far we are going to move - a random number of steps b/w 0 and windowSize is actually used.