private static void advance ( Calendar cal , int field , int nextField , long haystack , int needle ) { long higher = higher ( haystack , needle ) ; if ( higher != 0 ) { cal . set ( field , first ( higher ) ) ; } else { cal . set ( field , first ( haystack ) ) ; cal . add ( nextField , 1 ) ; } }
Moves the value of the specified field forward in time to satisfy constraints of the specified bitmask . If a position higher than needle is found in haystack then that higher position is set as the value in field . Otherwise the lowest value in haystack is set as the value in field and the value in nextField is incremented .