Adding N-way merge class in Java