net.alloyggp.tournament.impl.MatchResults Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ggp-tournament Show documentation
Show all versions of ggp-tournament Show documentation
A library for GGP tournament specification and scheduling.
package net.alloyggp.tournament.impl;
import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.SetMultimap;
import net.alloyggp.tournament.api.MatchResult;
/**
* Contains utility methods for dealing with {@link MatchResult}s.
*/
public class MatchResults {
private MatchResults() {
//Not instantiable
}
/**
* Returns only those {@link MatchResult}s that are from the given stage.
*/
public static Set filterByStage(Collection inputs, int stageNum) {
return inputs.stream()
.filter(result -> {
String matchId = result.getSetup().getMatchId();
int matchStage = MatchIds.parseStageNumber(matchId);
return matchStage == stageNum;
})
.collect(Collectors.toSet());
}
/**
* Returns only those {@link MatchResult}s that are from a stage before the
* one specified.
*/
public static Set getResultsPriorToStage(Collection inputs, int stageNum) {
return inputs.stream()
.filter(result -> {
String matchId = result.getSetup().getMatchId();
int matchStage = MatchIds.parseStageNumber(matchId);
return matchStage < stageNum;
})
.collect(Collectors.toSet());
}
/**
* Returns a {@link SetMultimap} including all the {@link MatchResult}s from the given
* stage. The results are grouped by their round number.
*/
public static SetMultimap mapByRound(Collection resultsSoFar,
int stageNum) {
SetMultimap mapped = HashMultimap.create();
for (MatchResult result : filterByStage(resultsSoFar, stageNum)) {
String matchId = result.getSetup().getMatchId();
int matchRound = MatchIds.parseRoundNumber(matchId);
mapped.put(matchRound, result);
}
return mapped;
}
}