The analysis above seems incorrect. The value of diff is of type long and is always positive. Dividing by another positive long should yield the desired value. Right after periodBarriersCrossed method is invoked, the value is compared to MAX_VALUE_FOR_INACTIVITY_PERIODS as follows:
periodsElapsed = Math.min(periodsElapsed, MAX_VALUE_FOR_INACTIVITY_PERIODS);
This call *may *reduce the value of periodsElapsed to MAX_VALUE_FOR_INACTIVITY_PERIODS, i.e 336. |