All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.alloyggp.tournament.api.TTournamentStatus Maven / Gradle / Ivy

package net.alloyggp.tournament.api;

import java.util.Collection;
import java.util.List;

import javax.annotation.concurrent.Immutable;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

/**
 * An immutable object representing a particular state of a tournament. This includes
 * the specification of the tournament, the initial seeding of players, and any match
 * results obtained so far.
 */
@Immutable
public class TTournamentStatus {
    private final TTournament spec;
    private final TSeeding initialSeeding;
    private final ImmutableSet resultsSoFar;

    private TTournamentStatus(TTournament spec, TSeeding initialSeeding,
            ImmutableSet resultsSoFar) {
        this.spec = spec;
        this.initialSeeding = initialSeeding;
        this.resultsSoFar = resultsSoFar;
    }

    /**
     * Returns the initial status of the tournament in which no matches have been played.
     *
     * 

In addition to the tournament specification, this requires an initial seeding of * the players that will be participating. This seeding is used as a tie-breaker in * the first stage of the tournament. It also affects match assignments. For some * tournaments, the client may want to use a pre-existing set of player rankings; in * other cases, a random seeding is sufficient. */ public static TTournamentStatus getInitialStatus(TTournament spec, TSeeding initialSeeding) { return new TTournamentStatus(spec, initialSeeding, ImmutableSet.of()); } /** * Returns a new TournamentStatus object that includes the given result in addition * to the results already known. */ public TTournamentStatus withNewResult(TMatchResult newResult) { return withNewResults(ImmutableList.of(newResult)); } /** * Returns a new TournamentStatus object that includes the given results in addition * to the results already known. */ public TTournamentStatus withNewResults(Collection newResults) { ImmutableSet allMatchResults = ImmutableSet.builder() .addAll(resultsSoFar) .addAll(newResults) .build(); return new TTournamentStatus(spec, initialSeeding, allMatchResults); } public TTournament getSpec() { return spec; } public ImmutableSet getResultsSoFar() { return resultsSoFar; } /** * Returns true iff the tournament is over and there are no more matches to * run. */ public boolean isComplete() { return getNextMatchesToRun().getMatchesToRun().isEmpty(); } /** * Returns the next set of matches to run. */ public TNextMatchesResult getNextMatchesToRun() { return spec.getMatchesToRun(initialSeeding, resultsSoFar); } public TRanking getCurrentStandings() { return spec.getCurrentStandings(initialSeeding, resultsSoFar); } public List getStandingsHistory() { return spec.getStandingsHistory(initialSeeding, resultsSoFar); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy