// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.ArrayList;
import java.util.List;

public class Tournament {
    private List<Team> startTeams;
    private List<Team> activeTeams;
    private List<Match> round;
    private void initActiveTeams() {
		if(activeTeams == null) {
			activeTeams = new ArrayList<Team>(startTeams);
		}
    }
    public Tournament() {
        this.startTeams = new ArrayList<Team>();
        this.activeTeams = null;
        this.round = null;
    }
    public List<Team> getStartTeams() {
        return startTeams;
    }
	public List<Team> getActiveTeams() {
		initActiveTeams();
		return activeTeams;
	}
	public List<Match> getRound() {
		return round;
	}
	public void planRound() {
		initActiveTeams();
		round = new ArrayList<Match>();
		for(int i = 0; i < activeTeams.size() / 2; i++) {
			round.add(new Match(activeTeams.get(i), activeTeams.get(activeTeams.size() - 1 - i)));
		}
	}
	public void processRound() {
		activeTeams = new ArrayList<Team>();
		for(Match m : round) {
			switch(m.getResult()) {
				case NotPlayed:
					throw new RuntimeException("Round not played");
				case HomeWin:
					activeTeams.add(m.getHome());
					break;
				case AwayWin:
					activeTeams.add(m.getAway());
					break;
			}
		}
	}
}
