Merge Intervals in Java