/**
* @TODO clean up this code
*/
private void addTeamRotation(List<Move> moveList) {
for (ListIterator<Team> firstTeamIt = teamList.listIterator(); firstTeamIt.hasNext();) {
Team firstTeam = firstTeamIt.next();
Map<Day, Match> firstTeamDayMap = teamDayMap.get(firstTeam);
for (ListIterator<Team> secondTeamIt = teamList.listIterator(firstTeamIt.nextIndex()); secondTeamIt.hasNext();) {
Team secondTeam = secondTeamIt.next();
List<Match> clonedFirstTeamMatchList = new ArrayList<Match>(firstTeamDayMap.values());
while (!clonedFirstTeamMatchList.isEmpty()) {
List<Match> firstRotateList = new ArrayList<Match>();
List<Match> secondRotateList = new ArrayList<Match>();
Match firstStartMatch = clonedFirstTeamMatchList.remove(0);
Team firstStartTeam = getOtherTeam(firstStartMatch, firstTeam);
Day startDay = firstStartMatch.getDay();
boolean firstTeamIsHomeTeam = firstStartMatch.getHomeTeam().equals(firstTeam);
Match secondStartMatch = teamDayMap.get(secondTeam).get(startDay);
if (firstStartMatch.equals(secondStartMatch)) {
break;
}
firstRotateList.add(0, firstStartMatch);
secondRotateList.add(secondStartMatch);
Map<Team, Match> visitedTeamMap = new HashMap<Team, Match>();
Team teamToFind = getOtherTeam(secondStartMatch, secondTeam);
while (!teamToFind.equals(firstStartTeam)) {
// boolean shortcut = visitedTeamMap.containsKey(teamToFind);
// if (shortcut) {
Match firstRepairMatch = homeTeamAwayTeamMap
.get(firstTeamIsHomeTeam ? firstTeam : teamToFind)
.get(firstTeamIsHomeTeam ? teamToFind : firstTeam);