source: protocol/src/main/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsState.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 2.3 KB
Line 
1package geniusweb.protocol.tournament.allpermutations;
2
3import java.math.BigInteger;
4import java.util.ArrayList;
5import java.util.List;
6
7import com.fasterxml.jackson.annotation.JsonCreator;
8import com.fasterxml.jackson.annotation.JsonProperty;
9
10import geniusweb.protocol.session.SessionResult;
11import geniusweb.protocol.session.SessionSettings;
12import geniusweb.protocol.tournament.TournamentState;
13
14/**
15 * A non-parallel simple implementation of all-permutations
16 */
17public class AllPermutationsState implements TournamentState {
18
19 protected final AllPermutationsSettings toursettings; // original settings
20 // limited to MAX_INT elements. But we need to store results anyway
21 protected final List<SessionResult> results;
22
23 @JsonCreator
24 public AllPermutationsState(
25 @JsonProperty("toursettings") AllPermutationsSettings toursettings,
26 @JsonProperty("results") List<SessionResult> results) {
27 this.toursettings = toursettings;
28 this.results = results;
29 }
30
31 public List<SessionResult> getResults() {
32 return results;
33 }
34
35 @Override
36 public boolean isFinal(long currentTimeMs) {
37 return toursettings.permutations().size().intValue() == results.size();
38 }
39
40 /**
41 * @return the settings for the next session. Null if no such session.
42 */
43 public SessionSettings getNextSettings() {
44 if (isFinal(0l))
45 return null;
46 return toursettings.permutations()
47 .get(BigInteger.valueOf(results.size()));
48 }
49
50 /**
51 *
52 * @param result the next {@link SessionResult}
53 * @return new state
54 * @throws IllegalArgumentException if the result participants are not
55 * matching the expected participants
56 */
57 public AllPermutationsState with(List<SessionResult> res) {
58 // FIXME do we really need this? Why is this not working?
59 // if (!new HashSet<PartyWithProfile>(getNextSettings().getAllParties())
60 // .equals(result.getParticipants().values())) {
61 // throw new IllegalArgumentException("Inconsistent session result");
62 // }
63 ArrayList<SessionResult> newresults = new ArrayList<>(results);
64 newresults.addAll(res);
65 return new AllPermutationsState(toursettings, newresults);
66 }
67
68 /**
69 *
70 * @return number of sessions in this tournament.
71 */
72 public BigInteger getSize() {
73 return toursettings.permutations().size();
74 }
75
76 @Override
77 public AllPermutationsSettings getSettings() {
78 return toursettings;
79 }
80
81}
Note: See TracBrowser for help on using the repository browser.