net.alloyggp.tournament.spec.RoundSpec 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.spec;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import javax.annotation.concurrent.Immutable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import net.alloyggp.tournament.api.Game;
import net.alloyggp.tournament.impl.YamlUtils;
@Immutable
public class RoundSpec {
private final Optional startTime;
private final ImmutableList matches;
private RoundSpec(Optional startTime, ImmutableList matches) {
this.startTime = startTime;
this.matches = matches;
}
private static final ImmutableSet ALLOWED_KEYS = ImmutableSet.of(
"startTime",
"matches"
);
@SuppressWarnings("unchecked")
public static RoundSpec parseYaml(Object yamlRound, Map games) {
Map roundMap = (Map) yamlRound;
YamlUtils.validateKeys(roundMap, "round", ALLOWED_KEYS);
final Optional startTime;
if (roundMap.containsKey("startTime")) {
String timeString = (String) roundMap.get("startTime");
startTime = Optional.of(ZonedDateTime.parse(timeString, DateTimeFormatter.RFC_1123_DATE_TIME));
// java.util.Date date = (Date) roundMap.get("startTime");
// startTime = date.
} else {
startTime = Optional.empty();
}
List matches = Lists.newArrayList();
for (Object yamlMatch : (List